当前位置: 首页>>代码示例>>Java>>正文


Java Context.sendBroadcast方法代码示例

本文整理汇总了Java中android.content.Context.sendBroadcast方法的典型用法代码示例。如果您正苦于以下问题:Java Context.sendBroadcast方法的具体用法?Java Context.sendBroadcast怎么用?Java Context.sendBroadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.sendBroadcast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: notifyPause

import android.content.Context; //导入方法依赖的package包/类
public static void notifyPause(Context mContext, DownloadInfo info) {
    if (callbackCategory == DataCallbackCategory.BROADCAST) {
        Intent notifyIntent = baseIntent(mContext, info);
        notifyIntent.putExtra("type", 3);
        mContext.sendBroadcast(notifyIntent);
        return;
    }
    callbackClient(3, info);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:10,代码来源:NotifyManage.java

示例2: processCustomMessage

import android.content.Context; //导入方法依赖的package包/类
private void processCustomMessage(Context context, Bundle bundle) {
	if (MainActivity.isForeground) {
		String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
		String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
		Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
		msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
		if (!ExampleUtil.isEmpty(extras)) {
			try {
				JSONObject extraJson = new JSONObject(extras);
				if (extraJson.length() > 0) {
					msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
				}
			} catch (JSONException e) {

			}

		}
		context.sendBroadcast(msgIntent);
	}
}
 
开发者ID:LuoLuo0101,项目名称:JPush,代码行数:21,代码来源:MyReceiver.java

示例3: writeToUri

import android.content.Context; //导入方法依赖的package包/类
public static int writeToUri(Context context, Filesystem filesystem, LocalFilesystemURL inputURL, String data, int offset, boolean isBinary) throws NoModificationAllowedException {
    Uri uri = filesystem.toNativeUri(inputURL);
    OutputStream outputStream = null;

    try {
        outputStream = context.getContentResolver().openOutputStream(uri);

        byte[] rawData;
        if (isBinary) {
            rawData = Base64.decode(data, Base64.DEFAULT);
        } else {
            rawData = data.getBytes(Charset.defaultCharset());
        }

        outputStream.write(rawData);
        outputStream.flush();
        outputStream.close();

        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
        context.sendBroadcast(intent);

        return rawData.length;

    } catch (Exception e) {
        NoModificationAllowedException exception = new NoModificationAllowedException("Couldn't write to file given its content URI");
        exception.initCause(e);
        throw exception;
    }
}
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:30,代码来源:FileWriter.java

示例4: updateWidgets

import android.content.Context; //导入方法依赖的package包/类
private void updateWidgets() {
    Context context = getContext();
    // Setting the package ensures that only components in our app will receive the broadcast
    Intent dataUpdatedIntent = new Intent(ACTION_DATA_UPDATED)
            .setPackage(context.getPackageName());
    context.sendBroadcast(dataUpdatedIntent);
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:8,代码来源:SunshineSyncAdapter.java

示例5: onPushMsg

import android.content.Context; //导入方法依赖的package包/类
/**
 * 推送消息下来时会自动回调onPushMsg方法实,现应用透传消息处理
 *
 * @param extras 扩展信息,暂时不启用
 * @return 统一返回false, 暂时没有作用(官方文档未予说明)
 */
@Override
public boolean onPushMsg(Context context, byte[] msg, Bundle extras) {
  Intent intent = new Intent(JINGOAL_PUSH_ACTION);
  intent.putExtra(PUS_CLIENT_TYPE, NXTReceiver.PushClientType.HUA_WEI);
  intent.putExtra(MSG_CONTENT, new String(msg));
  intent.putExtra(NXTReceiver.MESSAGE_TYPE, NXTReceiver.MessageType.MESSAGE);
  context.sendBroadcast(intent);
  return false;
}
 
开发者ID:pengkobe,项目名称:nxtpush-cordova-plugin,代码行数:16,代码来源:HuaWeiReceiver.java

示例6: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
  if (intent.getAction().matches("android.intent.action.AIRPLANE_MODE")) {
    String airplaneMode = (new AirplaneModeSettingsHandler(context)).getSetting();

    Intent i = new Intent(Constants.AIRPLANE_MODE_CHANGED);
    i.putExtra(Constants.AIRPLANE_MODE_SETTING, airplaneMode);
    context.sendBroadcast(i);
  }
}
 
开发者ID:rmrs,项目名称:react-native-settings,代码行数:11,代码来源:AirplaneModeReceiver.java

示例7: clearAllNotifications

import android.content.Context; //导入方法依赖的package包/类
@Override
public void clearAllNotifications(Context context) {
    context.sendBroadcast(intent);
    //方法执行后,不会马上清除所有的消息,而是在通知栏下拉,通知内容变得可见后才清除。
    //所以在这里调用一次下拉通知栏的方法
    //再收起通知栏
    try {
        Object statusBarManager = context.getSystemService("statusbar");
        Method expand;
        expand = statusBarManager.getClass().getMethod("expandNotificationsPanel");
        expand.invoke(statusBarManager);
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}
 
开发者ID:EggUncle,项目名称:XposedNavigationBar,代码行数:16,代码来源:BtnClearAllNotifications.java

示例8: updateWidget

import android.content.Context; //导入方法依赖的package包/类
private static void updateWidget(Context context) {
  ComponentName name   = new ComponentName(context, BooksWidgetProvider.class);
  int[]         ids    = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
  Intent        intent = new Intent(context, BooksWidgetProvider.class);
  intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
  intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
  context.sendBroadcast(intent);
}
 
开发者ID:paulnunezm,项目名称:Boookito-Capstone-Project,代码行数:9,代码来源:FirebaseRepo.java

示例9: addShortcutIcon

import android.content.Context; //导入方法依赖的package包/类
public static void addShortcutIcon(Context context, PreferencesRepository preferencesRepository){

        if (!preferencesRepository.isShortCutCreated()) {
            Intent shortcutIntent = new Intent(context, SplashActivity.class);
            shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, R.string.app_name);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher));
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            addIntent.putExtra("duplicate", false);
            context.sendBroadcast(addIntent);

            preferencesRepository.setShortCutCreate(true);
        }
    }
 
