@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showJellyBean() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.activity) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(this.title) .setContentText(this.text); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(activity, activity.getClass()); // 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(activity); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(activity.getClass()); // 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) activity.getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(this.id, mBuilder.build()); }
private void startAsForeground() { NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 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); int icon; if (Build.VERSION.SDK_INT > 21) icon = R.mipmap.ic_test; else icon = R.mipmap.ic_test103; mBuilder .setContentTitle("Stats Collector") .setContentText("Started: " + dateFormat.format(date)) .setSubText("Session: " + counter) .setContentInfo("Interval: " + Settings.interval) .setSmallIcon(icon) .setColor(Color.parseColor("#78909C")) .setCategory(Notification.CATEGORY_SERVICE) .setPriority(Notification.PRIORITY_LOW) .setContentIntent(resultPendingIntent); // .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_test1)); startForeground(ONGOING_NOTIFICATION_ID, mBuilder.build()); isForeground = true; }
public void setupNotification() { // From Google: http://developer.android.com/guide/topics/ui/notifiers/notifications.html NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.earphone) .setContentTitle("Cloud Player") .setContentText(cds.playlist_selected.get(cds.song_index)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); myspref = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstance()); SharedPreferences.Editor editor = myspref.edit(); editor.putBoolean("NOTIFICATION", true); editor.apply(); resultIntent.putExtra("fromNotification", true); mNotificationManager.notify(NOTIFY_ID, mBuilder.build()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(getIntent()); nome = i.getIntExtra("nome", nome); foto = i.getIntExtra("foto", foto); id = UUID.fromString(i.getStringExtra("id")); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.novo_evento)); builder.setContentText(getString(nome)); builder.setTicker(getString(R.string.notificacao_evento)); builder.setSmallIcon(foto); // TODO colocar rodar mesmo com app fechado Intent resultIntent = new Intent(this, EventoPagerActivity.class); resultIntent.putExtra(EventoFragment.EXTRA_EVENTO_ID, id); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(resultPendingIntent); builder.setAutoCancel(true); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(idNotificacao, builder.build()); finish(); }
/** * Custom View Notification * * @return Notification * @see CreateNotification */ private Notification setCustomViewNotification() { // Creates an explicit intent for an ResultActivity to receive. Intent resultIntent = new Intent(this, ResultActivity.class); // This ensures that the back button follows the recommended convention for the back key. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ResultActivity.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); // Create remote view and set bigContentView. RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote); expandedView.setTextViewText(R.id.text_view, "Neat logo!"); Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContentIntent(resultPendingIntent) .setContentTitle("Custom View") .build(); notification.bigContentView = expandedView; return notification; }
private void sendNotification(String uniqueId) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle("New item found") .setContentText("An beacon of item " + uniqueId + " is nearby.") .setSmallIcon(R.drawable.ic_shopping_basket_24dp) .setAutoCancel(true); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(DetailViewActivity.class); // Adds the Intent to the top of the stack Intent intent = new Intent(this, DetailViewActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); ItemSet itemSet = new ItemSet(); itemSet.imageList.add(SpecifyViewActivity.setBtImage(uniqueId)); intent.putExtra("itemSet", itemSet); intent.putExtra("name", (String) null); intent.putExtra("id", Integer.parseInt(uniqueId)); intent.setAction(Long.toString(System.currentTimeMillis())); stackBuilder.addNextIntent(intent); // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Integer.parseInt(uniqueId), builder.build()); }
private void handleErrorInBackground(ConnectionResult connectionResult, int startId) { if (!connectionResult.hasResolution()) { // Show the localized error notification GoogleApiAvailability.getInstance() .showErrorNotification(this, connectionResult.getErrorCode()); return; } // The failure has a resolution. Resolve it. // Called typically when the app is not yet authorized, and an // authorization dialog is displayed to the user. Intent resultIntent = new Intent(this, WorkoutListActivity.class); resultIntent.putExtra(WorkoutListActivity.EXTRA_PLAY_API_CONNECT_RESULT, connectionResult); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(WorkoutListActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle( getResources().getString(R.string.permission_needed_play_service_title)) .setContentText(getResources().getString(R.string.permission_needed_play_service)) .setSmallIcon(R.drawable.common_ic_googleplayservices) .setContentIntent(resultPendingIntent) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setCategory(Notification.CATEGORY_ERROR); } ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(Constants.NOTIFICATION_PLAY_INTERACTION, notificationBuilder.build()); stopSelfResult(startId); }
public void showNotification(Friend f) { Log.i(TAG, "notification"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Tracing of \n" + f.getPseudo()) .setContentText(f.getFirstName() + "," + f.getLastName()); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, GoogleMapActivity.class); f.setVisibleInMap(true); // resultIntent.putExtra("onePoint", f); // 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(GoogleMapActivity.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(0, mBuilder.build()); }
public void sendNotification() { // // Create an explicit intent for a MainActivity in my app Intent mainActivityIntent = new Intent(activity, CallActivity.class); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.notification_template_icon_bg) .setContentTitle(" Title (test):") .setContentText("content") .setAutoCancel(true); // 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 my application // to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(activity); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Add the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(mainActivityIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(TEST_NOTIF_ID, notificationBuilder.build()); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void notifyMe(String titulo, String message) { counter++; NotificationCompat.Builder mNotifyBuilder; NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); mNotifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(titulo) .setContentText(message) .setSmallIcon(R.mipmap.ic_launcher) .setDefaults(Notification.DEFAULT_SOUND) .setNumber(counter) .setAutoCancel(true); mNotifyBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build()); Intent intent = new Intent(this, HomeActivity.class); intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(HomeActivity.class); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build()); }
@Override public void onClick(View v) { // TODO Auto-generated method stub NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World! \n hello world!!"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainController.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(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainController.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) getActivity().getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mBuilder.setTicker("helo"); mNotificationManager.notify(1, mBuilder.build()); mBuilder.setNumber(1).setAutoCancel(true); }
private void fireSimpleDefaultPriorityNotification(String notificationTitle, String contentText) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(notificationTitle) .setContentText(contentText) .setPriority(NotificationCompat.PRIORITY_DEFAULT); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainSetupActivity.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(MainSetupActivity.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); // simpleDefaultPriorityNotificationID allows you to update the notification later on. mNotificationManager.notify(simpleDefaultPriorityNotificationID, mBuilder.build()); }
public void showNotification(String title, String text) { mId = PreferenceEditor.getInstance().getNotificationCount(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_setting_light) .setContentTitle("Tesseract - " + title) .setContentText(text); // 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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
private PendingIntent getPendingIntent(Context mContext, ShowUpdate update) { Intent intent = new Intent(mContext, ShowDetailsActivity.class); intent.putExtra(ShowDetailsActivity.EXTRA_SHOW, update.show()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ShowDetailsActivity.class); stackBuilder.addNextIntent(intent); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
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); }
private void sendNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle("LittleHelper") .setContentText("An beacon is nearby.") .setSmallIcon(R.mipmap.ic_launcher); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addNextIntent(new Intent(this, MainActivity.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()); }
public void showNotification(Notification.Builder notificationBuilder) { Intent resultIntent = new Intent(this, this.getClass()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(this.getClass()); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = getSystemService(Context.NOTIFICATION_SERVICE, NotificationManager.class); notificationManager.notify(notificationID++, notificationBuilder.build()); }
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. Intent intent = new Intent(); int id = item.getItemId(); if (id == R.id.nav_activation) { intent = new Intent(ContactsActivity.this, ActivationActivity.class); } else if (id == R.id.nav_profile) { intent = new Intent(ContactsActivity.this, ProfileActivity.class); intent.putExtra( "username", SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username")); } else if (id == R.id.nav_contacts) { intent = new Intent(ContactsActivity.this, ContactsActivity.class); } else if (id == R.id.nav_settings) { intent = new Intent(ContactsActivity.this, SettingsActivity.class); } else if (id == R.id.nav_logout) { SharedPreferencesHelper.removeKey(getApplicationContext(), "username"); SharedPreferencesHelper.removeKey(getApplicationContext(), "loggedIn"); intent = new Intent(ContactsActivity.this, LoginActivity.class); TaskStackBuilder.create(getApplicationContext()) .addNextIntentWithParentStack(intent) .startActivities(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); startActivity(intent); return true; }
@SuppressLint("NewApi") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { AlertActivity alertActivity = AlertActivity.this; Cursor cursor = alertActivity.getItemForView(view); long alarmId = cursor.getLong(INDEX_ROW_ID); long eventId = cursor.getLong(AlertActivity.INDEX_EVENT_ID); long startMillis = cursor.getLong(AlertActivity.INDEX_BEGIN); // Mark this alarm as DISMISSED dismissAlarm(alarmId, eventId, startMillis); // build an intent and task stack to start EventInfoActivity with AllInOneActivity // as the parent activity rooted to home. long endMillis = cursor.getLong(AlertActivity.INDEX_END); Intent eventIntent = AlertUtils.buildEventViewIntent(AlertActivity.this, eventId, startMillis, endMillis); if (Utils.isJellybeanOrLater()) { TaskStackBuilder.create(AlertActivity.this) .addParentStack(EventInfoActivity.class) .addNextIntent(eventIntent) .startActivities(); } else { alertActivity.startActivity(eventIntent); } alertActivity.finish(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void triggerNotification(String info, String info2, Context context, Intent intent) { NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_directions_bus_black_48dp) .setContentTitle(context.getResources().getString(R.string.app_name)) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(info2)) .setContentText(info) .setVibrate(null) .setSound(null) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); // Notifications if (Repository.getInstance().getRingtoneNotification().equals(true)) { // Ton Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); } if (Repository.getInstance().getVibrationNotification().equals(true)) { // Vibration mBuilder.setVibrate(new long[] {1000, 1000, 1000, 1000, 1000}); } if (Repository.getInstance().getLedNotification().equals(true)) { // LED mBuilder.setLights(ContextCompat.getColor(context, R.color.ledColour), 1000, 1000); } // Creates an explicit intent for an Activity Intent resultIntent = new Intent(context, 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 // application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // 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); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(418, mBuilder.build()); }
/** * Inbox Style Notification * * @return Notification * @see CreateNotification */ private Notification setInboxStyleNotification() { Bitmap remote_picture = null; // Create the style object with InboxStyle subclass. NotificationCompat.InboxStyle notiStyle = new NotificationCompat.InboxStyle(); notiStyle.setBigContentTitle("Inbox Style Expanded"); // Add the multiple lines to the style. // This is strictly for providing an example of multiple lines. for (int i = 0; i < 5; i++) { notiStyle.addLine("(" + i + " of 6) Line one here."); } notiStyle.setSummaryText("+2 more Line Samples"); try { remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent()); } catch (IOException e) { e.printStackTrace(); } // Creates an explicit intent for an ResultActivity to receive. Intent resultIntent = new Intent(this, ResultActivity.class); // This ensures that the back button follows the recommended convention for the back key. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself). stackBuilder.addParentStack(ResultActivity.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); return new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setLargeIcon(remote_picture) .setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_launcher, "One", resultPendingIntent) .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent) .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent) .setContentTitle("Inbox Style Normal") .setContentText("This is an example of a Inbox Style.") .setStyle(notiStyle) .build(); }
/** * Big Text Style Notification * * @return Notification * @see CreateNotification */ private Notification setBigTextStyleNotification() { Bitmap remote_picture = null; // Create the style object with BigTextStyle subclass. NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle(); notiStyle.setBigContentTitle("Big Text Expanded"); notiStyle.setSummaryText("Nice big text."); try { remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent()); } catch (IOException e) { e.printStackTrace(); } // Add the big text to the style. CharSequence bigText = "This is an example of a large string to demo how much " + "text you can show in a 'Big Text Style' notification."; notiStyle.bigText(bigText); // Creates an explicit intent for an ResultActivity to receive. Intent resultIntent = new Intent(this, ResultActivity.class); // This ensures that the back button follows the recommended convention for the back key. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself). stackBuilder.addParentStack(ResultActivity.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); return new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setLargeIcon(remote_picture) .setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_launcher, "One", resultPendingIntent) .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent) .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent) .setContentTitle("Big Text Normal") .setContentText("This is an example of a Big Text Style.") .setStyle(notiStyle) .build(); }
private void startApplicationDetailsActivity(String packageName) { Intent intent = new Intent( Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)); intent.setComponent(intent.resolveActivity(mContext.getPackageManager())); TaskStackBuilder.create(getContext()).addNextIntentWithParentStack(intent).startActivities(); }
@Override public void onCreate() { IntentFilter filterUsbDetached = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mUsbDetachedReceiver, filterUsbDetached); Intent settingsIntent = new Intent(this, SteeringWheelInterfaceActivity.class); settingsIntent.setAction(Intent.ACTION_EDIT); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(SteeringWheelInterfaceActivity.class); stackBuilder.addNextIntent(settingsIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNoticeBuilder.setContentIntent(resultPendingIntent); mNoticeBuilder.setSmallIcon(R.drawable.ic_notice); mNoticeBuilder.setContentTitle(getString(R.string.app_name)); mNoticeBuilder.setContentText(getString(R.string.msg_app_starting)); mNoticeManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNoticeManager.notify(mNoticeID, mNoticeBuilder.build()); mCarInterface = new ElmInterface(getApplicationContext()); mCarInterface.deviceOpenEvent_AddListener(mDeviceOpenListener); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String baudDefault = getString(R.string.scantool_baud); int baudValue = Integer.parseInt(settings.getString("scantool_baud", baudDefault)); mCarInterface.setBaudRate(baudValue); String deviceNumDefault = getString(R.string.scantool_device_number); int deviceNumValue = Integer.parseInt(settings.getString("scantool_device_number", deviceNumDefault)); mCarInterface.setDeviceNumber(deviceNumValue); String protocolCommandDefault = getString(R.string.scantool_protocol); String protocolCommandValue = settings.getString("scantool_protocol", protocolCommandDefault); mCarInterface.setProtocolCommand(protocolCommandValue); String monitorCommandDefault = getString(R.string.scantool_monitor_command); String monitorCommandValue = settings.getString("scantool_monitor_command", monitorCommandDefault); mCarInterface.setMonitorCommand(monitorCommandValue); }
@SuppressLint("NewApi") public static void notifyUser(String title, String text, Intent intent, Activity activity) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(title) .setContentText(text); TaskStackBuilder stackBuilder = TaskStackBuilder.create(activity); stackBuilder.addParentStack(activity.getClass()); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
@Override public void onHandleIntent(Intent intent) { long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1); long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1); long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1); boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false); long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY); int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1); Uri uri = CalendarAlerts.CONTENT_URI; String selection; // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms if (eventId != -1) { selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId; } else if (eventIds != null && eventIds.length > 0) { selection = buildMultipleEventsQuery(eventIds); } else { selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED; } ContentResolver resolver = getContentResolver(); ContentValues values = new ContentValues(); values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED); resolver.update(uri, values, selection, null); // Remove from notification bar. if (notificationId != -1) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(notificationId); } if (showEvent) { // Show event on Calendar app by building an intent and task stack to start // EventInfoActivity with AllInOneActivity as the parent activity rooted to home. Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd); TaskStackBuilder.create(this) .addParentStack(EventInfoActivity.class) .addNextIntent(i) .startActivities(); } // Stop this service stopSelf(); }
// NOTIFICATION! public void startNotification() { String titlee = "Hey Good Looking"; String contente = "Whats cooking?"; File f = getBaseContext().getFileStreamPath("Done.txt"); if (!f.exists()) return; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)) .setContentTitle(titlee) .setContentText(contente) .setAutoCancel(true) .setVibrate(new long[100]) .setPriority(Notification.PRIORITY_MAX); if (Build.VERSION.SDK_INT >= 21) mBuilder.setVibrate(new long[0]); Intent resultIntent = new Intent(this, OpenCamera.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.addAction(0, "Take a Selfie!", resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); try { FileOutputStream fos = openFileOutput("Done.txt", Context.MODE_APPEND); fos.write(("yio").getBytes()); fos.close(); } catch (Exception e) { } }
@Override public void onTaskViewAppInfoClicked(Task t) { // Create a new task stack with the application info details activity Intent baseIntent = t.key.baseIntent; Intent intent = new Intent( Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null)); intent.setComponent(intent.resolveActivity(getContext().getPackageManager())); TaskStackBuilder.create(getContext()) .addNextIntentWithParentStack(intent) .startActivities(null, new UserHandle(t.key.userId)); }
public void sendAlert(String stockSymbol, String targetPrice, String stockState) { Notification.Builder mBuilder = new Notification.Builder(this) .setSmallIcon(R.drawable.appicon) .setContentTitle("EZQuote - '" + stockSymbol + "'") .setContentText(stockState + " Target Price " + targetPrice + " reached. Hurry!"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MarketSummaryActivity.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(MarketSummaryActivity.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(getRandomNumber(), mBuilder.build()); // Delete the alarm after it goes off. for (ParseObject o : alertObjs) { if (stockSymbol.equalsIgnoreCase((o.getString("symbol"))) && targetPrice.equals(o.getString("targetPrice")) && stockState.equals(o.getString("StockState"))) { o.deleteInBackground(); } } }
private void goToSection() { // Intent sectionIntent = new Intent(this, SingleSheetActivity.class); Section sectionaux = Utils.getSectionByID(String.valueOf(value.getRef_sectionID())); Sheet sheetAux = Utils.getSheetByID(String.valueOf(sectionaux.getRef_SheetID())); Intent singlesheetIntent = new Intent(this, SingleSheetWithTabsActivity.class); String rootID = ""; if (sheetAux != null) { rootID = sheetAux.getRef_UserID(); } singlesheetIntent.putExtra("rootID", rootID); singlesheetIntent.putExtra("sheetID", String.valueOf(sectionaux.getRef_SheetID())); // sectionIntent.putExtra("sheetID", String.valueOf(sectionaux.getRef_SheetID())); Intent home = new Intent(this, RootsActivity.class); home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); taskStackBuilder.addNextIntent(home); taskStackBuilder.addNextIntent(singlesheetIntent); taskStackBuilder.startActivities(); onBackPressed(); }