mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +08:00
Sends broadcast on app open to notify addon termux receivers
This commit is contained in:
@@ -17,6 +17,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@@ -104,6 +105,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
private static final String RELOAD_STYLE_ACTION = "com.termux.app.reload_style";
|
private static final String RELOAD_STYLE_ACTION = "com.termux.app.reload_style";
|
||||||
|
|
||||||
|
private static final String BROADCAST_TERMUX_OPENED = "com.termux.app.OPENED";
|
||||||
|
|
||||||
/** The main view of the activity showing the terminal. Initialized in onCreate(). */
|
/** The main view of the activity showing the terminal. Initialized in onCreate(). */
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -334,6 +337,26 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
checkForFontAndColors();
|
checkForFontAndColors();
|
||||||
|
|
||||||
mBellSoundId = mBellSoundPool.load(this, R.raw.bell, 1);
|
mBellSoundId = mBellSoundPool.load(this, R.raw.bell, 1);
|
||||||
|
|
||||||
|
sendOpenedBroadcast();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a broadcast notifying Termux app has been opened
|
||||||
|
*/
|
||||||
|
void sendOpenedBroadcast() {
|
||||||
|
Intent broadcast = new Intent(BROADCAST_TERMUX_OPENED);
|
||||||
|
List<ResolveInfo> matches = getPackageManager().queryBroadcastReceivers(broadcast, 0);
|
||||||
|
|
||||||
|
// send broadcast to registered Termux receivers
|
||||||
|
// this technique is needed to work around broadcast changes that Oreo introduced
|
||||||
|
for (ResolveInfo info : matches) {
|
||||||
|
Intent explicitBroadcast = new Intent(broadcast);
|
||||||
|
ComponentName cname = new ComponentName(info.activityInfo.applicationInfo.packageName,
|
||||||
|
info.activityInfo.name);
|
||||||
|
explicitBroadcast.setComponent(cname);
|
||||||
|
sendBroadcast(explicitBroadcast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleShowExtraKeys() {
|
void toggleShowExtraKeys() {
|
||||||
|
Reference in New Issue
Block a user