List of usage examples for android.app TaskStackBuilder getPendingIntent
public PendingIntent getPendingIntent(int requestCode, @PendingIntent.Flags int flags)
From source file:re.serialout.MainScreen.java
public void buildNotification(Context context) { //Feature in progress, not in current version. NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle("There is a new survey for you to complete!"); builder.setContentText("Please take a second to fill it out."); builder.setSmallIcon(R.drawable.logo2); builder.setAutoCancel(true);// www.j a v a 2s . co m System.out.println("BUILT"); Intent resultIntent = new Intent(this, MainScreen.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainScreen.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(100, builder.build()); }
From source file:com.fimo_pitch.main.MainActivity.java
private void makeNotification(Context context, String title, String content) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri) .setPriority(Notification.PRIORITY_HIGH).setContentText(content); Intent resultIntent = new Intent(context, MainActivity.class); userModel = getUserModel();//from w w w .ja v a 2 s . co m resultIntent.putExtra(CONSTANT.KEY_USER, userModel); resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true"); TaskStackBuilder stackBuilder = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(FirstActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(ZAQ500); } else { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(500); } }
From source file:com.radiusnetworks.scavengerhunt.ScavengerHuntApplication.java
private void sendNotification() { try {/*from www .j a va 2s. c o m*/ NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.sh_notification_title)) .setContentText(getString(R.string.sh_notification_text)).setVibrate(VIBRATOR_PATTERN) .setSmallIcon(R.drawable.sh_notification_icon).setAutoCancel(true); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); Intent notificationIntent = new Intent(this, TargetCollectionActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); stackBuilder.addNextIntent(notificationIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); } catch (Exception e) { e.printStackTrace(); } }
From source file:at.aec.solutions.checkmkagent.AgentService.java
@Override public void onCreate() { super.onCreate(); Log.v(TAG, "onCreate"); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); m_wakeLock.acquire();//from ww w . j a v a 2 s. c om //Copy busybox binary to app directory if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled", false)) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit() .putBoolean("bbinstalled", true).commit(); // There is also String[] Build.SUPPORTED_ABIS from API 21 on and // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there String arch = System.getProperty("os.arch"); Log.v(TAG, arch); if (arch.equals("armv7l")) { copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox"); } if (arch.equals("i686")) { copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox"); } // copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64"); changeBusyboxPermission(); } socketServerThread = new Thread(new SocketServerThread()); socketServerThread.setName("CheckMK-Agent ServerThread"); socketServerThread.start(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.") .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure."); Intent resultIntent = new Intent(this, ConfigureActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ConfigureActivity.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); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. Notification notify = mBuilder.build(); notify.flags |= Notification.FLAG_NO_CLEAR; mNotificationManager.notify(mId, notify); }
From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java
private void notifyGooglePlay() { int idGooglePlay = 12345; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.to_google_play)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, ToGooglePlayActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ToGooglePlayActivity.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); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(idGooglePlay, mBuilder.build()); }
From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java
private void notifyAppWebpage() { int idGooglePlay = 12346; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.to_app_webpage)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, ToAppWebpageActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ToAppWebpageActivity.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); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(idGooglePlay, mBuilder.build()); }
From source file:com.polkapolka.bluetooth.le.DeviceControlActivity.java
public void showNotification(View view) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.NotifationTitle)) .setContentText(getString(R.string.NotificationSubtitle)) .setTicker(getString(R.string.NotificationTicker)).setSmallIcon(R.drawable.icon); // Define that we have the intention of opening MoreInfoNotification Intent moreInfoIntent = new Intent(this, userActivity.class); // Used to stack tasks across activites so we go to the proper place when back is clicked TaskStackBuilder tStackBuilder = TaskStackBuilder.create(this); // Add all parents of this activity to the stack tStackBuilder.addParentStack(DeviceControlActivity.class); // Add our new Intent to the stack tStackBuilder.addNextIntent(moreInfoIntent); notificationBuilder.setDefaults(Notification.DEFAULT_ALL); notificationBuilder.setAutoCancel(true); // Define an Intent and an action to perform with it by another application // FLAG_UPDATE_CURRENT : If the intent exists keep it but update it if needed PendingIntent pendingIntent = tStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Defines the Intent to fire when the notification is clicked notificationBuilder.setContentIntent(pendingIntent); // Gets a NotificationManager which is used to notify the user of the background event notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Post the notification notificationManager.notify(notifID, notificationBuilder.build()); }
From source file:br.com.Utilitarios.WorkUpService.java
public void criarNotificacoes(Notificacoes n, String titulo, String texto, String ticker, String tipo, String extra) {/*w w w . ja va 2 s .com*/ // Build notification NotificationCompat.Builder noti = new NotificationCompat.Builder(this); noti.setContentTitle(titulo); noti.setContentText(texto); noti.setTicker(ticker); noti.setSmallIcon(R.drawable.ic_launcher); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); noti.setSound(alarmSound); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent resultIntent = null; if (tipo.equals("novoPersonal")) { // Creates an expnovaAvaliacaolicit intent for an Activity in your app resultIntent = new Intent(this, AceitarRejeitarAmigo.class); resultIntent.putExtra("usuario", n.getOrigemNotificacao()); resultIntent.putExtra("tipo", "aluno"); } if (tipo.equals("novoAluno")) { resultIntent = new Intent(this, AceitarRejeitarAmigo.class); resultIntent.putExtra("usuario", n.getOrigemNotificacao()); resultIntent.putExtra("tipo", "personal"); } if (tipo.equals("novaAula")) { // Creates an explicit intent for an Activity in your app resultIntent = new Intent(this, ConfirmarAula.class); resultIntent.putExtra("codAula", extra); } //This ensures that navigating backward from the Activity leads out of the app to Home page TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); if (tipo.equals("novoPersonal") || tipo.equals("novoAluno")) { // Adds the back stack for the Intent stackBuilder.addParentStack(AceitarRejeitarAmigo.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT //can only be used once ); // start the activity when the user clicks the notification text noti.setContentIntent(resultPendingIntent); } // pass the Notification object to the system notificationManager.notify(0, noti.build()); n.visualizarNotificacao(n.getCodNotificacao()); //---------------------------------------------------------------------------------- }
From source file:com.android.mms.transaction.MessagingNotification.java
private static void notifyFailed(Context context, boolean isDownload, long threadId, boolean noisy) { // TODO factor out common code for creating notifications boolean enabled = MessagingPreferenceActivity.getNotificationEnabled(context); if (!enabled) { return;//from w w w . j a va 2 s. c om } // Strategy: // a. If there is a single failure notification, tapping on the notification goes // to the compose view. // b. If there are two failure it stays in the thread view. Selecting one undelivered // thread will dismiss one undelivered notification but will still display the // notification.If you select the 2nd undelivered one it will dismiss the notification. int totalFailedCount = getUndeliveredMessageCount(context); Intent failedIntent; Notification notification = new Notification(); String title; String description; if (totalFailedCount > 1) { description = context.getString(R.string.notification_failed_multiple, Integer.toString(totalFailedCount)); title = context.getString(R.string.notification_failed_multiple_title); } else { title = isDownload ? context.getString(R.string.message_download_failed_title) : context.getString(R.string.message_send_failed_title); description = context.getString(R.string.message_failed_body); } TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // Get failed intent by folder mode or conversation mode. if (MessageUtils.isMailboxMode()) { failedIntent = getFailedIntentFromFolderMode(context, totalFailedCount, isDownload); if (failedIntent == null) { return; } else if (isDownload) { // When isDownload is true, the valid threadId is passed into this function. failedIntent.putExtra(FAILED_DOWNLOAD_FLAG, true); } else { failedIntent.putExtra(UNDELIVERED_FLAG, true); } } else { failedIntent = getFailedIntentFromConversationMode(context, isDownload, threadId); } taskStackBuilder.addNextIntent(failedIntent); notification.icon = R.drawable.stat_notify_sms_failed; notification.tickerText = title; notification.setLatestEventInfo(context, title, description, taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); if (noisy) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false /* don't vibrate by default */); if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr); } NotificationManager notificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (isDownload) { notificationMgr.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification); } else { notificationMgr.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification); } }
From source file:ua.mkh.weather.MainActivity.java
private void create_notif() { // TODO Auto-generated method stub // Prepare intent which is triggered if the // notification is selected String tittle = textView3.getText().toString(); String subject = textView3.getText().toString(); String body = ""; /*//from ww w . ja va 2s . c o m NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis()); PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); notify.setLatestEventInfo(getApplicationContext(),subject,body,pending); notif.notify(0, notify); final NotificationManager mgr= (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); Notification note=new Notification((Integer)img1.getTag(), "", System.currentTimeMillis()); // This pending intent will open after notification click PendingIntent i=PendingIntent.getActivity(this, 0, new Intent(), 0); note.setLatestEventInfo(this, tittle, "", i); //After uncomment this line you will see number of notification arrived //note.number=2; mgr.notify(1, note); PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Resources r = getResources(); Notification notification = new NotificationCompat.Builder(this) .setTicker("Tiket") .setSmallIcon(android.R.drawable.ic_menu_report_image) .setContentTitle("Title") .setContentText("Context Text") .setContentIntent(pi) .setAutoCancel(true) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, notification); */ RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for // the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.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); remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent); remoteViews.setTextViewText(R.id.textView1, nnn); remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white)); remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag()); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build()); }