本文整理匯總了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);
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
}