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.kratav.tinySurprise.notification.MyGcmListenerService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification notificationType2() {
    Bitmap smallIconBitmap = getMeBitmap(smallIcon);
    if (smallIconBitmap == null)
        return null;

    // Constructs the Builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setTicker(title).setSubText(subtitle).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(smallIconBitmap).setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMsg))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    builder.setContentIntent(pendingIntent);
    return builder.build();
}

From source file:com.tessoft.nearhere.GcmIntentService.java

private void sendNotification(Bundle extras) {

    String title = extras.getString("title");
    String type = extras.getString("type");
    String msg = extras.getString("message");

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);//from  w w w . j av a2s  . co m

    Intent intent = null;

    boolean isActive = false;

    // check if background
    //        ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
    //        List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
    //        for(int i = 0; i < procInfos.size(); i++)
    //        {
    //            if(procInfos.get(i).processName.equals("com.tessoft.nearhere")) 
    //               isActive = true;
    //        }

    // check if foreground
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);

    if (services.get(0).topActivity.getPackageName().toString()
            .equalsIgnoreCase(getApplicationContext().getPackageName().toString())) {
        isActive = true;
    }

    if (isActive) {
        intent = new Intent("updateUnreadCount");
        intent.putExtra("type", type);
        if ("message".equals(type)) {
            intent.putExtra("fromUserID", extras.getString("fromUserID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        } else if ("postReply".equals(type)) {
            intent.putExtra("postID", extras.getString("postID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        }

        getApplicationContext().sendBroadcast(intent);
    } else {
        if ("message".equals(type)) {
            intent = new Intent(this, UserMessageActivity.class);
            HashMap hash = new HashMap();
            hash.put("fromUserID", extras.getString("fromUserID"));
            hash.put("userID", extras.getString("toUserID"));
            intent.putExtra("messageInfo", hash);
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("postReply".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("newPostByDistance".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
        } else if ("event".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else if ("eventssl".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));
            intent.putExtra("ssl", "true");

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else {
            intent = new Intent(this, MainActivity.class);
        }

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}

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

private void sendNotification(String message) {
    Intent intent = new Intent(this, SellHomeActivity.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)
            .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.whereismyfriend.GcmIntentService.java

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

    int notification_id;
    PendingIntent contentIntent;//from ww w.j a  va 2s  .co m
    if (type.compareTo("s") == 0) {
        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Solicitudes.class), 0);
        notification_id = 0;
    } else {
        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Mapa.class), 0);
        notification_id = 1;
    }

    if (Integer.parseInt(badge) > 1) {
        if (type.compareTo("s") == 0)
            msg = getResources().getString(R.string.push_no_leidas_1) + " " + badge + " "
                    + getResources().getString(R.string.push_no_leidas_2);
        else
            msg = getResources().getString(R.string.push_no_leidas_1_acc) + " " + badge + " "
                    + getResources().getString(R.string.push_no_leidas_2_acc);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    }

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(notification_id, mBuilder.build());
}

From source file:com.getmarco.weatherstationviewer.gcm.StationGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   www  .  j av  a 2 s  .  c o  m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, StationListActivity.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("Station update").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.lovespectre.lwin.message.services.IMService.java

/**
 * Show a notification while this service is running.
 *
 * @param msg/*from   w  w  w.  j av  a  2  s.co m*/
 */
private void showNotification(String username, String msg) {
    // Set the icon, scrolling text and TIMESTAMP
    String title = "AndroidIM: You got a new Message! (" + username + ")";

    String text = username + ": " + ((msg.length() < 5) ? msg : msg.substring(0, 5) + "...");

    //NotificationCompat.Builder notification = new NotificationCompat.Builder(R.drawable.stat_sample, title,System.currentTimeMillis());
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_message_black_24dp).setContentTitle(title).setContentText(text)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    Intent i = new Intent(this, Messaging.class);
    i.putExtra(FriendInfo.USERNAME, username);
    i.putExtra(MessageInfo.MESSAGETEXT, msg);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    // Set the info for the views that show in the notification panel.
    // msg.length()>15 ? MSG : msg.substring(0, 15);
    mBuilder.setContentIntent(contentIntent);

    mBuilder.setContentText("New message from " + username + ": " + msg);

    //TODO: it can be improved, for instance message coming from same user may be concatenated
    // next version

    // Send the notification.
    // We use a layout id because it is a unique number.  We use it later to cancel.
    mNM.notify((username + msg).hashCode(), mBuilder.build());
}

From source file:com.poguico.palmabici.network.synchronizer.NetworkStationAlarm.java

public void showNotification(Station station) {
    SharedPreferences mPrefs;//  w w w  .  jav a 2  s. co m
    SharedPreferences.Editor edit;
    String message = Formatter.formatBikesAvailableMessage(context, station);
    Bitmap bigIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.palmabici_bw);
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK),
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.bike)
            .setLargeIcon(bigIcon).setContentTitle("PalmaBici").setContentText(message)
            .setLights(0x0000ff00, 1000, 1000).setTicker(message).setSound(uri).setAutoCancel(true);

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mBuilder.setContentIntent(pendingIntent);

    mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    edit = mPrefs.edit();
    edit.putInt(PREFS_SHOWN_STATION, station.getId());
    edit.commit();

    mgr.notify(0, mBuilder.build());
}

From source file:com.popdeem.sdk.core.gcm.GCMIntentService.java

private void sendNotification(String title, String message, PendingIntent pendingIntent, int id) {
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_pd_notification).setContentTitle(title).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, notificationBuilder.build());
}

From source file:com.preguardia.app.notification.MyGcmListenerService.java

private void showMessageNewNotification(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.GENERAL_NEW_MESSAGE_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(Constants.NOTIFICATION_NEW_MESSAGE_ID, notificationBuilder.build());
}

From source file:app.androidhive.info.realm.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("phone", link);//from w w  w .j a  va  2 s  . com
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);*/

    Phone = link;

    //   getData(link);

    Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class);
    dialogIntent.putExtra("Phone", link);
    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplication().startActivity(dialogIntent);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(BitmapFactory.decodeResource(getBaseContext().getResources(), R.mipmap.ic_launcher))
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(link).setAutoCancel(true)
            .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 });
    }
    // 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());
    }

}