开发者ID:afiqiqmal,项目名称:MVP-Android,代码行数:19,代码来源:DeviceUtils.java

示例10: onReceive

import android.content.Context; //导入方法依赖的package包/类
@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) {
        VLog.d("IntentSender", "onReceive's realIntent =" + realIntent + ",extra=" + VLog.toString(realIntent.getExtras()));
        Intent newIntent = ComponentUtils.redirectBroadcastIntent(realIntent, userId);
        if (newIntent != null) {
            context.sendBroadcast(newIntent);
        }
    }
}
 
开发者ID:codehz,项目名称:container,代码行数:13,代码来源:StubPendingReceiver.java

示例11: sendRefreshBroadcast

import android.content.Context; //导入方法依赖的package包/类
public static void sendRefreshBroadcast(Context context) {
    Intent intent = new Intent(context, TodoListAppWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    ComponentName component = new ComponentName(context, TodoListAppWidgetProvider.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, manager.getAppWidgetIds(component));
    context.sendBroadcast(intent);
}
 
开发者ID:djuelg,项目名称:Neuronizer,代码行数:9,代码来源:TodoListAppWidgetProvider.java

示例12: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    if (extras == null)
        return;

    // To display mContext Toast whenever there is an SMS.
    // Toast.makeText(mainScriptContext,"Recieved",Toast.LENGTH_LONG).show();

    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String sender = SMessage.getOriginatingAddress();
        String body = SMessage.getMessageBody().toString();

        // A custom Intent that will used as another Broadcast
        Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("get_msg", sender + ":" + body);

        // You can place your check conditions here(on the SMS or the
        // sender)
        // and then send another broadcast
        context.sendBroadcast(in);

        // This is used to abort the broadcast and can be used to silently
        // process incoming message and prevent it from further being
        // broadcasted. Avoid this, as this is not the way to program an
        // app.
        // this.abortBroadcast();
    }
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:32,代码来源:SmsReceiver.java

示例13: sendIcon2HomeScreen

import android.content.Context; //导入方法依赖的package包/类
public static boolean sendIcon2HomeScreen(Context context, int iconId, String appName,
                                          String pkgName, String launcherName) {
    if (context == null || iconId == 0 || TextUtils.isEmpty(appName)
            || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(launcherName)) {
        return false;
    }

    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
    shortcutIntent.setClassName(pkgName, launcherName);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";

    Intent addIntent = new Intent();
    addIntent.setAction(ACTION_ADD_SHORTCUT);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, iconId));
    addIntent.putExtra("duplicate", false);
    context.sendBroadcast(addIntent);

    return true;
}
 
开发者ID:by-syk,项目名称:NanoIconPack,代码行数:26,代码来源:ExtraUtil.java

示例14: udpateMedia

import android.content.Context; //导入方法依赖的package包/类
public static void udpateMedia(Context context, String url) {
    //图片路径
    File file = new File(url);
    ContentResolver localContentResolver = context.getContentResolver();
    ContentValues localContentValues = getImageContentValues(context, file, System.currentTimeMillis());
    localContentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues);
    Intent localIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
    final Uri localUri = Uri.fromFile(file);
    localIntent.setData(localUri);
    //发送广播即时更新图库
    context.sendBroadcast(localIntent);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:13,代码来源:RUtils.java

示例15: changeGpsStatus

import android.content.Context; //导入方法依赖的package包/类
private void changeGpsStatus(final Context context, final boolean status) {
    if (AppUtil.sdkVersion() < 19 && isGpsAvailable(context)) {
        Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
        intent.putExtra("enabled", status);
        context.sendBroadcast(intent);
    }
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:8,代码来源:GpsManager.java


注:本文中的android.content.Context.sendBroadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。