本文整理了Java中android.content.Context.sendBroadcast()
方法的一些代码示例,展示了Context.sendBroadcast()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.sendBroadcast()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:sendBroadcast
暂无
代码示例来源:origin: stackoverflow.com
// This function will create an intent. This intent must take as parameter the "unique_name" that you registered your activity with
static void updateMyActivity(Context context, String message) {
Intent intent = new Intent("unique_name");
//put whatever data you want to send, if any
intent.putExtra("message", message);
//send broadcast
context.sendBroadcast(intent);
}
代码示例来源:origin: k9mail/k-9
public static void set(Context context, Intent broadcastIntent) {
broadcastIntent.setAction(K9RemoteControl.K9_SET);
context.sendBroadcast(broadcastIntent, K9RemoteControl.K9_REMOTE_CONTROL_PERMISSION);
}
代码示例来源:origin: chentao0707/SimplifyReader
public static void checkNetworkState(Context mContext) {
Intent intent = new Intent();
intent.setAction(CUSTOM_ANDROID_NET_CHANGE_ACTION);
mContext.sendBroadcast(intent);
}
代码示例来源:origin: jeasonlzy/ImagePicker
/**
* 扫描图片
*/
public static void galleryAddPic(Context context, File file) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
}
代码示例来源:origin: leolin310148/ShortcutBadger
@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
Intent intent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
intent.putExtra("packageName", context.getPackageName());
intent.putExtra("className", componentName.getClassName());
intent.putExtra("notificationNum", badgeCount);
context.sendBroadcast(intent);
}
代码示例来源:origin: aa112901/remusic
@Override
public void onReceive(Context context, Intent intent) {
// if (MusicPlayer.isPlaying()) {
Intent activityIntent = new Intent(context.getApplicationContext(), PlayingActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(activityIntent);
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.wm.remusic", "com.wm.remusic.activity.PlayingActivity.class"));
context.sendBroadcast(intent1);
// }
}
代码示例来源:origin: leolin310148/ShortcutBadger
private static void executeBadgeByBroadcast(Context context, ComponentName componentName,
int badgeCount) {
Intent intent = new Intent(INTENT_ACTION);
intent.putExtra(INTENT_EXTRA_PACKAGE_NAME, componentName.getPackageName());
intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
intent.putExtra(INTENT_EXTRA_MESSAGE, String.valueOf(badgeCount));
intent.putExtra(INTENT_EXTRA_SHOW_MESSAGE, badgeCount > 0);
context.sendBroadcast(intent);
}
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public void onReceive(Context context, Intent intent) {
Intent realIntent = intent.getParcelableExtra("_VA_|_intent_");
int userId = intent.getIntExtra("_VA_|_user_id_", VUserHandle.USER_ALL);
if (realIntent != null) {
Intent newIntent = ComponentUtils.redirectBroadcastIntent(realIntent, userId);
if (newIntent != null) {
context.sendBroadcast(newIntent);
}
}
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void onAudioSessionId(int i) {
if (!PlayerHelper.isUsingDSP(context)) return;
final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, i);
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
context.sendBroadcast(intent);
}
代码示例来源:origin: k9mail/k-9
public static void releaseWakeLock(Context context, int wakeLockId) {
Timber.v("CoreReceiver Got request to release wakeLock %d", wakeLockId);
Intent i = new Intent();
i.setClass(context, CoreReceiver.class);
i.setAction(WAKE_LOCK_RELEASE);
i.putExtra(WAKE_LOCK_ID, wakeLockId);
context.sendBroadcast(i);
}
}
代码示例来源:origin: commonsguy/cw-omnibus
private static void sendImplicitBroadcast(Context ctxt, Intent i) {
PackageManager pm=ctxt.getPackageManager();
List<ResolveInfo> matches=pm.queryBroadcastReceivers(i, 0);
for (ResolveInfo resolveInfo : matches) {
Intent explicit=new Intent(i);
ComponentName cn=
new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);
explicit.setComponent(cn);
ctxt.sendBroadcast(explicit);
}
}
}
代码示例来源:origin: lingochamp/FileDownloader
public static void sendCompletedBroadcast(FileDownloadModel model) {
if (model == null) throw new IllegalArgumentException();
if (model.getStatus() != FileDownloadStatus.completed) throw new IllegalStateException();
final Intent intent = new Intent(ACTION_COMPLETED);
intent.putExtra(KEY_MODEL, model);
FileDownloadHelper.getAppContext().sendBroadcast(intent);
}
}
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public void notifyBadgerChange(BadgerInfo info) throws RemoteException {
Intent intent = new Intent(VASettings.ACTION_BADGER_CHANGE);
intent.putExtra("userId", info.userId);
intent.putExtra("packageName", info.packageName);
intent.putExtra("badgerCount", info.badgerCount);
VirtualCore.get().getContext().sendBroadcast(intent);
}
}
代码示例来源:origin: k9mail/k-9
public static void triggerMessageListWidgetUpdate(Context context) {
Context appContext = context.getApplicationContext();
AppWidgetManager widgetManager = AppWidgetManager.getInstance(appContext);
ComponentName widget = new ComponentName(appContext, MessageListWidgetProvider.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widget);
Intent intent = new Intent(context, MessageListWidgetProvider.class);
intent.setAction(ACTION_UPDATE_MESSAGE_LIST);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
context.sendBroadcast(intent);
}
代码示例来源:origin: leolin310148/ShortcutBadger
public static void sendIntentExplicitly(Context context, Intent intent) throws ShortcutBadgeException {
List<ResolveInfo> resolveInfos = resolveBroadcast(context, intent);
if (resolveInfos.size() == 0) {
throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString());
}
for (ResolveInfo info : resolveInfos) {
Intent actualIntent = new Intent(intent);
if (info != null) {
actualIntent.setPackage(info.resolvePackageName);
context.sendBroadcast(actualIntent);
}
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public void sendBroadcastAsUser(Intent intent, VUserHandle user) {
SpecialComponentList.protectIntent(intent);
Context context = VirtualCore.get().getContext();
if (user != null) {
intent.putExtra("_VA_|_user_id_", user.getIdentifier());
}
context.sendBroadcast(intent);
}
代码示例来源:origin: android-hacker/VirtualXposed
public void sendBroadcast(Intent intent, int userId) {
Intent newIntent = ComponentUtils.redirectBroadcastIntent(intent, userId);
if (newIntent != null) {
VirtualCore.get().getContext().sendBroadcast(newIntent);
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public void sendBroadcastAsUser(Intent intent, VUserHandle user, String permission) {
SpecialComponentList.protectIntent(intent);
Context context = VirtualCore.get().getContext();
if (user != null) {
intent.putExtra("_VA_|_user_id_", user.getIdentifier());
}
// TODO: checkPermission
context.sendBroadcast(intent);
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public boolean onPlayerOptionSelected(MenuItem item) {
if (item.getItemId() == R.id.action_switch_background) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(BackgroundPlayer.class));
return true;
}
return false;
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public boolean onPlayerOptionSelected(MenuItem item) {
if (item.getItemId() == R.id.action_switch_popup) {
if (!PermissionHelper.isPopupEnabled(this)) {
PermissionHelper.showPopupEnablementToast(this);
return true;
}
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class));
return true;
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!