List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP
int FLAG_ACTIVITY_SINGLE_TOP
To view the source code for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.
Click Source Link
From source file:edu.mines.letschat.GcmIntentService.java
private void sendNotification(String msg, String senderID) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, MainActivity.class); intent.putExtra(MainActivity.EXTRA_NOTIFICATION_RETRIEVE, senderID); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationCounter++;//from w w w . j a v a2s. c o m if (messages.size() > 1) { msg = msg + "..."; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setVibrate(new long[] { 0, 500, 250, 500, 250 }).setLights(Color.BLUE, 200, 200) .setSmallIcon(R.drawable.logo).setContentTitle("Let's Chat Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setNumber(notificationCounter) .setTicker(msg).setContentText(msg); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle("Unread messages (" + notificationCounter + "):"); // Moves events into the big view ArrayList<String> temp = new ArrayList<String>(); for (int i = 0; i < 5; ++i) { if (i == messages.size()) { break; } temp.add(messages.get(i)); } Collections.reverse(temp); messages = temp; for (String s : messages) { inboxStyle.addLine(s); } mBuilder.setStyle(inboxStyle); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); // AwesomeAdapter.animate = true; }
From source file:net.openid.appauth.AuthorizationManagementActivity.java
/** * Creates an intent to handle the completion of an authorization flow. This restores * the original AuthorizationManagementActivity that was created at the start of the flow. * @param context the package context for the app. * @param responseUri the response URI, which carries the parameters describing the response. */// w w w.ja v a 2s . c o m public static Intent createResponseHandlingIntent(Context context, Uri responseUri) { Intent intent = createBaseIntent(context); intent.setData(responseUri); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); return intent; }
From source file:com.scto.filerenamer.FileRenamerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: { Intent intent = new Intent(this, PreferencesActivity.class); intent.putExtra("theme", mThemeId); startActivity(intent);//from ww w .j a v a 2 s .c o m return true; } case android.R.id.home: { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); return true; } default: { return super.onOptionsItemSelected(item); } } }
From source file:de.qspool.clementineremote.backend.ClementineService.java
/** * Setup the Notification// www . ja va 2 s . c om */ private void setupNotification(boolean ongoing) { mNotifyBuilder = new NotificationCompat.Builder(App.mApp); mNotifyBuilder.setSmallIcon(R.drawable.notification); mNotifyBuilder.setOngoing(ongoing); // If we don't have an ongoing notification, it shall be closed after clicked. if (!ongoing) { mNotifyBuilder.setAutoCancel(true); } // Set the result intent Intent resultIntent = new Intent(App.mApp, MainActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); resultIntent.putExtra(App.NOTIFICATION_ID, -1); // Create a TaskStack, so the app navigates correctly backwards TaskStackBuilder stackBuilder = TaskStackBuilder.create(App.mApp); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingintent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingintent); // Create intents for buttons Intent playIntent = new Intent(NotificationReceiver.PLAYPAUSE); Intent nextIntent = new Intent(NotificationReceiver.NEXT); PendingIntent piPlay = PendingIntent.getBroadcast(App.mApp, 0, playIntent, 0); PendingIntent piNext = PendingIntent.getBroadcast(App.mApp, 0, nextIntent, 0); if (ongoing) { mNotifyBuilder.addAction(R.drawable.ic_media_pause_resume, App.mApp.getString(R.string.notification_action_playpause), piPlay); mNotifyBuilder.addAction(R.drawable.ic_media_next_not, App.mApp.getString(R.string.notification_action_next), piNext); mNotifyBuilder.setPriority(1); } }
From source file:com.chilliworks.chillisource.core.GCMService.java
private void generateNotification(Context context, HashMap<String, String> inParams) { //if the application is active then pass this information on to the application. if (CSApplication.get() != null && CSApplication.get().isActive() == true) { //build the array of keys and values int dwNumEntries = inParams.size(); String[] astrKeys = new String[dwNumEntries]; String[] astrValues = new String[dwNumEntries]; int dwCount = 0; for (String strKey : inParams.keySet()) { astrKeys[dwCount] = strKey;//w w w. j a va 2 s. co m astrValues[dwCount] = inParams.get(strKey); dwCount++; } // Send this to the native side of the engine. mNativeInterface.OnRemoteNotificationReceived(astrKeys, astrValues); } // Otherwise display a notification. else { String strTitle = context.getString(R.getId(context, R.Type.STRING, "app_name")); String strMessage = inParams.get("message"); Intent notificationIntent = new Intent(context, CSActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int smallIconId = 0; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify") == true) { smallIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify"); } int largeIconId = smallIconId; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify_large") == true) { largeIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify_large"); } Bitmap largeIconBitmap = null; if (largeIconId > 0) { largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), largeIconId); } Notification notification = new NotificationCompat.Builder(context).setContentTitle(strTitle) .setContentText(strMessage).setSmallIcon(smallIconId).setLargeIcon(largeIconBitmap) .setContentIntent(intent).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); } }
From source file:com.nanostuffs.yurdriver.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from ww w . java 2 s . co m 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.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java
private void onUnhandled(Context context, Intent intent) { String action = intent.getAction(); if ((MFPPushUtils.getIntentPrefix(context) + GCM_MESSAGE).equals(action)) { MFPInternalPushMessage message = intent.getParcelableExtra(GCM_EXTRA_MESSAGE); int notificationId = randomObj.nextInt(); message.setNotificationId(notificationId); saveInSharedPreferences(message); intent = new Intent(MFPPushUtils.getIntentPrefix(context) + IBM_PUSH_NOTIFICATION); intent.setClass(context, MFPPushNotificationHandler.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(NOTIFICATIONID, message.getNotificationId()); generateNotification(context, message.getAlert(), getNotificationTitle(context), message.getAlert(), getCustomNotificationIcon(context, message.getIcon()), intent, getNotificationSound(message), notificationId, message); }// w w w.j av a 2 s . com }
From source file:com.example.administrator.e_pic.GcmIntentService.java
private void sendNotification(String from, int notificationType) { int requestID = (int) System.currentTimeMillis(); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = null;//www . j a va2s. com long[] vibrate = { 130, 100, 130, 100 }; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.sneeze_icon).setContentTitle("iSneeze"); switch (notificationType) { case CODE_ADD_SNEEZE: mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(from + " heeft geniesd.")) .setContentText(from + " heeft geniesd.").setTicker(from + " heeft geniesd."); notificationIntent = new Intent(getApplicationContext(), iSneezeActivity.class); //contentIntent = PendingIntent.getActivity(this, 0, // new Intent(this.getApplicationContext(), iSneezeActivity.class), 0); break; case CODE_ACCEPT_FRIENDS: mBuilder.setStyle( new NotificationCompat.BigTextStyle().bigText(from + " heeft je vriendschapsverzoek aanvaard.")) .setContentText(from + " heeft je vriendschapsverzoek aanvaard.") .setTicker(from + " heeft je vriendschapsverzoek aanvaard."); notificationIntent = new Intent(getApplicationContext(), MyFriendsActivity.class); //contentIntent = PendingIntent.getActivity(this, 0, // new Intent(this.getApplicationContext(), iSneezeActivity.class), 0); break; case CODE_FRIEND_REQUEST: mBuilder.setStyle(new NotificationCompat.BigTextStyle() .bigText(from + " heeft je een vriendschapsverzoek gestuurd.")) .setContentText(from + " heeft je een vriendschapsverzoek gestuurd.") .setTicker(from + " heeft je een vriendschapsverzoek gestuurd."); SaveSharedPreference.setNrOfSneezes(getApplicationContext(), SaveSharedPreference.getNrOfSneezes(getApplicationContext()) + 1); notificationIntent = new Intent(getApplicationContext(), FriendRequestsActivity.class); //contentIntent = PendingIntent.getActivity(this, 0, // new Intent(this.getApplicationContext(), iSneezeActivity.class), 0); break; case CODE_OTHER_LOGIN: SaveSharedPreference.clear(this); if (RandomShit.isAppOnForeground(this)) { Intent i = new Intent(getApplicationContext(), RealMainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } default: return; } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, requestID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mBuilder.setVibrate(vibrate); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:cs460.grouple.grouple.GcmIntentService.java
private void sendNotification(String msg) { updateMyActivity(this);// crash seems RECEIVER be here Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_MESSAGE.toString())) { Intent notificationIntent = new Intent(this, EntityMessagesActivity.class); if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString())) { notificationIntent.putExtra("CONTENT_TYPE", "GROUP"); notificationIntent.putExtra("GID", RECEIVER); Group g = new Group(Integer.parseInt(RECEIVER)); g.fetchGroupInfo();/* ww w. j ava2 s . co m*/ GLOBAL.setGroupBuffer(g); } else { notificationIntent.putExtra("CONTENT_TYPE", "EVENT"); notificationIntent.putExtra("EID", RECEIVER); Event e = new Event(Integer.parseInt(RECEIVER)); e.fetchEventInfo(); GLOBAL.setEventBuffer(e); } notificationIntent.putExtra("email", SENDER); notificationIntent.putExtra("name", NAME); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentTitle(NAME) .setStyle(new NotificationCompat.BigTextStyle() // .bigText(msg)) .bigText(SENDER_FIRST + " " + SENDER_LAST + ": " + msg)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.USER_MESSAGE.toString())) { Intent notificationIntent = new Intent(getApplicationContext(), MessagesActivity.class); notificationIntent.putExtra("sender", SENDER); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("receiver", RECEIVER); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle(SENDER_FIRST + " " + SENDER_LAST) .setStyle(new NotificationCompat.BigTextStyle() // .bigText(msg)) .bigText(msg)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.FRIEND_REQUEST.toString())) { // Send friend request. Intent notificationIntent = new Intent(getApplicationContext(), ListActivity.class); notificationIntent.putExtra("email", GLOBAL.getCurrentUser().getEmail()); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("content", CONTENT_TYPE.FRIEND_REQUEST.toString()); GLOBAL.getCurrentUser().fetchFriendRequests(); GLOBAL.getCurrentUser().fetchUserInfo(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle("New friend request from " + SENDER_FIRST + " " + SENDER_LAST + "!") .setStyle(new NotificationCompat.BigTextStyle().bigText(SENDER_FIRST + " " + SENDER_LAST)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (TYPE.equals(CONTENT_TYPE.GROUP_INVITE.toString())) { // Send friend request. Intent notificationIntent = new Intent(getApplicationContext(), ListActivity.class); notificationIntent.putExtra("email", GLOBAL.getCurrentUser().getEmail()); notificationIntent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); notificationIntent.putExtra("content", "GROUPS_INVITES"); GLOBAL.getCurrentUser().fetchFriendRequests(); GLOBAL.getCurrentUser().fetchUserInfo(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle( "New group invite to " + NAME + " from " + SENDER_FIRST + " " + SENDER_LAST + "!") .setStyle(new NotificationCompat.BigTextStyle().bigText(SENDER_FIRST + " " + SENDER_LAST)) .setSmallIcon(R.drawable.icon_grouple).setSound(soundUri).setContentText(msg); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setAutoCancel(true); // null check mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:de.qspool.clementineremote.ui.Player.java
private void setupNotification() { mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifyBuilder = new NotificationCompat.Builder(this); mNotifyBuilder.setSmallIcon(R.drawable.ic_launcher); mNotifyBuilder.setOngoing(true);/*w w w.j a v a2 s . co m*/ // Set the result intent Intent resultIntent = new Intent(this, Player.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Create a TaskStack, so the app navigates correctly backwards TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(Player.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingintent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingintent); }