List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:net.mceoin.cominghome.NestUtils.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the main Activity. * * @param transitionType The type of transition that occurred. *///from ww w . jav a2 s .co m public static void sendNotification(Context context, String transitionType) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean notifications = prefs.getBoolean(MainActivity.PREFS_NOTIFICATIONS, true); if (!notifications) { if (debug) Log.d(TAG, "notifications are turned off"); return; } // Create an explicit content Intent that starts the main Activity Intent notificationIntent = new Intent(context, MainActivity.class); // Construct a task stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the main Activity to the task stack as the parent stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Set the notification contents builder.setSmallIcon(R.drawable.home) .setContentTitle(context.getString(R.string.nest_transition_notification_title, transitionType)) .setContentText(context.getString(R.string.nest_transition_notification_text)) .setContentIntent(notificationPendingIntent); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:edu.polyu.screamalert.SoundProcessing.java
private static void sendNotification(Context context, int notiID, String contentStr) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification noti = new NotificationCompat.Builder(Exchanger.thisContext).setContentTitle("Scream Detector") .setContentText(contentStr).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent).build(); //n1.defaults = Notification.DEFAULT_VIBRATE; //noti.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(notiID, noti); }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private NotificationManager getNotificationManager() { if (mNotificationManager != null) return mNotificationManager; final Context context = getContext(); return mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void sendMissingKey(Account account, final String authToken, byte[] saltPwdCheck) { Intent intent = KeyPasswordActivity.createKeyPasswortActivity(mContext, account, authToken, saltPwdCheck); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.notif_key) .setContentTitle(String.format(mContext.getText(R.string.notif_missing_key).toString())) .setContentText(account.name).setAutoCancel(false).setOnlyAlertOnce(true) .setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(account.name, Constants.NOTIF_MISSING_KEY, mBuilder.build()); }
From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java
public void onDestroy() { super.onDestroy(); // Remove notification ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(0); if (httpServer != null) httpServer.stop();//from w w w.j a v a2 s. c o m // Cancel potentially running tasks: if (mInitQCARTask != null && mInitQCARTask.getStatus() != InitQCARTask.Status.FINISHED) { mInitQCARTask.cancel(true); mInitQCARTask = null; } // Ensure that the asynchronous operations to initialize QCAR does // not overlap: synchronized (mShutdownLock) { // Do application deinitialization in native code: deinitApplicationNative(); // Deinit the tracker: deinitTracker(); // Deinitialize QCAR SDK: QCAR.deinit(); } System.gc(); }
From source file:org.wso2.iot.agent.utils.CommonUtils.java
public static void displayNotification(Context context, int icon, String title, String message, Class<?> sourceActivityClass, String tag, int id) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(icon);//from w w w. j a v a 2 s .c o m mBuilder.setContentTitle(title); mBuilder.setContentText(message); mBuilder.setOngoing(true); mBuilder.setOnlyAlertOnce(true); Intent resultIntent = new Intent(context, sourceActivityClass); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(sourceActivityClass); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(tag, id, mBuilder.build()); }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void notifyUserPhotoNotSynced(String accountName) { Account account = new Account(accountName, Constants.ACCOUNT_TYPE); AccountManager acm = AccountManager.get(mContext); String synced = acm.getUserData(account, NOTIF_SHOWN_PHOTO_SYNCED); if (synced == null) { Intent shopIntent = new Intent(mContext, ShopActivity.class); shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, accountName); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ShopActivity.class); stackBuilder.addNextIntent(shopIntent); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(getText(R.string.notif_photonotsynced_title)).setContentText(accountName) .setAutoCancel(true)//from w w w . j ava 2 s . com .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) .setOnlyAlertOnce(true); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(Constants.NOTIF_PHOTO_NOT_SYNCED, mBuilder.build()); acm.setUserData(account, NOTIF_SHOWN_PHOTO_SYNCED, String.valueOf(System.currentTimeMillis())); } }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java
private void updateProgressBar(final int progress, final boolean error) { switch (progress) { case DfuService.PROGRESS_CONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_connecting); break;/*from ww w .j a v a 2s.c o m*/ case DfuService.PROGRESS_STARTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_starting); break; case DfuService.PROGRESS_VALIDATING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_validating); break; case DfuService.PROGRESS_DISCONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_disconnecting); break; case DfuService.PROGRESS_COMPLETED: mTextPercentage.setText(R.string.dfu_status_completed); // let's wait a bit until we reconnect to the device again. Mainly because of the notification. When canceled immediately it will be recreated by service again. new Handler().postDelayed(new Runnable() { @Override public void run() { showFileTransferSuccessMessage(); // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); break; default: mProgressBar.setIndeterminate(false); if (error) { showErrorMessage(progress); } else { mProgressBar.setProgress(progress); mTextPercentage.setText(getString(R.string.progress, progress)); } break; } }
From source file:com.buddi.client.dfu.DfuActivity.java
private void updateProgressBar(final int progress, final int part, final int total, final boolean error) { switch (progress) { case DfuService.PROGRESS_CONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_connecting); break;//from w w w . j ava2 s . c o m case DfuService.PROGRESS_STARTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_starting); break; case DfuService.PROGRESS_VALIDATING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_validating); break; case DfuService.PROGRESS_DISCONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_disconnecting); break; case DfuService.PROGRESS_COMPLETED: mTextPercentage.setText(R.string.dfu_status_completed); // let's wait a bit until we cancel the notification. When canceled immediately it will be recreated by service again. new Handler().postDelayed(new Runnable() { @Override public void run() { onTransferCompleted(); // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); break; case DfuService.PROGRESS_ABORTED: mTextPercentage.setText(R.string.dfu_status_aborted); // let's wait a bit until we cancel the notification. When canceled immediately it will be recreated by service again. new Handler().postDelayed(new Runnable() { @Override public void run() { onUploadCanceled(); // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); break; default: mProgressBar.setIndeterminate(false); if (error) { showErrorMessage(progress); } else { mProgressBar.setProgress(progress); mTextPercentage.setText(getString(R.string.progress, progress)); if (total > 1) mTextUploading.setText(getString(R.string.dfu_status_uploading_part, part, total)); else mTextUploading.setText(R.string.dfu_status_uploading); } break; } }
From source file:eu.operando.operandoapp.OperandoProxyStatus.java
private void LoadPendingNotificationsTab() { final String addAllowedSuccessful = "Added to Allowed Domains Successfully", addAllowedUnsuccessfull = "This domain already exists in your allowed domain list", addBlockedSuccessfull = "Added to Blocked Domains Successfully", addBlockedUnsuccessfull = "This domain already exists in your blocked domain list"; try {// w ww . j a va 2s . c om for (final PendingNotification pending_notification : new DatabaseHelper(this) .getAllPendingNotifications()) { String info = pending_notification.app_info + " || " + pending_notification.permission + " || " + pending_notification.id; Button b = new Button(this); b.setText(info); b.setLayoutParams(new LinearLayout.LayoutParams(android.app.ActionBar.LayoutParams.MATCH_PARENT, android.app.ActionBar.LayoutParams.WRAP_CONTENT)); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView)) .getChildAt(0)).getChildAt(1)).addView(b); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { final int notificationId = Integer .parseInt(((Button) v).getText().toString().split(" \\|\\| ")[2]); new AlertDialog.Builder(MainActivity.this).setIcon(R.drawable.logo_bevel) .setTitle("Manage Application Permission") .setMessage("What do you want to do with this specific application permission?") .setPositiveButton("ALLOW", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DatabaseHelper db = new DatabaseHelper(MainActivity.this); boolean add = true; for (String permission : pending_notification.permission .split("\\, ")) { add = add && db.addAllowedDomain(pending_notification.app_info, permission); } boolean remove = db.removePendingNotification(notificationId); ((NotificationManager) MainActivity.this .getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(notificationId); Toast.makeText(MainActivity.this, add && remove ? addAllowedSuccessful : addAllowedUnsuccessfull, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(MainActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show(); } ((TableLayout) ((LinearLayout) ((ScrollView) findViewById( R.id.PendingNotificationsScrollView)).getChildAt(0)) .getChildAt(1)).removeAllViews(); LoadPendingNotificationsTab(); new DatabaseHelper(MainActivity.this).sendSettingsToServer( new RequestFilterUtil(MainActivity.this).getIMEI()); } }).setNegativeButton("BLOCK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DatabaseHelper db = new DatabaseHelper(MainActivity.this); boolean add = true; for (String permission : pending_notification.permission .split("\\, ")) { add = add && db.addBlockedDomain(pending_notification.app_info, permission); } boolean remove = db.removePendingNotification(notificationId); ((NotificationManager) MainActivity.this .getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(notificationId); Toast.makeText(MainActivity.this, add && remove ? addBlockedSuccessfull : addBlockedUnsuccessfull, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(MainActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show(); } ((TableLayout) ((LinearLayout) ((ScrollView) findViewById( R.id.PendingNotificationsScrollView)).getChildAt(0)) .getChildAt(1)).removeAllViews(); LoadPendingNotificationsTab(); new DatabaseHelper(MainActivity.this).sendSettingsToServer( new RequestFilterUtil(MainActivity.this).getIMEI()); } }).setNeutralButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //nothing } }).show(); } catch (Exception e) { Log.d("ERROR", e.getMessage()); } } }); } } catch (Exception e) { Log.d("ERROR", e.getMessage()); } }