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:com.creativechaitu.castremotedisplay.CastRemoteDisplayActivity.java
private void startCastService(CastDevice castDevice) { Intent intent = new Intent(CastRemoteDisplayActivity.this, CastRemoteDisplayActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent notificationPendingIntent = PendingIntent.getActivity(CastRemoteDisplayActivity.this, 0, intent, 0);// ww w.j a v a 2 s . c o m CastRemoteDisplayLocalService.NotificationSettings settings = new CastRemoteDisplayLocalService.NotificationSettings.Builder() .setNotificationPendingIntent(notificationPendingIntent).build(); CastRemoteDisplayLocalService.startService(CastRemoteDisplayActivity.this, PresentationService.class, getString(R.string.app_id), castDevice, settings, new CastRemoteDisplayLocalService.Callbacks() { @Override public void onServiceCreated(CastRemoteDisplayLocalService service) { Log.d(TAG, "onServiceCreated"); } @Override public void onRemoteDisplaySessionStarted(CastRemoteDisplayLocalService service) { Log.d(TAG, "onServiceStarted"); } @Override public void onRemoteDisplaySessionError(Status errorReason) { int code = errorReason.getStatusCode(); Log.d(TAG, "onServiceError: " + errorReason.getStatusCode()); initError(); mCastDevice = null; CastRemoteDisplayActivity.this.finish(); } }); }
From source file:com.tml.sharethem.sender.SHAREthemService.java
/** * Creates a Notification for {@link Service#startForeground(int, Notification)} method. * Adds text passed in <code>text</code> param as content and title * * @param text message and title * @param addStopAction if true STOP action is added to stop {@link SHAREthemService} * @return Notification// w w w . java2 s .c om */ private Notification getShareThemNotification(String text, boolean addStopAction) { Intent notificationIntent = new Intent(getApplicationContext(), SHAREthemActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher) .setWhen(System.currentTimeMillis()).setContentTitle(getString(R.string.app_name)).setTicker(text) .setContentText(text); if (addStopAction) builder.addAction(getStopAction()); return builder.build(); }
From source file:com.frostwire.android.gui.services.EngineService.java
public void notifyDownloadFinished(String displayName, File file, String infoHash) { try {//w w w. j a v a2 s. c om if (notifiedStorage.contains(infoHash)) { // already notified return; } else { notifiedStorage.add(infoHash); } Context context = getApplicationContext(); Intent i = new Intent(context, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); i.putExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION, true); i.putExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH, file.getAbsolutePath()); PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context, Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID).setWhen(System.currentTimeMillis()) .setContentText(getString(R.string.download_finished)) .setContentTitle(getString(R.string.download_finished)) .setSmallIcon(getNotificationIcon()).setContentIntent(pi).build(); notification.vibrate = ConfigurationManager.instance().vibrateOnFinishedDownload() ? VENEZUELAN_VIBE : null; notification.number = TransferManager.instance().getDownloadsToReview(); notification.flags |= Notification.FLAG_AUTO_CANCEL; if (manager != null) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID, "FrostWire", NotificationManager.IMPORTANCE_MIN); channel.setSound(null, null); manager.createNotificationChannel(channel); } manager.notify(Constants.NOTIFICATION_DOWNLOAD_TRANSFER_FINISHED, notification); } } catch (Throwable e) { LOG.error("Error creating notification for download finished", e); } }
From source file:com.tws.soul.soulbrown.gcm.GcmIntentService.java
private void sendNotification(String msg) { WakeupMgr wakeupMgr;//w ww . j a v a2 s. com wakeupMgr = new WakeupMgr(this); wakeupMgr.setPowerWakeUp(4); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, SplashActivity.class); intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.push_logo_s).setContentTitle(getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); wakeupMgr.releaseWifiManager(); }
From source file:com.onesignal.GenerateNotification.java
private static Intent getNewBaseIntent(int notificationId) { Intent intent = new Intent(currentContext, notificationOpenedClass).putExtra("notificationId", notificationId);//from w w w. jav a 2 s. c om if (openerIsBroadcast) return intent; return intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); }
From source file:com.orange.oidc.secproxy_service.Service.java
void resetCookies() { // init intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClass(Service.this, WebViewActivity.class); intent.putExtra("resetcookies", "true"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION); // launch webview startActivity(intent);// ww w . ja v a 2 s . c o m }
From source file:at.maui.cheapcast.service.CheapCastService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LOG_TAG, "onStartCommand()"); Notification n = null;//from w w w.j a v a 2 s. com if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Notification.Builder mBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_service) .setContentTitle("CheapCast").setContentText("Service enabled.").setOngoing(true) .addAction(R.drawable.ic_reload, getString(R.string.restart_service), PendingIntent.getBroadcast(this, 1, new Intent(Const.ACTION_RESTART), PendingIntent.FLAG_ONE_SHOT)) .addAction(R.drawable.ic_stop, getString(R.string.stop_service), PendingIntent .getBroadcast(this, 2, new Intent(Const.ACTION_STOP), PendingIntent.FLAG_ONE_SHOT)); Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); mBuilder.setContentIntent(pi); n = mBuilder.build(); } else { Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_service).setContentTitle("CheapCast") .setContentText("Service enabled.").setOngoing(true).setContentIntent(pi); n = mBuilder.getNotification(); } startForeground(1337, n); if (!mRunning) initService(); return START_STICKY; }
From source file:com.ingeneo.cordova.plugins.ibeacon.GPIBeacon.java
/** * + * Issues a notification to inform the user that server has sent a * message. +// w w w . ja va 2s. c om * * @throws JSONException */ private static void createNotification(Context context, JSONObject json) throws JSONException { Bundle extra = new Bundle(); extra.putString("json", json.toString()); Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("beacon", extra); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); JSONObject obj = json.getJSONObject("ibeacon"); String message = obj.getString("message"); String title = obj.getString("title"); if (title == null || title == "") { title = context.getApplicationInfo().name; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis()).setTicker(message) .setContentTitle(title).setContentText(message).setSmallIcon(context.getApplicationInfo().icon) .setContentIntent(contentIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle("Beacons"); // Moves events into the big view for (int i = 0; i < itemsNotification.size(); i++) { JSONObject beacon = beaconsData.get(itemsNotification.get(i)); inboxStyle.addLine(beacon.getString("message")); } // Moves the big view style object into the notification object. mBuilder.setStyle(inboxStyle); if (message != null) { mBuilder.setContentText(message); } else { mBuilder.setContentText("<missing message content>"); } mBuilder.addAction(context.getApplicationInfo().icon, "Ver mas", contentIntent); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)) .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build()); }
From source file:de.qspool.clementineremote.backend.ClementineSongDownloader.java
private PendingIntent buildNotificationIntent() { Intent intent = new Intent(App.mApp, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(App.NOTIFICATION_ID, mId); intent.setData(Uri.parse("ClemetineDownload" + mId)); // Create a TaskStack, so the app navigates correctly backwards TaskStackBuilder stackBuilder = TaskStackBuilder.create(App.mApp); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent);//ww w . jav a 2 s.co m return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);/*w w w . ja v a2 s. c o m*/ IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][] {}; filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); try { filters[0].addDataType(MIME_TEXT_PLAIN); } catch (MalformedMimeTypeException e) { throw new RuntimeException("Check your mime type."); } adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); }