List of usage examples for android.app PendingIntent getActivity
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.handshake.notifications.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. *//*from www.j av a 2s . c o m*/ private void sendNotification(final Bundle data, long userId, boolean isContact) { Intent intent; if (userId == 0) { intent = new Intent(this, MainActivity.class); } else if (isContact) { intent = new Intent(this, ContactUserProfileActivity.class); } else { intent = new Intent(this, GenericUserProfileActivity.class); } intent.putExtra("userId", userId); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Handshake") .setContentText(data.getString("message")).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
public static void notifyUpdate(final AppVersionInfo info, final Context context) { final String versionInfo = info.versionName; final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.ic_notify_icon, "?" + versionInfo, System.currentTimeMillis()); final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, DownloadService.getNewVersionIntent(context, info), 0); notification.setLatestEventInfo(context, "?" + versionInfo, "", contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(2, notification);/*from ww w. j a v a 2 s. c o m*/ }
From source file:de.grobox.blitzmail.AsyncMailTask.java
@Override protected void onPostExecute(Boolean result) { String msg = ""; // set progress notification to finished activity.mBuilder.setProgress(0, 0, false); activity.mBuilder.setOngoing(false); // set dialog to auto close when clicked activity.mBuilder.setAutoCancel(true); if (result) { // Everything went fine, so delete mail from local storage MailStorage.deleteMail(activity, mail.optString("id")); // check to see if there should be a success notification if (!PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("pref_success_notification", true)) {/*w ww . j a v a2s . c om*/ // don't show success notification activity.mNotifyManager.cancel(0); return; } // show success notification activity.mBuilder.setSmallIcon(R.drawable.ic_launcher); activity.mBuilder.setContentTitle(activity.getString(R.string.sent_mail)); activity.notifyIntent.putExtra("ContentTitle", activity.getString(R.string.sent_mail)); msg = mail.optString("subject"); } else { activity.mBuilder.setContentTitle( activity.getString(R.string.app_name) + " - " + activity.getString(R.string.error)); activity.notifyIntent.putExtra("ContentTitle", activity.getString(R.string.error)); activity.mBuilder.setSmallIcon(android.R.drawable.ic_dialog_alert); Log.d("AsyncMailTask", e.getClass().getCanonicalName()); if (e.getClass().getCanonicalName().equals("javax.mail.AuthenticationFailedException")) { msg = activity.getString(R.string.error_auth_failed); } else if (e.getClass().getCanonicalName().equals("javax.mail.MessagingException") && e.getCause() != null && e.getCause().getClass().getCanonicalName().equals("javax.net.ssl.SSLException") && e.getCause().getCause().getClass().getCanonicalName() .equals("java.security.cert.CertificateException")) { // TODO use MemorizingTrustManager instead, issue #1 msg = activity.getString(R.string.error_sslcert_invalid); } else { msg = activity.getString(R.string.error_smtp) + '\n' + e.getMessage(); } // get and show the cause for the exception if it exists if (e.getCause() != null) { Throwable ecause = e.getCause(); Log.d("AsyncMailTask", ecause.getClass().getCanonicalName()); msg += "\nCause: " + ecause.getMessage(); } } // Update the notification activity.mBuilder.setContentText(msg); activity.notifyIntent.putExtra("ContentText", msg); activity.mBuilder.setContentIntent( PendingIntent.getActivity(activity, 0, activity.notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT)); activity.mNotifyManager.notify(0, activity.mBuilder.build()); }
From source file:com.google.android.gcm.demo.app.GcmBroadcastReceiver.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, LLActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:br.ajmarques.cordova.plugin.localnotification.Receiver.java
/** * Fgt der Notification einen onclick Handler hinzu. *///from w w w . ja va 2 s. c om private NotificationCompat.Builder setClickEvent(NotificationCompat.Builder notification) { Intent intent = new Intent(context, ReceiverActivity.class) .putExtra(OPTIONS, options.getJSONObject().toString()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT); return notification.setContentIntent(contentIntent); }
From source file:com.molice.oneingdufs.androidpn.Notifier.java
public void notify(String notificationId, String apiKey, String title, String message, String uri) { Log.d(LOGTAG, "notify()..."); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + apiKey); Log.d(LOGTAG, "notificationTitle=" + title); Log.d(LOGTAG, "notificationMessage=" + message); Log.d(LOGTAG, "notificationUri=" + uri); if (SettingsActivity.getNotificationEnabled(context)) { // Show the toast // if (isNotificationToastEnabled()) { // Toast.makeText(context, message, Toast.LENGTH_LONG).show(); // } // Notification Notification notification = new Notification(); notification.icon = getNotificationIcon(); // notification.defaults = Notification.DEFAULT_LIGHTS; if (SettingsActivity.getNotificationSound(context)) { notification.defaults |= Notification.DEFAULT_SOUND; }//from ww w .jav a 2s.com if (SettingsActivity.getNotificationVibrate(context)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.when = System.currentTimeMillis(); notification.tickerText = message; // Intent intent; // if (uri != null // && uri.length() > 0 // && (uri.startsWith("http:") || uri.startsWith("https:") // || uri.startsWith("tel:") || uri.startsWith("geo:"))) { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // } else { // String callbackActivityPackageName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); // String callbackActivityClassName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); // intent = new Intent().setClassName(callbackActivityPackageName, // callbackActivityClassName); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // } Intent intent = new Intent(context, MessageDetailActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); JSONObject data = formatMetaFromTitle(title); try { data.putOpt("id", notificationId); data.putOpt("content", message); } catch (Exception e) { Log.d("JSON", "Notifier#notify, e=" + e.toString()); } intent.putExtra("data", data.toString()); intent.putExtra("fromNotification", true); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, data.optString("title"), message, contentIntent); notificationManager.notify(random.nextInt(), notification); // Intent clickIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLICKED); // clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title); // clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message); // clickIntent.putExtra(Constants.NOTIFICATION_URI, uri); // // positiveIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clickPendingIntent = PendingIntent.getBroadcast( // context, 0, clickIntent, 0); // // notification.setLatestEventInfo(context, title, message, // clickPendingIntent); // // Intent clearIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLEARED); // clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // // negativeIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clearPendingIntent = PendingIntent.getBroadcast( // context, 0, clearIntent, 0); // notification.deleteIntent = clearPendingIntent; // // notificationManager.notify(random.nextInt(), notification); } else { Log.w(LOGTAG, "Notificaitons disabled."); } }
From source file:com.arubadesignweb.app.appoverview.util.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Application.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.push_icon) .setContentTitle(this.getApplicationContext().getString(R.string.url)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setAutoCancel(true);/*w w w. j a va 2 s .c om*/ mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:de.appplant.cordova.plugin.background.ForegroundService.java
/** * Create a notification as the visible part to be able to put the service * in a foreground state./*from w w w . j a va 2 s.c om*/ * * @return * A local ongoing notification which pending intent is bound to the * main activity. */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") private Notification makeNotification() { JSONObject settings = BackgroundMode.getSettings(); Context context = getApplicationContext(); String pkgName = context.getPackageName(); Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgName); notification = new Notification.Builder(context).setContentTitle(settings.optString("title", "")) .setContentText(settings.optString("text", "")).setTicker(settings.optString("ticker", "")) .setOngoing(true).setSmallIcon(getIconResId()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (settings.optBoolean("isPublic") == true) { notification.setVisibility(Notification.VISIBILITY_PUBLIC); } if (!settings.optString("color").equals("")) { try { notification.setColor(Color.parseColor(settings.optString("color"))); } catch (Exception e) { Log.e("BackgroundMode", settings.optString("color") + " is not a valid color"); } } } if (intent != null && settings.optBoolean("resume")) { PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); } if (Build.VERSION.SDK_INT < 16) { // Build notification for HoneyComb to ICS return notification.getNotification(); } else { // Notification for Jellybean and above return notification.build(); } }
From source file:ru.orangesoftware.financisto.activity.FlowzrSyncActivity.java
public void initProgressDialog() { Intent notificationIntent = new Intent(getApplicationContext(), FlowzrSyncActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(getApplicationContext().getString(R.string.flowzr_sync)) .setContentText(getApplicationContext().getString(R.string.flowzr_sync_auth_inprogress)); nm.notify(NOTIFICATION_ID, mNotifyBuilder.build()); }