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.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   w  ww. j  a  v  a  2s. c  o m
 */
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_notification).setContentTitle("Live Document Translator")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    //        int notificationCount = getSharedPreferences("Notification", MODE_PRIVATE).getInt("Count", 0);
    //        notificationCount ++;
    //        SharedPreferences.Editor editor = this.getSharedPreferences("Notification", MODE_PRIVATE).edit();
    //        editor.putInt("Count", notificationCount);
    //        editor.commit();
    //
    //        boolean success = ShortcutBadger.applyCount(getApplicationContext(), notificationCount);

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

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

From source file:com.lokesh.FCMNotification.plugin.MyFirebaseMessagingService.java

public void createNotification(Context context, RemoteMessage.Notification message) {
    saveNotificationOnSharedPreferences(message.getBody(), context);
    Intent intent = new Intent(this, FCMNotificationHandlerActivity.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(this.getApplicationInfo().icon).setContentTitle(message.getTitle())
            .setContentText(message.getBody()).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.attiqrao.systemsltd.list_to_do.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));

    // Get notification title from Reminder Database
    ReminderDatabase rb = new ReminderDatabase(context);
    Reminder reminder = rb.getReminder(mReceivedID);
    String mTitle = reminder.getTitle();

    // Create intent to open ReminderEditActivity on notification click
    Intent editIntent = new Intent(context, ReminderEditActivity.class);
    editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
    PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create Notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_icon))
            .setSmallIcon(R.mipmap.ic_icon).setContentTitle(context.getResources().getString(R.string.app_name))
            .setTicker(mTitle).setContentText(mTitle)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).setContentIntent(mClick)
            .setAutoCancel(true).setOnlyAlertOnce(true);

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(mReceivedID, mBuilder.build());
}

From source file:com.dnabuba.tacademy.abuband.GCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w w w.java  2 s .c o  m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, IntroActivity.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);
    //        Uri defaultSoundUri= RingtoneManager.getDefaultUri(R.raw.alert_sound);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.icon).setContentTitle("").setContentText(message)
            .setAutoCancel(true)
            //                .setVibrate(new long[]{1000, 1000, 1000})
            //                .setSound(defaultSoundUri)
            .setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);

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

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

From source file:com.example.gcmproject.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//www.java  2s. co m
 */
private void sendNotification(String message, String code) {
    Intent intent = null;
    if (code.equals("1")) { // ?   
        intent = new Intent(this, MainActivity.class); //  
    } else if (code.equals("2")) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(message)); //    ?  ?  message ? uri .
    }

    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("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:fr.bmartel.android.iotf.app.BaseActivity.java

protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);

    sharedpreferences = getSharedPreferences(StorageConst.STORAGE_PROFILE, Context.MODE_PRIVATE);

    notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    try {/* www.j av a  2 s  . c  o m*/
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);

    } catch (Exception e) {
        e.printStackTrace();
        ringtone = null;
    }

    screenLock = ((PowerManager) getSystemService(POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
}

From source file:com.twilio.android.quickstart.MyFcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  ww  w  .j a v  a2s .c  o m*/
 */
private void sendNotification(String pTitle, 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);

    String title = "FCM Message";

    if (pTitle != null) {
        title = pTitle;
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle(title).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.luan.thermospy.android.core.NotificationHandler.java

private NotificationCompat.Builder createBuilder(Context c, String temperature, boolean playSound) {
    String text = "Current temperature is " + temperature;

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true).setContentTitle("Thermospy")
            .setContentText(text).setOnlyAlertOnce(false)
            .setSmallIcon(R.drawable.ic_stat_action_assignment_late);

    Uri alarmSound = null;//from   ww w.  j  av  a  2 s  . c  om
    if (playSound) {
        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    }

    mBuilder.setSound(alarmSound);

    Intent resultIntent = new Intent(c, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(c);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    return mBuilder;
}

From source file:com.leo.cattle.presentation.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* ww w  .j a v a 2s .  c  o  m*/
 */
private void sendNotification(Bundle bundle) {
    String message = bundle.getString("message");
    Intent intent = new Intent(this, SignInActivity.class);
    Bundle b = new Bundle();
    //b.putString("username", AndroidApplication.sessionUser.getFullName());
    b.putString("to", bundle.getString("username"));
    b.putString("session_id", bundle.getString("chatSessionId"));
    b.putString("type", bundle.getString("type"));
    intent.putExtras(b);
    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_whats_hot).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.teamappjobs.appjobs.FCM.MyFirebaseMessagingService.java

/**
 * Create and show notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//* w w w. ja  va 2  s.  c om*/
private void onNovaPromocao(String messageBody) {
    VitrineJson vitrineJson = new VitrineJson();
    Promocao promocao = vitrineJson.JsonToPromocao(messageBody);

    //  Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("From", "notifyFragSigo");

    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);
    long[] v = { 100, 500, 100, 500 }; //Vibrao
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

            .setSmallIcon(R.drawable.heart_notif).setContentTitle(promocao.getNome())
            .setContentText(promocao.getDescricao()).setAutoCancel(true).setSound(defaultSoundUri).setVibrate(v)
            .setContentIntent(pendingIntent);

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

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