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.webonise.gardenIt.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w w  w. ja  v a  2 s. c o  m*/
 */
private void sendNotification(String id, String type, String message) {
    Intent intent = new Intent(this, GeneralDetailsActivity.class);
    if (type.equalsIgnoreCase(getString(R.string.notification_type_issue))) {
        intent.putExtra(Constants.BUNDLE_KEY_TYPE, Constants.TYPE_ADVICE);
    } else if (type.equalsIgnoreCase(getString(R.string.notification_type_request))) {
        intent.putExtra(Constants.BUNDLE_KEY_TYPE, Constants.TYPE_SERVICE);
    }
    intent.putExtra(Constants.BUNDLE_KEY_ID, Integer.parseInt(id));
    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_notification).setLargeIcon(getBitmapDrawable())
            .setContentTitle(getString(R.string.app_name)).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.nghianh.giaitriviet.util.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param remoteMessage FCM remoteMessage
 *///w  w  w . j a v  a2 s .com
private void sendNotification(RemoteMessage remoteMessage) {
    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 imageUri = remoteMessage.getData().get("image");
    String message = remoteMessage.getData().get("message");
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(getBitmapfromUrl(imageUri)).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(remoteMessage.getNotification().getTitle()).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.kr.zenithcompany.MyGcmListenerService.java

private void sendNotification(String message, Bitmap bitmap) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    if (bitmap != null) {
        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
        style.setBigContentTitle(getString(R.string.app_name));
        style.setSummaryText(message);//w w  w.  jav  a  2 s .  com
        style.bigPicture(bitmap);
        notificationBuilder.setStyle(style);
    }

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

    notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build());
}

From source file:com.UpTopApps.OilResetPro.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///w ww. j  av a 2s  .  c  o m
private void sendNotification(String messageBody, String title) {
    Intent intent = new Intent(this, NotificationActivity.class);
    String text = "";
    try {

        JSONObject obj = new JSONObject(messageBody);

        text = obj.getString("text");

    } catch (JSONException e) {
        Log.d("jex", e.getMessage());
    }
    intent.putExtra("body", text);
    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_stat_ic_notification).setContentTitle(title).setContentText(text)
            .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.echopf.ECHOFcmListenerService.java

/**
 * Sets notification layouts.//from  www.j av a 2 s .  c o m
 * @param data 
 * @return NotificationCompat.Builder
 */
public NotificationCompat.Builder getNotificationBuilder(Bundle data) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setAutoCancel(true);

    // get ApplicationInfo
    ApplicationInfo appInfo = null;
    String appName = null;
    try {
        appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        appName = getPackageManager()
                .getApplicationLabel(getPackageManager().getApplicationInfo(getPackageName(), 0)).toString();
    } catch (NameNotFoundException e) {
        throw new RuntimeException(e);
    }

    // set title
    String title = (data.getString("title") != null) ? data.getString("title") : appName;
    notificationBuilder.setContentTitle(title);

    // set message
    if (data.getString("message") != null)
        notificationBuilder.setContentText(data.getString("message"));

    // set icon
    int manifestIco = appInfo.metaData.getInt(NOTIFICATION_ICON_KEY);
    int icon = (manifestIco != 0) ? manifestIco : appInfo.icon;
    notificationBuilder.setSmallIcon(icon);

    // set sound
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationBuilder.setSound(defaultSoundUri);

    // set content intent
    String activity = appInfo.metaData.getString(PUSH_OPEN_ACTIVITY_KEY);
    if (activity != null) {

        try {
            Intent intent = new Intent(this, Class.forName(activity)).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                    .setComponent(new ComponentName(appInfo.packageName, activity)).putExtras(data);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            notificationBuilder.setContentIntent(pendingIntent);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

    return notificationBuilder;
}

From source file:com.meiste.tempalarm.ui.Alarm.java

@Override
protected void onResume() {
    super.onResume();

    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // do not play alarms if stream volume is 0 (typically because ringer mode is silent).
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
        final Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(final MediaPlayer mp, final int what, final int extra) {
                Timber.e("Error occurred while playing audio.");
                mp.stop();//  w  ww.j ava 2 s .c  o  m
                mp.reset();
                mp.release();
                mMediaPlayer = null;
                return true;
            }
        });
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        try {
            mMediaPlayer.setDataSource(this, alert);
            mMediaPlayer.setLooping(true);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        } catch (final IOException e) {
            Timber.e("Failed to play alarm tone: %s", e);
        }
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mVibrator.vibrate(sVibratePattern, 0);

    mPlaying = true;
    mHandler.sendEmptyMessageDelayed(KILLER, ALARM_TIMEOUT);
}

From source file:com.yj.wangjatv.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM message received.// w  ww .ja v a  2 s  .co  m
 */
private void sendNotification(Bundle data) {
    Intent intent = new Intent(this, IntroActivity.class);
    intent.putExtra("data", data);
    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(getString(R.string.app_name))
            .setContentText(data.getString("msg")).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.afrolkin.samplepushclient.GCMIntentService.java

private static void generateNotification(Context context, String message) {
    int icon = R.mipmap.ic_announcement_black_48dp;
    long when = System.currentTimeMillis();
    String title = context.getString(R.string.app_name);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, "Push Message", when);
    notification.sound = soundUri;/*  ww  w.  ja  v  a 2 s .  c  om*/

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message", message);
    // Set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.iovirta.iot_kamera_sovellus.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*  w  w w  .ja v  a  2  s  .  c  o  m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, mediaView.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.drawable.ic_stat_ic_notification).setContentTitle("Iot Cam Demo")
            .setContentText("Liikett havaittu!").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.android.talkbacktests.testsession.NotificationTest.java

private void showTickerNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(android.R.drawable.stat_notify_more).setAutoCancel(true)
            .setContentTitle(getString(R.string.ticker_notification_title))
            .setContentText(getString(R.string.ticker_notification_text))
            .setTicker(getString(R.string.ticker_notification_ticker))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build());
}