Java Code Examples for android.app.TaskStackBuilder#create()
The following examples show how to use
android.app.TaskStackBuilder#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StageService.java From AndroidSamples with Apache License 2.0 | 7 votes |
private void showNotification() { // 创建通知栏 Notification.Builder mBuilder = new Notification.Builder(this) .setSmallIcon(R.drawable.img_tm) .setContentTitle("标题") .setContentText("文本"); // 点击跳转到Activity Intent intent = new Intent(this, MainActivity.class); // 创建任务栈 TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); // 设置跳转 mBuilder.setContentIntent(pendingIntent); // 获取通知服务 NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 构建通知 Notification notification = mBuilder.build(); // 显示通知 nm.notify(0,notification); // 启动前台服务 startForeground(0,notification); }
Example 2
Source File: ForegroundServiceStarter.java From xDrip with GNU General Public License v3.0 | 6 votes |
private Notification notification() { Intent intent = new Intent(mContext, Home.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(Home.class); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); NotificationCompat.Builder b=new NotificationCompat.Builder(mService); b.setOngoing(true); b.setCategory(Notification.CATEGORY_SERVICE); // Hide this notification "below the fold" on L+ b.setPriority(Notification.PRIORITY_MIN); // Don't show this notification on the lock screen on L+ b.setVisibility(Notification.VISIBILITY_SECRET); b.setContentTitle("xDrip is Running") .setContentText("xDrip Data collection service is running.") .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on); b.setContentIntent(resultPendingIntent); return(b.build()); }
Example 3
Source File: ITagsService.java From itag with GNU General Public License v3.0 | 6 votes |
static Notification createForegroundNotification(Context context) { createForegroundNotificationChannel(context); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, FOREGROUND_CHANNEL_ID); builder .setTicker(null) .setSmallIcon(R.drawable.app) .setContentTitle(context.getString(R.string.service_in_background)) .setContentText(context.getString(R.string.service_description)); Intent intent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); builder.setContentIntent(pendingIntent); return builder.build(); }
Example 4
Source File: PassiveService.java From privacy-friendly-netmonitor with GNU General Public License v3.0 | 6 votes |
private void showAppNotification() { mBuilder.setSmallIcon(R.drawable.ic_notification); mBuilder.setLargeIcon(mIcon); 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); mBuilder.setContentIntent(resultPendingIntent); startForeground(SERVICE_IDENTIFIER, mBuilder.build()); }
Example 5
Source File: ReminderReceiver.java From YCNotification with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "ReminderReceiver"); //Calendar now = GregorianCalendar.getInstance(); Notification.Builder mBuilder = new Notification.Builder(context) .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("广播接受者标题,小杨") .setContentText("广播接受者内容,扯犊子") .setAutoCancel(true); Log.i(TAG, "onReceive: intent" + intent.getClass().getName()); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); //将该Activity添加为栈顶 stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build()); }
Example 6
Source File: BeaconReferenceApplication.java From android-beacon-library-reference with Apache License 2.0 | 6 votes |
private void sendNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle("Beacon Reference Application") .setContentText("An beacon is nearby.") .setSmallIcon(R.drawable.ic_launcher); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class)); 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()); }
Example 7
Source File: ComposeTweetService.java From catnut with MIT License | 6 votes |
private void fallback(Draft draft, String error) { draft.createAt = System.currentTimeMillis(); getContentResolver().insert(CatnutProvider.parse(Draft.MULTIPLE), Draft.METADATA.convert(draft)); mBuilder.setContentTitle(getString(R.string.post_fail)) .setContentText(error) .setTicker(getText(R.string.post_fail)) .setProgress(0, 0, false); // 添加fallback跳转 Intent resultIntent = SingleFragmentActivity.getIntent(this, SingleFragmentActivity.DRAFT); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); taskStackBuilder.addParentStack(SingleFragmentActivity.class); taskStackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent( ID, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent) .setAutoCancel(true); mNotifyManager.notify(ID, mBuilder.build()); }
Example 8
Source File: NotificationReceiver.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
private Notification createStreamNotification(StreamInfo stream, @Nullable Bitmap image, boolean showViewers, Context context) { Intent resultIntent = LiveStreamActivity.createLiveStreamIntent(stream, false, context); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MyStreamsActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent clickIntent = stackBuilder.getPendingIntent( stream.getChannelInfo().getDisplayName().hashCode(), PendingIntent.FLAG_UPDATE_CURRENT ); NotificationTextData textData = constructStreamNotificationText(stream, context); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getString(R.string.live_streamer_notification_id)) .setAutoCancel(false) .setContentTitle(textData.getTitle()) .setContentText(textData.getContent()) .setGroup(GROUP_KEY) .setWhen(stream.getStartedAt()) .setShowWhen(true) .setSmallIcon(R.drawable.ic_notification_icon_refresh) .setColor(ContextCompat.getColor(context, R.color.primary)) .setContentIntent(clickIntent) .setSound(null); if (image != null) { mBuilder.setLargeIcon(image); } if (showViewers) { mBuilder.setSubText(textData.getSubtext()); } return mBuilder.build(); }
Example 9
Source File: CBIServiceMain.java From CarBusInterface with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); if (D) Log.d(TAG, "onCreate()"); //create this as we need to get user preferences several times mSettings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); //setup a receiver to watch for bluetooth adapter state changes final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); this.registerReceiver(mBTStateReceiver, filter); //setup the persistent notification as required for any service that returns START_STICKY final Intent intent = new Intent(this, CBIActivityMain.class); intent.setAction(Intent.ACTION_EDIT); final TaskStackBuilder stack = TaskStackBuilder.create(this); stack.addParentStack(CBIActivityMain.class); stack.addNextIntent(intent); PendingIntent resultPendingIntent = stack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNoticeBuilder = new Notification.Builder(this); mNoticeBuilder.setOngoing(true); mNoticeBuilder.setPriority(Notification.PRIORITY_LOW); mNoticeBuilder.setContentIntent(resultPendingIntent); mNoticeBuilder.setSmallIcon(R.drawable.ic_notice); mNoticeBuilder.setContentTitle(getString(R.string.app_name)); mNoticeStatus = getString(R.string.msg_starting); mNoticeBuilder.setContentText(mNoticeStatus); mNoticeManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); mNoticeManager.notify(PERSISTENT_NOTIFICATION_ID, mNoticeBuilder.build()); }
Example 10
Source File: NLService.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Creates an intent to open Fit Notifications settings when notification is clicked. */ private PendingIntent createSettingsIntent() { // Creates an explicit intent for the SettingsActivity in the app Intent settingsIntent = new Intent(this, SettingsActivity.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 the application to // the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(settingsIntent); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 11
Source File: RecommendationsService.java From iview-android-tv with MIT License | 5 votes |
private PendingIntent buildPendingIntent(EpisodeModel ep) { Intent intent = new Intent(this, DetailsActivity.class); intent.putExtra(ContentManager.CONTENT_ID, ep); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(DetailsActivity.class); stackBuilder.addNextIntent(intent); intent.setAction(ep.getHref()); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 12
Source File: AppGcmReceiverUIBackground.java From RxGcm with Apache License 2.0 | 5 votes |
private PendingIntent getPendingIntentForNotification(Application application, Message message) { Class<? extends Activity> classActivity = message.target().equals(GcmServerService.TARGET_ISSUE_GCM) ? HostActivityIssues.class : HostActivitySupplies.class; Intent resultIntent = new Intent(application, classActivity); TaskStackBuilder stackBuilder = TaskStackBuilder.create(application); stackBuilder.addParentStack(classActivity); stackBuilder.addNextIntent(resultIntent); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); }
Example 13
Source File: RecommendationsService.java From iview-android-tv with MIT License | 5 votes |
private PendingIntent buildPendingIntent(EpisodeModel ep) { Intent intent = new Intent(this, DetailsActivity.class); intent.putExtra(ContentManager.CONTENT_ID, ep); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(DetailsActivity.class); stackBuilder.addNextIntent(intent); intent.setAction(ep.getHref()); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 14
Source File: Notification.java From BLEMeshChat with Mozilla Public License 2.0 | 5 votes |
private static PendingIntent makePendingIntent(@NonNull Context context, @NonNull Intent resultIntent) { TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack stackBuilder.addParentStack(MainActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(resultIntent); // Gets a PendingIntent containing the entire back stack return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 15
Source File: ComposeTweetService.java From catnut with MIT License | 5 votes |
@Override public void asyncProcess(Context context, JSONObject json) throws Exception { // 本地持久化 ContentValues tweet = Status.METADATA.convert(json); tweet.put(Status.TYPE, Status.HOME); // 标记一下 getContentResolver().insert(CatnutProvider.parse(Status.MULTIPLE), tweet); String update = CatnutUtils.increment(true, User.TABLE, User.statuses_count, mApp.getAccessToken().uid); getContentResolver().update(CatnutProvider.parse(User.MULTIPLE), null, update, null); // 更新status bar mBuilder.setContentText(getText(R.string.post_success)) .setTicker(getText(R.string.post_success)) .setProgress(0, 0, false); // 设置点击后的跳转 Intent resultIntent = new Intent(ComposeTweetService.this, TweetActivity.class); resultIntent.putExtra(Constants.ID, json.optLong(Constants.ID)); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(ComposeTweetService.this); taskStackBuilder.addParentStack(TweetActivity.class); taskStackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent( ID, PendingIntent.FLAG_UPDATE_CURRENT ); // 判断一下是否是已经保存的草稿 if (draft.id != Integer.MIN_VALUE) { getContentResolver().delete(CatnutProvider.parse(Draft.MULTIPLE), BaseColumns._ID + "=" + draft.id, null); } mBuilder.setContentIntent(resultPendingIntent); mBuilder.setAutoCancel(true); mNotifyManager.notify(ID, mBuilder.build()); }
Example 16
Source File: WakeupReceiver.java From loaned-android with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") private void doNotification(Context c, Person person, Item item, Loan loan){ // Get picture for person. If none available, use app icon // Calculate days on loan // Set title to item name // Set message to "{person name} has had this for {number of days} days" // Set Intent to open app to main screen NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c); mBuilder.setSmallIcon(R.drawable.ic_launcher_grey); mBuilder.setContentTitle(item.getName()); long timeDifference = new Date().getTime()-loan.getStartDate().getTime(); int days = (int) (timeDifference / (1000*60*60*24)); mBuilder.setContentText(person.getName()+" has had this item for "+ Integer.toString(days) +" days"); NotificationManager mNotificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE); Intent resultIntent = new Intent(c, LoanHistoryActivity.class); Bundle b = new Bundle(); // Set which fragment to show based on the user's preference of preferred view if(SettingsFragment.isShowingItemList(c)){ b.putBoolean(LoanHistoryActivity.IS_FOR_ITEM, true); b.putInt(LoanHistoryActivity.ITEM_ID, item.getItemID()); } else { b.putBoolean(LoanHistoryActivity.IS_FOR_ITEM, false); b.putInt(LoanHistoryActivity.PERSON_ID, person.getPersonID()); } resultIntent.putExtras(b); // 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. if(Build.VERSION.SDK_INT>=16){ // If JellyBean or newer TaskStackBuilder stackBuilder = TaskStackBuilder.create(c); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); } // NOTIFICATION_ID allows you to update the notification later on. mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
Example 17
Source File: RecommendationsService.java From android-tv-leanback with Apache License 2.0 | 5 votes |
private PendingIntent buildPendingIntent(Video video) { Intent detailsIntent = new Intent(this, PlayerActivity.class); detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(VideoDetailsActivity.class); stackBuilder.addNextIntent(detailsIntent); // Ensure a unique PendingIntents, otherwise all recommendations end up with the same // PendingIntent detailsIntent.setAction(Long.toString(video.getId())); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 18
Source File: RecommendationsService.java From android-tv-leanback with Apache License 2.0 | 5 votes |
private PendingIntent buildPendingIntent(Video video) { Intent detailsIntent = new Intent(this, PlayerActivity.class); detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(VideoDetailsActivity.class); stackBuilder.addNextIntent(detailsIntent); // Ensure a unique PendingIntents, otherwise all recommendations end up with the same // PendingIntent detailsIntent.setAction(Long.toString(video.getId())); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
Example 19
Source File: BluetoothMedic.java From android-beacon-library with Apache License 2.0 | 5 votes |
@RequiresApi(21) private void sendNotification(Context context, String message, String detail) { initializeWithContext(context); if(this.mNotificationsEnabled) { if (!this.mNotificationChannelCreated) { createNotificationChannel(context, "err"); } NotificationCompat.Builder builder = (new NotificationCompat.Builder(context, "err")) .setContentTitle("BluetoothMedic: " + message) .setSmallIcon(mNotificationIcon) .setVibrate(new long[]{200L, 100L, 200L}).setContentText(detail); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(new Intent("NoOperation")); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.notify(1, builder.build()); } } }
Example 20
Source File: PApp.java From PHONK with GNU General Public License v3.0 | 4 votes |
public Notification create(Map map) { Bitmap iconBmp = null; String iconName = (String) map.get("icon"); if (iconName != null) iconBmp = BitmapFactory.decodeFile(getAppRunner().getProject().getFullPathForFile(iconName)); String launchOnClick = null; launchOnClick = (String) map.get("launchOnClick"); Project p = new Project(launchOnClick); String notificationData = null; notificationData = (String) map.get("notificationData"); this.id = ((Number) map.get("id")).intValue(); Intent intent = new Intent(getContext(), MyBroadcastReceiver.class); intent.putExtra("notificationData", notificationData); intent.putExtra(Project.FOLDER, p.getFolder()); intent.putExtra(Project.NAME, p.getName()); intent.putExtra("isNotification", true); intent.putExtra("notificationId", this.id); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(getContext(), AppRunnerActivity.class); resultIntent.putExtra("notificationData", notificationData); resultIntent.putExtra(Project.FOLDER, p.getFolder()); resultIntent.putExtra(Project.NAME, p.getName()); resultIntent.putExtra("isNotification", true); resultIntent.putExtra("notificationId", this.id); // The stack builder object will contain an artificial back stack for navigating backward from the Activity leads out your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext()); stackBuilder.addParentStack(AppRunnerActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); this.mBuilder = new NotificationCompat.Builder(getContext(), getAppRunner().getProject().name) .setSmallIcon(R.drawable.bubble) .setContentTitle((CharSequence) map.get("title")) .setContentText((CharSequence) map.get("description")) .setLights(Color.parseColor((String) map.get("color")), 1000, 1000) .setLargeIcon(iconBmp) .setAutoCancel((Boolean) map.get("autocancel")) .setTicker((String) map.get("ticker")) .setSubText((CharSequence) map.get("subtext")) .setDeleteIntent(deletePendingIntent) .setContentIntent(resultPendingIntent); // damm annoying android pofkjpodsjf0ewiah if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel mChannel = new NotificationChannel(getAppRunner().getProject().name, getAppRunner().getProject().name, importance); // mChannel.setDescription("lalalla"); mChannel.enableLights(false); mNotificationManager.createNotificationChannel(mChannel); } else { } return this; }