List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:it.evilsocket.dsploit.core.UpdateService.java
/** * connect to the notification manager and create a notification builder. * it also setup the cancellation Intent for get notified when our notification got cancelled. *//* ww w . ja v a 2 s .c o m*/ private void setupNotification() { // get notification manager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // get notification builder mBuilder = new NotificationCompat.Builder(this); // create a broadcast receiver to get actions // performed on the notification by the user mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return; // user cancelled our notification if (action.equals(NOTIFICATION_CANCELLED)) { mRunning = false; stopSelf(); } } }; // register our receiver registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED)); // set common notification actions mBuilder.setDeleteIntent( PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0)); mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)); }
From source file:org.csploit.android.core.UpdateService.java
/** * connect to the notification manager and create a notification builder. * it also setup the cancellation Intent for get notified when our notification got cancelled. *///from www . ja v a 2 s . c o m private void setupNotification() { // get notification manager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // get notification builder mBuilder = new NotificationCompat.Builder(this); // create a broadcast receiver to get actions // performed on the notification by the user mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return; // user cancelled our notification if (action.equals(NOTIFICATION_CANCELLED)) { mRunning = false; } } }; // register our receiver registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED)); // set common notification actions mBuilder.setDeleteIntent( PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0)); mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)); }
From source file:com.tonyodev.fetch.FetchService.java
private void updateRequestUrl(final long id, final String url) { if (activeDownloads.containsKey(id)) { runningTask = true;//from w ww . j av a2s.c o m BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (FetchRunnable.getIdFromIntent(intent) == id) { updateRequestUrlAction(id, url); broadcastManager.unregisterReceiver(this); registeredReceivers.remove(this); runningTask = false; startDownload(); } } }; registeredReceivers.add(broadcastReceiver); broadcastManager.registerReceiver(broadcastReceiver, FetchRunnable.getDoneFilter()); interruptActiveDownload(id); } else { updateRequestUrlAction(id, url); startDownload(); } }
From source file:cn.moon.superwechat.ui.MainActivity.java
/** * debug purpose only, you can ignore this *//* w w w . j a va2s . c o m*/ private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SuperWeChatHelper.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { finish(); startActivity(new Intent(MainActivity.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:cn.ucai.wechat.ui.MainActivity.java
/** * debug purpose only, you can ignore this *///from w w w.j av a 2 s .c om private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { WeChatHelper.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { finish(); startActivity(new Intent(MainActivity.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:de.da_sense.moses.client.WelcomeActivity.java
@Override protected void onResume() { super.onResume(); /*//from ww w . j a v a2 s. com * Register the RECEIVER for receiving informations about connectivity * to Internet ############## */ mConnReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { Log.i(LOG_TAG, "Internet connection changed"); ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo currentNetworkInfo = cm.getActiveNetworkInfo(); // go through all Fragments and inform the ones implementing the // InternetConnectionChangeListener for (WeakReference<Fragment> fragRef : mFragList) { Fragment fragment = fragRef.get(); if (fragment != null && fragment instanceof InternetConnectionChangeListener) { InternetConnectionChangeListener listener = (InternetConnectionChangeListener) fragment; if (currentNetworkInfo != null && currentNetworkInfo.isConnected()) { Log.d(LOG_TAG, "Informing a fragment about the establishment of the Internet connection"); listener.onConnectionEstablished(); } else { Log.d(LOG_TAG, "Informing a fragment about the loss of the Internet connection"); listener.onConnectionLost(); } } } } }; registerReceiver(mConnReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); /* * RECEIVER END * ######################################################### * #################### */ checkInstalledStatesOfApks(); Intent startingIntent = getIntent(); if (startingIntent.hasExtra(WelcomeActivity.KEY_VIEW_SURVEY)) { // some other activity has started this activity in order to show an // available survey, just scroll // to running fragment and let him do the rest mViewPager.setCurrentItem(WelcomeActivityPagerAdapter.TAB_RUNNING, true); } }
From source file:com.tealeaf.TeaLeaf.java
private void makeScreenOffReceiver() { screenOffReciever = new BroadcastReceiver() { @Override//w ww. j a v a2 s .co m public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub soundQueue.onPause(); soundQueue.pauseSound(SoundQueue.LOADING_SOUND); } }; }
From source file:cn.wyl.superwechat.ui.MainActivity.java
/** * debug purpose only, you can ignore this *//*from w w w.j a v a 2 s . c om*/ private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SuperWeChatHelper.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { finish(); startActivity(new Intent(MainActivity.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.nexmo.sdk.verify.client.VerifyClient.java
/** * Handle the GCM notifications broadcast receiver, enable it to automatically trigger the check request * for the ongoing verify./*from w w w . j ava 2s . c o m*/ */ private void setGcmBroadcastReceiver() { this.gcmPayloadBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.hasExtra(VerifyGcmListenerService.MESSAGE_KEY_PIN)) { String pinCode = intent.getExtras().getString(VerifyGcmListenerService.MESSAGE_KEY_PIN); Log.d(TAG, "gcmPayloadBroadcastReceiver Pin: " + pinCode); manageCheckPin(pinCode); } } }; LocalBroadcastManager.getInstance(this.nexmoClient.getContext()).registerReceiver( this.gcmPayloadBroadcastReceiver, new IntentFilter(VerifyGcmListenerService.ACTION_BROADCAST_PIN)); }
From source file:com.mk4droid.IMC_Activities.Fragment_Map.java
private void HandlersAndReceivers() { //----- Handler for Redrawing Markers from update thread ------------ handlerMarkersUPD = new Handler() { public void handleMessage(Message msg) { setUpMap();//from w w w .ja v a2 s .c o m PutMarkers(msg.arg1); // 1 rezoom, 2 no-rezoom super.handleMessage(msg); } }; //----- Handler for Redrawing Markers from update thread ------------ handlerBroadcastRefresh = new Handler() // Broadcast 1. Refresh Button 2. DistanceCh 3. IssuesNoCh { public void handleMessage(Message msg) { if (msg.arg1 == 1) // Refresh Button ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("Refresh", "ok")); else if (msg.arg1 == 2) ctx.sendBroadcast( new Intent("android.intent.action.MAIN").putExtra("DistanceChanged", "Indeed")); else if (msg.arg1 == 3) ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("IssuesNoChanged", "yep")); super.handleMessage(msg); } }; //--------------- Receiver for Data change ------------ intentFilter = new IntentFilter("android.intent.action.MAIN"); // DataCh mReceiverDataChanged = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String DataChanged = intent.getStringExtra("DataChanged"); String mes_touser = intent.getStringExtra("mes_touser"); int progressval = intent.getIntExtra("progressval", -1); String progressBarVis = intent.getStringExtra("ProgressBar"); if (progressBarVis != null) { if (progressBarVis.length() > 0) { if (progressBarVis.equals("Visible")) pbgeneral.setVisibility(View.VISIBLE); else if (progressBarVis.equals("Gone")) pbgeneral.setVisibility(View.GONE); } } if (DataChanged != null) { Log.e("FMain: DataChanged", " " + DataChanged); if (mes_touser != null) if ((mes_touser.trim()).length() > 0) Toast.makeText(ctx, mes_touser, Toast.LENGTH_LONG).show(); pbgeneral.setVisibility(View.GONE); Message msg = new Message(); msg.arg1 = 1; handlerMarkersUPD.sendMessage(msg); } if (progressval != -1) { pbgeneral.setProgress(progressval); } } }; ctx.registerReceiver(mReceiverDataChanged, intentFilter); }