List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.vidinoti.pixlive.PixLive.java
static void startSDK(final Context c) { if (VDARSDKController.getInstance() != null) { return;/*from w w w .j av a 2 s . c om*/ } String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK"; String licenseKey = null; try { ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey"); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key."); return; } catch (NullPointerException e) { Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key."); return; } if (storage == null || licenseKey == null) { Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key."); return; } VDARSDKController.startSDK(c, storage, licenseKey); /* Comment out to disable QR code detection */ VDARSDKController.getInstance().setEnableCodesRecognition(true); VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() { @Override public Notification createNotification(String title, String message, String notificationID) { Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName()); appIntent.putExtra("nid", notificationID); appIntent.putExtra("remote", false); PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent, PendingIntent.FLAG_UPDATE_CURRENT); ApplicationInfo ai = c.getApplicationInfo(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c) .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off) .setContentTitle(title).setContentText(message).setContentIntent(contentIntent) .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 }) .setLights(Color.BLUE, 500, 1500); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); return mBuilder.getNotification(); } }); }
From source file:com.preguardia.app.notification.MyGcmListenerService.java
private void showPatientNotification(String title, String message, String consultationId) { // Prepare intent which is triggered if the notification is selected Intent intent = new Intent(this, ConsultationDetailsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId); PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_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_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(3, notificationBuilder.build()); }
From source file:com.android.contacts.editor.EditorUiUtils.java
/** * Returns a ringtone URI, based on the string and version #. *//*from w w w . j av a 2 s. co m*/ public static Uri getRingtoneUriFromString(String str, int currentVersion) { if (str != null) { if (isNewerThanM(currentVersion) && TextUtils.isEmpty(str)) return null; return Uri.parse(str); } return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); }
From source file:at.flack.receiver.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_sms", true); if (notify == false) return;// ww w . ja v a 2 s .c o m Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += msgs[i].getMessageBody().toString(); str += "\n"; } NotificationCompat.Builder mBuilder; if (main != null) { main.addNewMessage(str); return; } boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = null; try { origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress()); if (origin_name == null) origin_name = msgs[0].getDisplayOriginatingAddress(); } catch (Exception e) { } if (origin_name == null) origin_name = "Unknown"; try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int positionOfBase64End = str.lastIndexOf("="); if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) { mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon) .setContentTitle(origin_name).setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else if (str.toString().charAt(0) == '%' && (str.toString().length() == 10 || str.toString().length() == 9)) { int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (str.toString().charAt(0) == '%' && str.toString().length() >= 120 && str.toString().length() < 125) { // DH Handshake int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else { // unencrypted messages if (all) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(str)) .setSmallIcon(R.drawable.raven_notification_icon); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop) mNotificationManager.notify(7, mBuilder.build()); // Save SMS if default app if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) { ContentValues values = new ContentValues(); values.put("address", msgs[0].getDisplayOriginatingAddress()); values.put("body", str.replace("\n", "").replace("\r", "")); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;/*from w w w .java 2s . c om*/ } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // it is a direct message resultIntent = new Intent(context, RedirectToDMs.class); } else { resultIntent = new Intent(context, MainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Intent reply; if (unreadCounts[1] == 1) { reply = new Intent(context, NotificationCompose.class); } else { reply = new Intent(context, NotificationDMCompose.class); } Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } else { // otherwise, if they can use the expanded notifications, the popup button will be shown Intent popup = new Intent(context, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
From source file:com.nutsuser.ridersdomain.activities.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w w w . j a va 2 s . c om */ /* private void sendNotification(String message, long number_push) { Log.e("message: ", "" + message); *//* try { *//**//* mJsonObject = new JSONObject(message); // mStringType = mJson_Object.getString("type"); mStringUsername = mJson_Object.getString("username"); senderUserId = mJson_Object.getInt("sender_user_id"); mStringMessage = mJson_Object.getString("message"); Log.e("mStringMessage: ", "" + mStringMessage);*//**//* } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); }*//* // Intent intent = new Intent(this, MessagesActivity.class); //intent.putExtra("message_username", mStringUsername); //intent.putExtra("whrlocation", "notification"); //intent.putExtra("userId2", senderUserId); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); //Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), // R.drawable.ic_launcher); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Rider Opinion") .setContentText(message) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) number_push *//**//* ID of notification *//**//*, notificationBuilder.build()); }*/ //This method is generating a notification and displaying the notification private void sendNotification(String message) { Intent intent = new Intent(this, NotificationListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); int requestCode = 0; PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.app_icon).setContentTitle("Rider Opinion").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.brq.wallet.lt.notification.GcmIntentService.java
private void showTradeNotification(String type, long lastChange) { Intent intent;//from w w w. ja v a 2 s. c om if (LtApi.TRADE_FINAL_NOTIFICATION_TYPE.equals(type)) { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.TRADE_HISTORY); } else { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.ACTIVE_TRADES); } Intent pinProtectedIntent = PinProtectedActivity.createIntent(this, intent); PendingIntent pIntent = PendingIntent.getActivity(this, 0, pinProtectedIntent, PendingIntent.FLAG_CANCEL_CURRENT); String title = getResources().getString(R.string.lt_mycelium_local_trader_title); String message = getResources().getString(R.string.lt_new_trading_activity_message); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setContentText(message).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true); // Add ticker builder.setTicker(message); // Tell other listeners that we have taken care of audibly notifying up // till this timestamp LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager(); ltManager.setLastNotificationSoundTimestamp(lastChange); // Vibrate long[] pattern = { 500, 500 }; builder.setVibrate(pattern); // Make a sound if (ltManager.getPlaySoundOnTradeNotification()) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarmSound != null) { builder.setSound(alarmSound); } } // Notify NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.gsma.rcs.ri.messaging.filetransfer.FileTransferIntentService.java
/** * Generate a notification//from www . ja va 2 s .c om * * @param pendingIntent pending intent * @param title title * @param message message * @return the notification */ private Notification buildNotification(PendingIntent pendingIntent, String title, String message) { NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(pendingIntent); notif.setSmallIcon(R.drawable.ri_notif_file_transfer_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(message); return notif.build(); }
From source file:com.mycelium.wallet.lt.notification.GcmIntentService.java
private void showTradeNotification(String type, long lastChange) { Intent intent;/* ww w .j a va2 s . c o m*/ if (LtApi.TRADE_FINAL_NOTIFICATION_TYPE.equals(type)) { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.TRADE_HISTORY); } else { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.ACTIVE_TRADES); } Intent pinProtectedIntent = PinProtectedActivity.createIntent(this, intent); PendingIntent pIntent = PendingIntent.getActivity(this, 0, pinProtectedIntent, PendingIntent.FLAG_CANCEL_CURRENT); String title = getResources().getString(R.string.lt_mycelium_local_trader_title); String message = getResources().getString(R.string.lt_new_trading_activity_message); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setContentText(message).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true); // Add ticker builder.setTicker(message); // Tell other listeners that we have taken care of audibly notifying up // till this timestamp LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager(); ltManager.setLastNotificationSoundTimestamp(lastChange); // Vibrate long[] pattern = { 500, 500 }; builder.setVibrate(pattern); // Make a sound if (ltManager.getPlaySoundOnTradeNotification()) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarmSound != null) { builder.setSound(alarmSound); } } // Notify NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
private void nativeRingtone(Context context, boolean hasSound) { if (hasSound) { final AudioManager.OnAudioFocusChangeListener listener = this; final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(listener, AudioManager.STREAM_NOTIFICATION, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mRingtone = RingtoneManager.getRingtone(context, notification); mRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); mRingtone.play();// ww w.j a v a2 s . c o m final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { audioManager.abandonAudioFocus(listener); } }, AUDIO_FOCUS_DURATION); } } }