List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION
int TYPE_NOTIFICATION
To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.
Click Source Link
From source file:com.aylanetworks.aura.GcmIntentService.java
private void sendNotification(String msg, String sound) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); // Find the launcher class for our application PackageManager pm = getPackageManager(); String packageName = getPackageName(); Intent query = new Intent(Intent.ACTION_MAIN); Class launcherClass = null;// w w w.ja va 2 s .c om query.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> foundIntents = pm.queryIntentActivities(query, 0); for (ResolveInfo info : foundIntents) { if (TextUtils.equals(info.activityInfo.packageName, packageName)) { launcherClass = info.activityInfo.getClass(); } } if (launcherClass == null) { Log.e(TAG, "Could not find application launcher class"); return; } Intent appIntent = new Intent(this, launcherClass); // main activity of Ayla Control/aMCA PendingIntent contentIntent = PendingIntent.getActivity(this, 0, appIntent, 0); //Determine the sound to be played Uri soundUri = null; if (sound == null) { // NOP //PushNotification.playSound("bdth.mp3"); } else if (sound.equals("none")) { // NOP } else if (sound.equals("default")) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM } else if (sound.equals("alarm")) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // TYPE_NOTIFICATION or TYPE_ALARM } else { boolean playedSound; playedSound = PushNotification.playSound(sound); if (playedSound == false) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM } } // @formatter:off NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) //.setSound(soundUri) .setSmallIcon(R.drawable.ic_push_icon).setContentTitle(getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFFff0000, 500, 500) // flashing red light .setContentText(msg).setAutoCancel(true) //.setPriority(Notification.FLAG_HIGH_PRIORITY) .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS); // @formatter:on if (soundUri != null) { mBuilder.setSound(soundUri); } mBuilder.setPriority(PRIORITY_MAX); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.pulp.campaigntracker.gcm.GcmIntentService.java
@SuppressWarnings("unchecked") private void sendNotification(GCM msg) { if (msg != null) { int index = 1; mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); bigText.bigText(msg.getMessage()); bigText.setBigContentTitle(msg.getTitle()); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationCount = mAppPref.getInt("Notif_Number_Constant", 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_app_icon).setContentTitle(msg.getTitle()) .setStyle(bigText).setContentText(msg.getMessage()).setSound(uri) .setNumber(mNotificationCount + 1); mAppPref.edit().putInt("Notif_Number_Constant", (mNotificationCount + 1)).commit(); try {//from w w w . ja v a 2 s .c o m if ((ArrayList<UserNotification>) ObjectSerializer .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, "")) == null) { notifyList = new ArrayList<UserNotification>(); } else { notifyList = (ArrayList<UserNotification>) ObjectSerializer .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, "")); } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } notification = new UserNotification(); notification.setTitle(msg.getTitle()); notification.setMessage(msg.getMessage()); notification.setNotifyTime(System.currentTimeMillis()); notifyList.add(notification); try { mAppPref.edit().putString(ConstantUtils.NOTIFICATION, ObjectSerializer.serialize(notifyList)) .commit(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent newIntent = null; ConstantUtils.SYNC_INTERVAL = 30 * 60 * 1000; // if (mAppPref.getString(ConstantUtils.USER_ROLE, "") // .equals(LoginData.)) { // newIntent = new Intent(getBaseContext(), // UserMotherActivity.class); // Intent i = new Intent(this, PeriodicService.class); // this.startService(i); // } else { newIntent = new Intent(getBaseContext(), SplashScreen.class); Intent i = new Intent(this, PeriodicService.class); this.startService(i); // } PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, 0, newIntent, 0); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(index, mBuilder.build()); Intent intent = new Intent(); intent.setAction("googleCloudMessage"); sendBroadcast(intent); } }
From source file:jahirfiquitiva.iconshowcase.services.NotificationsService.java
@SuppressWarnings("ResourceAsColor") private void pushNotification(String content, int type, int ID) { Preferences mPrefs = new Preferences(this); String appName = Utils.getStringFromResources(this, R.string.app_name); String title = appName, notifContent = null; switch (type) { case 1:/* ww w .j a v a 2 s .c o m*/ title = getResources().getString(R.string.new_walls_notif_title, appName); notifContent = getResources().getString(R.string.new_walls_notif_content, content); break; case 2: title = appName + " " + getResources().getString(R.string.news).toLowerCase(); notifContent = content; break; } // Send Notification NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); notifBuilder.setAutoCancel(true); notifBuilder.setContentTitle(title); if (notifContent != null) { notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notifContent)); notifBuilder.setContentText(notifContent); } notifBuilder.setTicker(title); Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notifBuilder.setSound(ringtoneUri); if (mPrefs.getNotifsVibrationEnabled()) { notifBuilder.setVibrate(new long[] { 500, 500 }); } else { notifBuilder.setVibrate(null); } int ledColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.dark_theme_accent) : ContextCompat.getColor(this, R.color.light_theme_accent); notifBuilder.setColor(ledColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notifBuilder.setPriority(Notification.PRIORITY_HIGH); } Class appLauncherActivity = getLauncherClass(getApplicationContext()); if (appLauncherActivity != null) { Intent appIntent = new Intent(this, appLauncherActivity); appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); appIntent.putExtra("notifType", type); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(appLauncherActivity); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(appIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notifBuilder.setContentIntent(resultPendingIntent); } notifBuilder.setOngoing(false); notifBuilder.setSmallIcon(R.drawable.ic_notifications); Notification notif = notifBuilder.build(); if (mPrefs.getNotifsLedEnabled()) { notif.ledARGB = ledColor; } notifManager.notify(ID, notif); }
From source file:com.gcmandroid_uniqueid1010.nemo.NirapodNouvromon.gcm.MyGcmPushReceiver.java
private void sendNotification(String message, String title) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); int requestCode = 0; int icon = this.getResources().getIdentifier("app_icon", "drawable", this.getPackageName()); if (alertClass_global.getIs_resolved() == 1) { icon = this.getResources().getIdentifier("danger", "drawable", this.getPackageName()); }//from ww w. j a v a 2s. com if (alertClass_global.getIs_resolved() == 2) { icon = this.getResources().getIdentifier("relax", "drawable", this.getPackageName()); } PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) // .setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(icon).setContentTitle(title).setContentText(message).setAutoCancel(true) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, noBuilder.build()); //0 = ID of notification }
From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java
public void notifyAnnouncement(String announcement) { Intent contentIntent = new Intent(this, MainActivity.class); contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS); contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent, PendingIntent.FLAG_ONE_SHOT); Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle(); notifStyle.bigText(announcement);/*from ww w . j a va 2 s. c o m*/ notifStyle.setBigContentTitle(getString(R.string.notif_announcement_title)); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon_nodpi) .setContentTitle(getString(R.string.notif_announcement_title)).setContentText(announcement) .setAutoCancel(true).setSound(defaultSoundUri) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent) .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off, getString(R.string.notif_action_options), settingsPendingIntent); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(NOTIFICATION_ID_ANNOUNCEMENT, notificationBuilder.build()); }
From source file:com.sourceauditor.sahomemonitor.GcmIntentService.java
private void sendNotification(String msg, Bundle extras) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notifyMainIntent = buildIntentForMainActifity(extras); // Figure out how to add extras for the URL and message PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyMainIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.home_small).setContentTitle("Home Monitor Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setExtras(extras).setContentText(msg); mBuilder.setContentIntent(contentIntent); mBuilder.setPriority(Notification.PRIORITY_MAX); mBuilder.setLights(0xFF0000, 500, 500); long[] pattern = new long[] { 0, 500, 0, 500, 0, 500, 0, 500, 0, 500 }; mBuilder.setVibrate(pattern);// w w w.j av a2 s .c o m Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(soundUri); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.magnet.mmx.client.MMXWakeupIntentService.java
private void invokeNotificationForPush(GCMPayload payload) { // Launch the activity with action=MAIN, category=DEFAULT. Make sure that // it has DEFAULT category declared in AndroidManifest.xml intent-filter. PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0, new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName()) .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED), PendingIntent.FLAG_UPDATE_CURRENT); // If title is not specified, use the app name (compatible with iOS push notification) String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle(); Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent) .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title) .setContentText(payload.getBody()); if (payload.getSound() != null) { // TODO: cannot handle custom sound yet; use notification ring tone. noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); }/*from w w w . j av a 2 s. c om*/ if (payload.getIcon() != null) { noteBuilder.setSmallIcon( this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName())); } else { noteBuilder.setSmallIcon(this.getApplicationInfo().icon); } if (payload.getBadge() != null) { noteBuilder.setNumber(payload.getBadge()); } NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); noteMgr.notify(sNoteId++, noteBuilder.build()); }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
private void playNotificationSound(Context context) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { Ringtone rt = RingtoneManager.getRingtone(context, uri); if (rt != null) rt.play();//w w w . j av a 2 s.c o m } }
From source file:com.fast.van.cloudmessaging.MyGcmListenerService.java
private void sendNotification(String message) { /*Intent intent;/* w w w. j a va 2s .co m*/ if(notificationType!=null&¬ificationType.equals("DRIVER_ASSIGNED")){ intent=new Intent(this,ActivityNewRequest.class); }else{ }*/ Intent intent = new Intent(this, ActivityOrderStateNotification.class); intent.putExtra("message", message); if (BaseActivity.isForeGround()) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return; } BaseUtils.removeCancelNotification(this); 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.mipmap.notification).setContentTitle(getString(R.string.app_name)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(128 /* ID of notification */, notificationBuilder.build()); }
From source file:com.gsma.rcs.ri.extension.MultiMediaSessionIntentService.java
private void addSessionInvitationNotification(Intent intent, ContactId contact) { /* Create pending intent */ Intent invitation = new Intent(intent); String title;/*from ww w .j a v a2 s.c o m*/ if (mMultimediaMessagingSession) { invitation.setClass(this, MessagingSessionView.class); title = getString(R.string.title_recv_messaging_session); } else { invitation.setClass(this, StreamingSessionView.class); title = getString(R.string.title_recv_streaming_session); } invitation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* * If the PendingIntent has the same operation, action, data, categories, components, and * flags it will be replaced. Invitation should be notified individually so we use a random * generator to provide a unique request code and reuse it for the notification. */ int uniqueId = Utils.getUniqueIdForPendingIntent(); PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, invitation, PendingIntent.FLAG_ONE_SHOT); String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact); /* Create notification */ NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(contentIntent); notif.setSmallIcon(R.drawable.ri_notif_mm_session_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(getString(R.string.label_from_args, displayName)); /* Send notification */ NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(uniqueId, notif.build()); }