List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:ca.rmen.android.poetassistant.wotd.Wotd.java
static void notifyWotd(Context context, Dictionary dictionary) { Log.v(TAG, "notifyWotd"); DictionaryEntry entry = dictionary.getRandomEntry(getTodayUTC().getTimeInMillis()); if (entry == null) return;/*from w w w. j av a 2s.co m*/ String title = context.getString(R.string.wotd_notification_title, entry.word); CharSequence content = buildWotdNotificationContent(context, entry); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(content); Uri uri = Uri.parse(String.format("poetassistant://%s/%s", Constants.DEEP_LINK_QUERY, entry.word)); Intent intent = new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW).setData(uri) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); int iconId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_book_vector : R.drawable.ic_book; Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(pendingIntent).setContentText(content).setContentTitle(title).setSmallIcon(iconId) .setStyle(bigTextStyle) .addAction(getShareIconId(), context.getString(R.string.share), getShareIntent(context, entry)) .build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(TAG.hashCode(), notification); }
From source file:pj.rozkladWKD.C2DMReceiver.java
public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent, int number) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.ic_launcher_wkd; CharSequence tickerText = ticker; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); notification.number = Prefs.getNotificationMessageNextNumber(context); notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences prefs = Prefs.get(context); if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true)) notification.defaults |= Notification.DEFAULT_SOUND; if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true)) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:jp.co.ipublishing.esnavi.impl.gcm.GcmIntentService.java
/** * Notification??//from w ww . ja va2 s . co m * * @param alert */ private void sendNotification(@NonNull Alert alert) { final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); final Intent resultIntent = new Intent(this, MapActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent contentIntent = PendingIntent.getActivity(this, 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Notification.Builder builder = new Notification.Builder(this).setWhen(System.currentTimeMillis()) .setContentIntent(contentIntent) .setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS) .setAutoCancel(true).setTicker(alert.getHeadlineBody()).setContentText(alert.getHeadlineBody()); onPreSendNotification(builder, alert); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationManager.notify(NOTIFICATION_ID, builder.build()); } else { notificationManager.notify(NOTIFICATION_ID, builder.getNotification()); } }
From source file:com.amaze.carbonfilemanager.services.ExtractService.java
@Override public int onStartCommand(Intent intent, int flags, final int startId) { Bundle b = new Bundle(); String file = intent.getStringExtra(KEY_PATH_ZIP); String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT); if (extractPath != null) { // a custom dynamic path to extract files to epath = extractPath;/* www . j av a2 s .c om*/ } else { epath = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_PATH_EXTRACT, file); } mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); entries = intent.getStringArrayListExtra(KEY_ENTRIES_ZIP); b.putString(KEY_PATH_ZIP, file); totalSize = getTotalSize(file); progressHandler = new ProgressHandler(1, totalSize); progressHandler.setProgressListener(new ProgressHandler.ProgressListener() { @Override public void onProgressed(String fileName, int sourceFiles, int sourceProgress, long totalSize, long writtenSize, int speed) { publishResults(startId, fileName, sourceFiles, sourceProgress, totalSize, writtenSize, speed, false); } }); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mBuilder = new NotificationCompat.Builder(cd); mBuilder.setContentIntent(pendingIntent); mBuilder.setContentTitle(getResources().getString(R.string.extracting)) .setContentText(new File(file).getName()).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp); startForeground(Integer.parseInt("123" + startId), mBuilder.build()); new DoWork().execute(b); return START_STICKY; }
From source file:org.roman.findme.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w w w.j a v a 2s . c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MessageActivity.class); intent.putExtra("message", message); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Message").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); if (sharedPreferences.getBoolean("display_message", true)) { displayMessage(message); } }
From source file:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java
/** * Called when message is received./*from ww w . j a v a2 s . c om*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) { Log.d(TAG, "Message: " + message); try { JSONObject object = new JSONObject(message); ArrayList<String> eventItem = new ArrayList<>(); eventItem.add(object.toString()); broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem); if (!GameSingleton.activityForeground) { if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) { GameMessageTopic topic = GameMessageTopic .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC)); ChallengeMessage challengeMessage = new ChallengeMessage(topic, object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID), object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)); Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : " + challengeMessage.getChallengerId()); Intent intent2 = new Intent(this, DeviceListActivity.class); intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!") .setContentText("challenged by " + challengeMessage.getChallengerName()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build()); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn == false) { PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); wl_cpu.acquire(10000); } GameSingleton.pendingChallengeMessage = challengeMessage; GameSingleton.pendingChallenge = true; } } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.otaupdater.utils.RomInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.ROM_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_ROM_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_rom)); builder.setTicker(ctx.getString(R.string.notif_text_rom)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.ROM_NOTIF_ID, builder.build()); }
From source file:ca.justinrichard.link.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w .ja va2 s.c o m*/ private void sendNotification(String messageBody, String linkId) { Intent intent; if (linkId.equals("")) { intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else { intent = new Intent(this, LinkActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(LINK_ID, linkId); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_link).setColor(getResources().getColor(R.color.colorPrimary)) .setContentTitle("Link request").setContentText(messageBody).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.procasy.dubarah_nocker.gcm.MyGcmPushReceiver.java
/** * Called when message is received./* w w w . j a v a 2 s. c om*/ * * @param from SenderID of the sender. * @param bundle Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ @Override public void onMessageReceived(String from, Bundle bundle) { MainActivity.getInstance().updateNotification(); try { Log.e("notify_gcm", "success , type = " + bundle.toString()); switch (bundle.getString(GCM_TAG)) { case "GENERAL": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); 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); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, GENERAL_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "HELP": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); 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); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, HELP_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } JSONObject content = new JSONObject(bundle.getString("content")); JSONObject hr = content.getJSONObject("hr"); JSONArray album = content.getJSONArray("album"); System.out.println(content.getInt("hr_id")); System.out.println(content.toString()); Bundle bundle1 = new Bundle(); bundle1.putString("hr_id", hr.getString("hr_id")); bundle1.putString("hr_user_id", hr.getString("hr_user_id")); bundle1.putString("hr_description", hr.getString("hr_description")); bundle1.putString("hr_est_date", hr.getString("hr_est_date")); bundle1.putString("hr_est_time", hr.getString("hr_est_time")); bundle1.putString("hr_skill_id", hr.getString("hr_skill_id")); bundle1.putString("hr_ua_id", hr.getString("hr_ua_id")); bundle1.putString("hr_voice_record", hr.getString("hr_voice_record")); bundle1.putString("hr_language", hr.getString("hr_language")); bundle1.putString("hr_lat", hr.getString("hr_lat")); bundle1.putString("hr_lon", hr.getString("hr_lon")); bundle1.putString("hr_address", hr.getString("hr_address")); ArrayList<String> array = new ArrayList<>(); for (int i = 0; i < album.length(); i++) { JSONObject object = album.getJSONObject(i); array.add(object.getString("ahr_img")); } bundle1.putStringArrayList("album", array); Intent intent = (new Intent(getApplicationContext(), JobRequestActivity.class)); intent.putExtras(bundle1); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); break; } case "APPOINTEMENT": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); 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); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, APPOINTEMENT_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_USER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); 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); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, USER_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_NOCKER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); 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); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, Nocker_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } } } catch (Exception e) { e.printStackTrace(); } }