List of usage examples for android.media Ringtone play
public void play()
From source file:com.memetro.android.notifications.GcmBroadcastReceiver.java
private void sendNotification(String msg, Intent intent, Context context) { mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent newIntent = new Intent(context, SplashScreenActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, newIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.icon_push).setContentTitle("Memetro") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true) .setContentText(msg);/* w ww.j a v a 2 s. co m*/ mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.droidanalyst.app.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_hamburger).setContentTitle("Server Prediction") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:es.reprogramador.util.notificationHelper.java
/** * Play the default "ding" sound//from w w w . j av a2 s. c o m */ private void playNotificationSound() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(_context.getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.abel.ooti.boss.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();//from w w w. j a v a 2 s . c om GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:org.getlantern.firetweet.preference.RingtonePreference.java
@Override protected void onPrepareDialogBuilder(final Builder builder) { loadRingtones(getContext());//ww w. jav a2 s.co m setSelectedItem(ArrayUtils.indexOf(mValues, getPersistedString(null))); builder.setSingleChoiceItems(getEntries(), getSelectedItem(), new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { setSelectedItem(which); final Ringtone ringtone = getSelectedRingtone(); if (ringtone.isPlaying()) { ringtone.stop(); } ringtone.play(); } }); }
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 a va2 s.c om }
From source file:random.taiga.chat.truelecter.randomchat.ChatActivity.java
/** * Plays device's default notification sound *///from w ww.ja va2s. c o m public void playBeep() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.shivshankar.MyFirebaseMessagingService.java
private void sendNotification(String strTitle, String strMsg) { Log.d("TAGRK", "Preparing to send notification...: " + strTitle + " Msg: " + strMsg); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Intent intent;//from w ww . j a v a 2s. c om if (AppPreferences.getPrefs().getBoolean(commonVariables.KEY_IS_SELLER, false)) intent = new Intent(this, MainActivitySeller.class); else intent = new Intent(this, MainActivityBuyer.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); int requestID = (int) System.currentTimeMillis(); PendingIntent contentIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this, requestID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentTitle(strTitle) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setStyle(new NotificationCompat.BigTextStyle().bigText(strMsg)).setContentText(strMsg) .setPriority(NotificationCompat.PRIORITY_MAX).setWhen(0).setVibrate(new long[] { 100, 100, 0, 0 }); mBuilder.setSmallIcon(R.drawable.ic_noti_fcm); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } mBuilder.setAutoCancel(true); if (!strMsg.contains("Your OTP is")) mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID++, mBuilder.build()); Log.d("TAGRK", "Notification sent successfully."); }
From source file:nl.johndekroon.dma.GCMIntentService.java
@Override protected void onMessage(Context context, Intent intent) { prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.getBoolean("muteAll", false); String data = intent.getStringExtra("message"); JSONObject datajson;//from w w w. ja v a 2s .co m try { datajson = new JSONObject(data); String message = datajson.get("message").toString(); String type = datajson.get("type").toString(); String monitor = datajson.get("monitor").toString(); DatabaseDAO datasource = new DatabaseDAO(this); datasource.open(); //On getting a warning or an OK if (type.equals("WARNING") || type.equals("OK")) { if (prefs.getBoolean("muteAll", false) != true) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase // alert backup is null, using 2nd backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on receiving an error else if (type.equals("ERROR")) { System.out.println("bbbrrrrrrr brrrrrr"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 1000, 50, 200, 50, 200, 50, 1200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); if (prefs.getBoolean("muteAll", false) != true) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on register, make a new scenario. else if (type.equals("REGISTER")) { datasource.createScenario(monitor); } System.out.println(intent.getStringExtra("message")); Log.i(TAG, "Received message"); //No idea why this part isn't working. It should. // if(type.equals("ERROR")) // { // displayMessage(context, message, "error"); // } // else // { displayMessage(context, message); // } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:edu.asu.cse535.assignment3.MainActivity.java
public void notifyCompletion() { try {// w w w . j a v a 2s. c o m Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }