List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.nttec.everychan.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Logger.d(TAG, "main activity creating"); settings = MainApplication.getInstance().settings.getStaticSettings(); autohideRulesHash = MainApplication.getInstance().settings.getAutohideRulesJson().hashCode(); rootViewWeight = MainApplication.getInstance().settings.getRootViewWeight(); tabsPanelRight = MainApplication.getInstance().settings.isTabsPanelOnRight(); openSpoilers = MainApplication.getInstance().settings.openSpoilers(); highlightSubscriptions = MainApplication.getInstance().settings.highlightSubscriptions(); swipeToHideThread = MainApplication.getInstance().settings.swipeToHideThread(); isHorizontalOrientation = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; (theme = MainApplication.getInstance().settings.getTheme()).setTo(this); super.onCreate(savedInstanceState); if (MainApplication.getInstance().settings.showSidePanel()) { setContentView(tabsPanelRight ? R.layout.main_activity_tablet_right : R.layout.main_activity_tablet); LinearLayout.LayoutParams sidebarLayoutParams = (LinearLayout.LayoutParams) findViewById(R.id.sidebar) .getLayoutParams();/*www . ja v a 2 s .c o m*/ Point displaySize = AppearanceUtils.getDisplaySize(getWindowManager().getDefaultDisplay()); int rootWidth = (int) (displaySize.x * rootViewWeight); sidebarLayoutParams.width = displaySize.x - rootWidth; findViewById(R.id.sidebar).setLayoutParams(sidebarLayoutParams); } else { setContentView(R.layout.main_activity_drawer); updateTabPanelTabletWeight(); } initDrawer(); View[] sidebarButtons = new View[] { findViewById(R.id.sidebar_btn_newtab), findViewById(R.id.sidebar_btn_history), findViewById(R.id.sidebar_btn_favorites) }; hiddenTabsSection = new HiddenTabsSection(sidebarButtons); DragSortListView list = (DragSortListView) findViewById(R.id.sidebar_tabs_list); TabsState state = MainApplication.getInstance().tabsState; tabsAdapter = initTabsListView(list, state); handleUriIntent(getIntent()); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { Logger.e(TAG, "received broadcast with NULL action"); return; } if (action.equals(PostingService.BROADCAST_ACTION_STATUS)) { int progress = intent.getIntExtra(PostingService.EXTRA_BROADCAST_PROGRESS_STATUS, -1); switch (progress) { case PostingService.BROADCAST_STATUS_SUCCESS: UrlHandler.open(intent.getStringExtra(PostingService.EXTRA_TARGET_URL), MainActivity.this); notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID); break; case PostingService.BROADCAST_STATUS_ERROR: Intent toPostForm = new Intent(MainActivity.this, PostFormActivity.class); toPostForm.putExtra(PostingService.EXTRA_PAGE_HASH, intent.getStringExtra(PostingService.EXTRA_PAGE_HASH)); toPostForm.putExtra(PostingService.EXTRA_SEND_POST_MODEL, intent.getSerializableExtra(PostingService.EXTRA_SEND_POST_MODEL)); toPostForm.putExtra(PostingService.EXTRA_BOARD_MODEL, intent.getSerializableExtra(PostingService.EXTRA_BOARD_MODEL)); toPostForm.putExtra(PostingService.EXTRA_RETURN_FROM_SERVICE, true); toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON, intent.getIntExtra(PostingService.EXTRA_RETURN_REASON, 0)); String error = intent.getStringExtra(PostingService.EXTRA_RETURN_REASON_ERROR); Serializable interactiveException = intent .getSerializableExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION); if (error != null) { toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_ERROR, error); } if (interactiveException != null) { toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION, interactiveException); } startActivity(toPostForm); notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID); break; } } else if (action.equals(TabsTrackerService.BROADCAST_ACTION_NOTIFY)) { tabsAdapter.notifyDataSetChanged(false); TabsTrackerService.clearUnread(); } } }; intentFilter = new IntentFilter(); intentFilter.addAction(PostingService.BROADCAST_ACTION_STATUS); intentFilter.addAction(TabsTrackerService.BROADCAST_ACTION_NOTIFY); if (!TabsTrackerService.isRunning() && MainApplication.getInstance().settings.isAutoupdateEnabled()) startService(new Intent(this, TabsTrackerService.class)); if (MainApplication.getInstance().settings.isSFWRelease()) NewsReader.checkNews(this); }
From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java
public void runIntent() { updateIntent();/* ww w. j av a 2 s . c om*/ IRemoteInterface remoteInterface = RunAsManager.getSelectedRemoteInterface(); Intent intent = mEditedIntent; IntentTracker intentTracker = getIntentTracker(); if (intentTracker != null) { intent = intentTracker.tagIntent(intent); } try { switch (getComponentType()) { case IntentEditorConstants.ACTIVITY: switch (getMethodId()) { case IntentEditorConstants.ACTIVITY_METHOD_STARTACTIVITY: if (remoteInterface != null) { startActivityRemote(remoteInterface, false); } else { startActivity(intent); } break; case IntentEditorConstants.ACTIVITY_METHOD_STARTACTIVITYFORRESULT: if (remoteInterface != null) { startActivityRemote(remoteInterface, true); } else { startActivityForResult(intent, REQUEST_CODE_TEST_STARTACTIVITYFORRESULT); } break; } break; case IntentEditorConstants.BROADCAST: switch (getMethodId()) { case IntentEditorConstants.BROADCAST_METHOD_SENDBROADCAST: sendBroadcast(intent); break; case IntentEditorConstants.BROADCAST_METHOD_SENDORDEREDBROADCAST: { sendOrderedBroadcast(intent, // intent null, // permission new BroadcastReceiver() { // resultReceiver @Override public void onReceive(Context context, Intent intent) { Bundle resultExtras = getResultExtras(false); new AlertDialog.Builder(IntentEditorActivity.this).setMessage(getString( R.string.received_broadcast_result) + "\ngetResultCode() = " + getResultCode() + "\ngetResultData() = " + getResultData() + "\ngetResultExtras() = " + (resultExtras == null ? "null" : resultExtras.isEmpty() ? "[Empty Bundle]" : "[Bundle]") ).setPositiveButton("OK", null).show(); } }, null, // scheduler 0, // initialCode null, // initialData null // initialExtras ); } break; case IntentEditorConstants.BROADCAST_METHOD_SENDSTICKYBROADCAST: sendStickyBroadcast(intent); break; } break; case IntentEditorConstants.SERVICE: switch (getMethodId()) { case IntentEditorConstants.SERVICE_METHOD_STARTSERVICE: startService(intent); break; default: { if (!SandboxManager.isSandboxInstalled(this)) { SandboxManager.requestSandboxInstall(this); } else { BindServiceManager.prepareBinderAndShowUI(this, new BindServiceDescriptor(new Intent(intent))); } } } break; case IntentEditorConstants.RESULT: setResult(0, new Intent().putExtra(EXTRA_FORWARD_RESULT_CODE, mMethodId) .putExtra(EXTRA_FORWARD_RESULT_INTENT, intent)); finish(); break; } } catch (Throwable exception) { Utils.toastException(this, exception); } }
From source file:org.gaeproxy.GAEProxyService.java
@Override public void onCreate() { super.onCreate(); mShutdownReceiver = new BroadcastReceiver() { @Override/* w w w . j a v a 2 s . c o m*/ public void onReceive(Context context, Intent intent) { stopSelf(); } }; IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN); registerReceiver(mShutdownReceiver, filter); EasyTracker.getTracker().trackEvent("service", "start", getVersionName(), 0L); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); settings = PreferenceManager.getDefaultSharedPreferences(this); Intent intent = new Intent(this, GAEProxyActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new Notification(); try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; } try { mSetForeground = getClass().getMethod("setForeground", mSetForegroundSignature); } catch (NoSuchMethodException e) { throw new IllegalStateException("OS doesn't have Service.startForeground OR Service.setForeground!"); } }
From source file:com.mine.psf.PsfPlaybackService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. * The intent will call closeExternalStorageFiles() if the external media * is going to be ejected, so applications can clean up any files they have open. *//*from w w w .j ava 2s .c o m*/ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { Log.d(LOGTAG, "SD Card Ejected, stop..."); saveQueue(); stop(); notifyChange(META_CHANGED); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { reloadQueue(); notifyChange(META_CHANGED); Log.d(LOGTAG, "SD Card Mounted..."); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme("file"); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.taobao.weex.dom.WXTextDomObject.java
private void registerTypefaceObserverIfNeed(String desiredFontFamily) { if (TextUtils.isEmpty(desiredFontFamily)) { return;/*w w w.ja va 2s . c o m*/ } if (WXEnvironment.getApplication() == null) { WXLogUtils.w("WXText", "ApplicationContent is null on register typeface observer"); return; } mFontFamily = desiredFontFamily; if (mTypefaceObserver != null) { return; } mTypefaceObserver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String fontFamily = intent.getStringExtra("fontFamily"); if (!mFontFamily.equals(fontFamily)) { return; } if (isDestroy() || getDomContext() == null) { return; } DOMActionContext domActionContext = WXSDKManager.getInstance().getWXDomManager() .getDomContext(getDomContext().getInstanceId()); if (domActionContext == null) { return; } WXDomObject domObject = domActionContext.getDomByRef(getRef()); if (domObject == null) { return; } domObject.markDirty(); domActionContext.markDirty(); WXSDKManager.getInstance().getWXDomManager() .sendEmptyMessageDelayed(WXDomHandler.MsgType.WX_DOM_START_BATCH, 2); if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("WXText", "Font family " + fontFamily + " is available"); } } }; if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("WXText", "Font family register " + desiredFontFamily + " is available" + getRef()); } LocalBroadcastManager.getInstance(WXEnvironment.getApplication()).registerReceiver(mTypefaceObserver, new IntentFilter(TypefaceUtil.ACTION_TYPE_FACE_AVAILABLE)); }
From source file:com.moez.QKSMS.mmssms.Transaction.java
private void sendMmsMessage(String text, String[] addresses, Bitmap[] image, String[] imageNames, byte[] media, String mimeType, String subject) { // merge the string[] of addresses into a single string so they can be inserted into the database easier String address = ""; for (int i = 0; i < addresses.length; i++) { address += addresses[i] + " "; }/* ww w.j a v a 2 s. c om*/ address = address.trim(); // create the parts to send ArrayList<MMSPart> data = new ArrayList<>(); for (int i = 0; i < image.length; i++) { // turn bitmap into byte array to be stored byte[] imageBytes = Message.bitmapToByteArray(image[i]); MMSPart part = new MMSPart(); part.MimeType = "image/jpeg"; part.Name = (imageNames != null) ? imageNames[i] : ("image" + i); part.Data = imageBytes; data.add(part); } // add any extra media according to their mimeType set in the message // eg. videos, audio, contact cards, location maybe? if (media.length > 0 && mimeType != null) { MMSPart part = new MMSPart(); part.MimeType = mimeType; part.Name = mimeType.split("/")[0]; part.Data = media; data.add(part); } if (!text.equals("")) { // add text to the end of the part and send MMSPart part = new MMSPart(); part.Name = "text"; part.MimeType = "text/plain"; part.Data = text.getBytes(); data.add(part); } MessageInfo info; try { info = getBytes(context, saveMessage, address.split(" "), data.toArray(new MMSPart[data.size()]), subject); } catch (MmsException e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); return; } try { MmsMessageSender sender = new MmsMessageSender(context, info.location, info.bytes.length); sender.sendMessage(info.token); IntentFilter filter = new IntentFilter(); filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int progress = intent.getIntExtra("progress", -3); if (LOCAL_LOGV) Log.v(TAG, "progress: " + progress); // send progress broadcast to update ui if desired... Intent progressIntent = new Intent(MMS_PROGRESS); progressIntent.putExtra("progress", progress); context.sendBroadcast(progressIntent); if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) { context.sendBroadcast(new Intent(REFRESH)); try { context.unregisterReceiver(this); } catch (Exception e) { // TODO fix me // receiver is not registered force close error... hmm. } } else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) { // This seems to get called only after the progress has reached 100 and then something else goes wrong, so here we will try and send again and see if it works if (LOCAL_LOGV) Log.v(TAG, "sending aborted for some reason..."); } } }; context.registerReceiver(receiver, filter); } catch (Throwable e) { Log.e(TAG, "exception thrown", e); // insert the pdu into the database and return the bytes to send if (settings.getWifiMmsFix()) { sendMMS(info.bytes); } else { sendMMSWiFi(info.bytes); } } }
From source file:com.mine.psf.PsfPlaybackService.java
private void registerNoisyListener() { if (mNoisyReceiver == null) { mNoisyReceiver = new BroadcastReceiver() { @Override/*from w w w .ja va2 s .co m*/ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { Log.d(LOGTAG, "To become noisy, pause"); pause(); } } }; IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); registerReceiver(mNoisyReceiver, filter); } }
From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.HXMainActivity.java
/** * debug purpose only, you can ignore this */// w w w .j ava2s.c o m private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { DemoHelper.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { finish(); // startActivity(new Intent(HXMainActivity.this, LoginActivity.class)); } }); } @Override public void onProgress(int progress, String status) { } @Override public void onError(int code, String message) { } }); } }; IntentFilter filter = new IntentFilter(getPackageName() + ".em_internal_debug"); registerReceiver(internalDebugReceiver, filter); }
From source file:com.hypodiabetic.happ.MainActivity.java
@Override protected void onResume() { super.onResume(); //xdrip start extendedGraphBuilder = new ExtendedGraphBuilder(getApplicationContext()); _broadcastReceiver = new BroadcastReceiver() { @Override// w ww. j ava2 s . c o m public void onReceive(Context ctx, Intent intent) { if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) { setupBGCharts(); displayCurrentInfo(); holdViewport.set(0, 0, 0, 0); } } }; newDataReceiver = new BroadcastReceiver() { @Override public void onReceive(Context ctx, Intent intent) { setupBGCharts(); displayCurrentInfo(); holdViewport.set(0, 0, 0, 0); } }; registerReceiver(_broadcastReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); registerReceiver(newDataReceiver, new IntentFilter(Intents.ACTION_NEW_BG)); setupBGCharts(); displayCurrentInfo(); holdViewport.set(0, 0, 0, 0); //xdrip end //listens out for new Stats newStatsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); Stats stat = gson.fromJson(intent.getStringExtra("stat"), Stats.class); updateStats(stat); displayCurrentInfo(); } }; registerReceiver(newStatsReceiver, new IntentFilter("ACTION_UPDATE_STATS")); updateStats(null); //listens out for openAPS updates newAPSUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); APSResult apsResult = gson.fromJson(intent.getStringExtra("APSResult"), APSResult.class); updateOpenAPSDetails(apsResult); setupBGCharts(); displayCurrentInfo(); } }; registerReceiver(newAPSUpdate, new IntentFilter("APS_UPDATE")); //listens out for app notifications appNotification = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int snackbar_length; snackbar_length = intent.getIntExtra("snackbar_length", Snackbar.LENGTH_INDEFINITE); final String alertDialogText = intent.getStringExtra("alertDialogText"); String snackBarMsg = intent.getStringExtra("snackBarMsg"); Snackbar snackbar = Snackbar .make(MainActivity.activity.findViewById(R.id.mainActivity), snackBarMsg, snackbar_length) .setAction("DETAILS", new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity); builder.setMessage(alertDialogText); builder.setPositiveButton("OK", null); builder.show(); } }); snackbar.show(); } }; registerReceiver(appNotification, new IntentFilter("NEW_APP_NOTIFICATION")); }
From source file:com.lemon.lime.MainActivity.java
private void getBatteryPercentage() { BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { context.unregisterReceiver(this); int currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if (currentLevel >= 0 && scale > 0) { level = (currentLevel * 100) / scale; }//from www . j a v a2 s .c o m } }; IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(batteryLevelReceiver, batteryLevelFilter); }