List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java
private void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { // raise notification Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE);//from w w w. j a va 2s . c o m PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } }
From source file:org.wso2.iot.agent.services.operation.OperationManager.java
/** * Lock the device.//from w w w . java 2 s .c om * * @param operation - Operation object. */ public void lockDevice(org.wso2.iot.agent.beans.Operation operation) throws AndroidAgentException { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); JSONObject inputData; String message = null; boolean isHardLockEnabled = false; try { if (operation.getPayLoad() != null) { inputData = new JSONObject(operation.getPayLoad().toString()); message = inputData.getString(Constants.ADMIN_MESSAGE); isHardLockEnabled = inputData.getBoolean(Constants.IS_HARD_LOCK_ENABLED); } } catch (JSONException e) { operation.setStatus(resources.getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing LOCK payload."); resultBuilder.build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } if (isHardLockEnabled && Constants.SYSTEM_APP_ENABLED) { if (message == null || message.isEmpty()) { message = resources.getString(R.string.txt_lock_activity); } Preference.putBoolean(context, Constants.IS_LOCKED, true); Preference.putString(context, Constants.LOCK_MESSAGE, message); operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); enableHardLock(message, operation); } else { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.alert_message)) .setContentText(message).setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, mBuilder.build()); devicePolicyManager.lockNow(); } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device locked"); } }
From source file:com.automated.taxinow.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w . jav a 2s . co m*/ private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message); int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainDrawerActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(0, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:jp.co.conit.sss.sp.ex1.billing.BillingService.java
/** * ????//w ww . j av a 2 s . c o m */ private void notificationRestore() { Context context = getApplicationContext(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(); Intent intent = new Intent(); PendingIntent pendingintent = PendingIntent.getActivity(context, 0, intent, 0); notification.icon = R.drawable.ic_status; notification.tickerText = context.getString(R.string.notification_restore); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, context.getString(R.string.notification_restore), context.getString(R.string.notification_urge_download), pendingintent); notificationManager.notify(1, notification); }
From source file:com.nanostuffs.yurdriver.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w ww.j a v a 2s. c om private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.CPTeam.VselCalc.AutoUpdateApk.java
protected void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { // raise notification Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis()); notification.flags |= NOTIFICATION_FLAGS; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE);//from w w w .jav a2 s. c o m PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } }
From source file:de.wikilab.android.friendica01.FileUploadService.java
private void showFailMsg(Context ctx, String txt) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt); //Instantiate the Notification: CharSequence tickerText = "Upload failed, please retry!"; Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); CharSequence contentTitle = "Upload failed, click to retry!"; CharSequence contentText = txt; Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class); Bundle b = new Bundle(); b.putParcelable(Intent.EXTRA_STREAM, fileToUpload); b.putString(Intent.EXTRA_SUBJECT, subject); b.putString(EXTRA_DESCTEXT, descText); notificationIntent.putExtras(b);/*from w w w.j a v a 2 s . com*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); //Pass the Notification to the NotificationManager: mNotificationManager.notify(UPLOAD_FAILED_ID, notification); //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show(); }
From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java
private static void generateNotification(Noticia noticia, Context context) { NotificationManager mNotificationManager; int numMessages = 0; Log.i("Start", "notification"); /* Invoking the default notification service */ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle("Nova noticia"); mBuilder.setContentText(noticia.getAssunto()); mBuilder.setTicker("Noticia !!!"); mBuilder.setSmallIcon(R.drawable.logo); /* Increase notification number every time a new notification arrives */ mBuilder.setNumber(++numMessages);/*from w w w . ja v a2s .c om*/ /* Creates an explicit intent for an Activity in your app */ Intent resultIntent = new Intent(context, NavigationDrawer.class); resultIntent.setAction("NOTICIA"); //tentando linkar Bundle bundle = new Bundle(); bundle.putSerializable("noticia", noticia); resultIntent.putExtras(bundle); // fim arrumar a inteao TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(NavigationDrawer.class); /* 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); mNotificationManager = // (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // (NotificationManager) getActivity().getApplication(). // getSystemService(getActivity().getApplication().NOTIFICATION_SERVICE); // (NotificationManager) getContext().getSystemService(getContext().NOTIFICATION_SERVICE); // (NotificationManager) getSystemService(NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); /* notificationID allows you to update the notification later on. */ mNotificationManager.notify(noticia.getCodigo(), mBuilder.build()); }
From source file:org.mythdroid.util.UpdateService.java
private void checkMythDroid() { if (MDVer == null) return;//w ww . ja va2s . co m Version runningVer; try { runningVer = new Version(getPackageManager().getPackageInfo(getPackageName(), 0).versionName, null); } catch (NameNotFoundException e) { return; } if (runningVer.compareTo(MDVer) >= 0) { LogUtil.debug("Already running latest version of MythDroid"); //$NON-NLS-1$ return; } LogUtil.debug("Version " + MDVer.toString() + //$NON-NLS-1$ " is available (current version is " + runningVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$ ); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.logo, Messages.getString("UpdateService.0") + "MythDroid" + //$NON-NLS-1$ //$NON-NLS-2$ Messages.getString("UpdateService.1"), //$NON-NLS-1$ System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; final Intent intent = new Intent(MDACTION); intent.putExtra(VER, MDVer.toString()); intent.putExtra(URL, MDVer.url.toString()); notification.setLatestEventInfo(getApplicationContext(), "MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$ MDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ Messages.getString("UpdateService.3"), //$NON-NLS-1$ PendingIntent.getBroadcast(this, 0, intent, 0)); nm.notify(CHECKMD, notification); }
From source file:ch.nexuscomputing.android.osciprimeics.OsciPrimeService.java
private void notifyService() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent ni = new Intent(this, OsciPrimeICSActivity.class); ni.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getActivity(this, 0, ni, PendingIntent.FLAG_UPDATE_CURRENT); // Bitmap tmp = BitmapFactory.decodeResource(getResources(), // R.drawable.notification); // sNotification.contentIntent = pi; // sNotification.flags = Notification.FLAG_ONGOING_EVENT; // sNotification.icon = R.drawable.notification; // sNotification.setLatestEventInfo(this, "OsciPrime", // "Collecting Data", // pi);/*from www . j ava2 s . co m*/ NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pi).setSmallIcon(R.drawable.notification).setTicker("Collecting Data") .setOngoing(true).setWhen(System.currentTimeMillis()).setAutoCancel(false) .setContentTitle("OsciPrime").setContentText("Collecting Data"); sNotification = builder.getNotification(); nm.notify(NOTIFICATION_ID, sNotification); }