Example usage for android.media RingtoneManager getDefaultUri

List of usage examples for android.media RingtoneManager getDefaultUri

Introduction

In this page you can find the example usage for android.media RingtoneManager getDefaultUri.

Prototype

public static Uri getDefaultUri(int type) 

Source Link

Document

Returns the Uri for the default ringtone of a particular type.

Usage

From source file:com.ghosthawk.salard.GCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w  w w  . ja  va2  s.c  o m*/
 */

private void sendMessageNotification(String message, Message m) {
    Intent intent = new Intent(this, ChattingActivity.class);
    intent.putExtra(ChattingActivity.EXTRA_MESSAGE, m);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker("Salard ").setSmallIcon(R.drawable.rating_bar_full)
            .setContentTitle("Salard ? ?.").setContentText(message)
            .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.begentgroup.miniproject.gcm.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    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.mipmap.ic_launcher).setTicker("GCM Message").setContentTitle("GCM Message")
            .setContentText(message).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.sumang.chatdemo.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w w  w .ja  v a 2  s . co  m*/
private void sendNotification(String title, String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    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).setGroup("ABC")
            .setGroupSummary(true).setSmallIcon(R.drawable.messenger_bubble_small_white)
            .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

    notificationManager.notify(Util.createID() /* ID of notification */, notificationBuilder.build());
}

From source file:com.app.ntuc.notifs.MyGcmListenerService.java

private void sendNotifications(String messageBody) {
    Intent intent = new Intent(this, MainActivity2_.class);
    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.mipmap.ic_launcher).setContentTitle("KPMG").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.example.android.sunshine.app.fcm.SunshineFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//* w w w  . java  2 s  .  c o m*/
private void sendNotification(String messageBody, int weatherId) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    /*Bitmap largeIcon =
        BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);*/
    Bitmap largeIcon = Utility.getBitmapIconFromWeatherID(this, weatherId);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_b_w).setLargeIcon(largeIcon).setContentTitle("Sunshine Alert")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setPriority(NotificationCompat.PRIORITY_HIGH);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.enadein.carlogbook.db.CommonUtils.java

public static void createNotify(Context ctx, long id, int res) {
    Cursor c = ctx.getContentResolver().query(ProviderDescriptor.Notify.CONTENT_URI, null,
            BaseActivity.SELECTION_ID_FILTER, new String[] { String.valueOf(id) }, null);

    UnitFacade notifyUF = new UnitFacade(ctx);
    boolean vibrate = "1".equals(notifyUF.getSetting(UnitFacade.SET_NOTIFY_VIBRATE, "1"));

    boolean sound = "1".equals(notifyUF.getSetting(UnitFacade.SET_NOTIFY_SOUND, "1"));

    if (c == null) {
        return;//  www  .  ja v a2  s .c o  m
    }
    boolean hasItem = c.moveToFirst();

    if (!hasItem) {
        return;
    }

    int nameIdx = c.getColumnIndex(ProviderDescriptor.Notify.Cols.NAME);

    String name = c.getString(nameIdx);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx).setSmallIcon(res);
    if (sound) {
        mBuilder.setSound(alarmSound);
    }

    //      if (vibrate) {
    //         mBuilder.setVibrate(new long[] {1000, 500, 1000});
    //      }

    mBuilder.setContentTitle(ctx.getString(R.string.app_name)).setContentText(name);
    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Intent notifyIntent = new Intent(ctx, AddUpdateNotificationActivity.class);
    notifyIntent.putExtra(BaseActivity.MODE_KEY, BaseActivity.PARAM_EDIT);
    notifyIntent.putExtra(BaseActivity.ENTITY_ID, id);
    notifyIntent.putExtra(BaseActivity.NOTIFY_EXTRA, true);

    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
    stackBuilder.addParentStack(AddUpdateNotificationActivity.class);
    stackBuilder.addNextIntent(notifyIntent);

    PendingIntent notifyPendingIntent = PendingIntent.getActivity(ctx, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(notifyPendingIntent);
    mBuilder.setAutoCancel(true);

    mNotificationManager.notify((int) id, mBuilder.build());
}

From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java

/**
 * OnRecieve method that recieves calls form the AlertManager class and then applies some logic to fire notifications to the user.
 *
 * @param context//from ww w .j a va2  s  .  c o  m
 * @param intent
 */
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onRecieve");
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MedMinder");
    //Acquire the lock
    wl.acquire();

    dose = null;
    dose = (Dose) intent.getSerializableExtra(AlertManager.ALARMSTRING);
    Log.d(TAG,
            " This dose is " + dose.getMedication().getMedName() + "  " + dose.getDoseTime().toString(dtfTime));

    if (dose == null) {
        Log.d(TAG, "Alert object Extra is null");
    }

    //get the parent med
    Medication med = dose.getMedication();
    int alertCount = 0;
    for (DateTime doseDueDT : med.getDoseMap1().keySet()) {
        DateTime doseTakenDT = med.getDoseMap1().get(doseDueDT);
        if (doseDueDT.isBefore(new DateTime().now())
                && doseDueDT.isAfter(new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0))
                && doseTakenDT.equals(new DateTime(0))) {
            alertCount++;
        }
    }

    if (alertCount == 0) {
        return;
    }

    SharedPreferences sharedPref = context.getSharedPreferences("AlertCounter", 0);
    int alertCountPref = sharedPref.getInt(med.getMedName(), 0);
    SharedPreferences.Editor editor = sharedPref.edit();

    DateTime now = new DateTime().now();
    int notifID = dose.getMedication().getDbID();
    Random rand = new Random();
    //int notifID = rand.nextInt();
    Log.d(TAG, dose.getMedication().getDbID() + "   " + dose.getDoseTime().getMillisOfDay());

    if (dose.getTakenTime().toString(dtfDate).equals(new DateTime(0).toString(dtfDate))) {
        //            if ((dose.getDoseTime().getMillis() + alertMissedWindowArray[dose.getMedication().getFreq() - 1] * 2) > new DateTime().getMillis());
        String alertString = "You have " + alertCount + " missed doses for " + med.getMedName();
        if (alertCount == 1) {
            alertString = "You have a missed dose for " + med.getMedName();
        }

        //check if the dose is due +/- 15mins and advise that a dose is due.
        long diffMillis = dose.getDoseTime().getMillis() - new DateTime().now().getMillis();
        Log.d(TAG, diffMillis + "   dose time = " + dose.getDoseTime().getMillis() + " now= "
                + new DateTime().now().getMillis());
        boolean doseDue = Math.abs(diffMillis) < 1800000;
        if (doseDue) {
            alertString = dose.getMedication().getDose() + " of " + dose.getMedication().getMedName()
                    + " is due now.";
        }

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.medminder_icon).setContentTitle("MedMinder").setContentText(alertString);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
        // Creates an explicit intent for an Activity in your app
        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 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(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) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        // mId allows you to update the notification later on.
        mNotificationManager.notify(notifID, mBuilder.build());
        Log.d(TAG, " Notification sent " + notifID);
        //
        //
        //            editor.putInt(med.getMedName(), alertCount);
        //            editor.commit();

        //Release the lock
        wl.release();
    }
}

From source file:com.digitalborder.webappessentials.GCM.GcmIntentService.java

private void sendNotification(String title, String msg, String link) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("link", link);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(BitmapFactory.decodeResource(getBaseContext().getResources(), R.mipmap.ic_launcher))
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    // Set the notification vibrate option
    if (preferences.getBoolean("notifications_new_message_vibrate", true)) {
        mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    }/*from ww w .  ja va  2  s  . co  m*/
    // Set the notification ringtone
    if (preferences.getString("notifications_new_message_ringtone", null) != null) {
        mBuilder.setSound(Uri.parse(preferences.getString("notifications_new_message_ringtone", null)));
    } else {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
    }

    // Show only if the notification are enabled
    if (preferences.getBoolean("notifications_new_message", true)) {
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}

From source file:com.mattprecious.locnotifier.LocationService.java

private void approachingDestination() {
    Log.d(getClass().getSimpleName(), "Within distance to destination");

    locationManager.removeUpdates(locationListener);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);

    String notifTitle = getString(R.string.notification_alert_title);
    String notifText = getString(R.string.notification_alert_text);

    runningNotification = null;//from www .  j  ava2 s .co  m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.notification_alert).setContentTitle(notifTitle)
            .setContentText(notifText).setContentIntent(contentIntent).setAutoCancel(true);

    String tone = preferences.getString("tone", null);
    Uri toneUri = (tone == null) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
            : Uri.parse(tone);

    notificationBuilder.setSound(toneUri);

    if (preferences.getBoolean("vibrate", false)) {
        int shortVib = 150;
        int shortPause = 150;

        // vibrate 3 short times
        long[] pattern = { 0, shortVib, shortPause, shortVib, shortPause, shortVib, };

        notificationBuilder.setVibrate(pattern);
    }

    notificationBuilder.setLights(0xffff0000, 500, 500);

    Notification notification = notificationBuilder.getNotification();
    if (preferences.getBoolean("insistent", false)) {
        notification.flags |= Notification.FLAG_INSISTENT;
    }

    notificationManager.notify(0, notification);

    // send sms
    if (preferences.getBoolean("sms_enabled", false)) {
        String number = preferences.getString("sms_contact", null);
        String message = preferences.getString("sms_message", null);

        if (number != null && message != null) {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(number, null, message, null, null);
        }
    }

    stopSelf();
}

From source file:com.supremainc.biostar2.push.GcmBroadcastReceiver.java

private void commonBuilder(Builder builder, PendingIntent intent, String ticker) {
    long[] pattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500 };
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentIntent(intent);//from   www.j  a v a2 s  . c  om
    builder.setSound(alarmSound);
    builder.setLights(Color.BLUE, 500, 500);
    builder.setVibrate(pattern);
    //        builder.setTicker(ticker);
    builder.setAutoCancel(true);
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
}