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.schantz.mydls.activity.registration.MyGcmListenerService.java

/**
 * Called when message is received.//w ww. ja  v  a  2  s  . c  o m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    String policyId = data.getString("policyId");
    String documentId = data.getString("documentId");

    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);
    Log.d(TAG, "PolicyId: " + policyId);
    Log.d(TAG, "documentId: " + documentId);

    Intent intent = new Intent(this, DocumentActivity.class);
    intent.putExtra("documentId", documentId);
    intent.putExtra("policyId", policyId);
    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)
            .setSmallIcon(R.drawable.schantz_logo).setContentTitle("Document received").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.example.rasel.firstfirebaseproject.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param remoteMessage FCM RemoteMessage received.
 */// w  w w.j a v a 2  s.  c o m
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);

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

    // this is a my insertion looking for a solution
    int icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.clkbtn : R.mipmap.ic_launcher;
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon)
            .setContentTitle(remoteMessage.getFrom()).setContentText(remoteMessage.getNotification().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.awt.supark.ParkingTimerService.java

public void onCreate() {
    super.onCreate();
    Log.i("Service", "---------- Service created ----------");

    notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
    soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}

From source file:com.pimp.instincts.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
        Log.e("FCM", "Message data payload: " + remoteMessage.getData());
    }//from   ww w  . j  a v a 2 s  . c  om

    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("google.sent_time", remoteMessage.getSentTime());
    intent.putExtra("from", remoteMessage.getFrom());
    intent.putExtra("google.message_id", remoteMessage.getMessageId());
    intent.putExtra("collapse_key", remoteMessage.getCollapseKey());
    for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
        intent.putExtra(entry.getKey(), entry.getValue());
    }
    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)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setColor(Color.parseColor(remoteMessage.getData().get("color")))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getData().get("content")))
            .setContentTitle(remoteMessage.getData().get("title"))
            .setContentText(remoteMessage.getData().get("content"))
            .setTicker(remoteMessage.getData().get("content")).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.miappgcm.appfactory.MiGcmListenerService.java

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

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

    int idNotificacion = 1;
    notificationManager.notify(1, notificationBuilder.build());
}

From source file:com.lumi_dos.lge.MyGcmListenerService.java

private void sendNotification(Bundle data) {
    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 = data.getString("title");
    String body = data.getString("body");
    Context context = this;
    Bitmap large_icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.launcher);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.launcher).setLargeIcon(large_icon).setContentTitle(title)
            .setContentText(body).setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent)
            .setPriority(NotificationCompat.PRIORITY_HIGH);

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

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

From source file:com.andrewchelladurai.simplebible.utilities.NotificationDisplayer.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive: called");
    long when = System.currentTimeMillis();
    int MID = (int) when;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notIntent = new Intent(context, SimpleBibleActivity.class);
    notIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification_small_icon)
            .setContentTitle(context.getString(R.string.application_name))
            .setContentText(context.getString(R.string.notification_text)).setSound(alarmSound)
            .setAutoCancel(true).setWhen(when).setContentIntent(pendingIntent);

    notificationManager.notify(MID, builder.build());
    Log.d(TAG, "onReceive: reminder Created");
}

From source file:com.vncreatures.customItems.wakefulservice.AppService.java

private void updateNotification() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String userId = pref.getString(Common.USER_ID, null);
    HrmService service = new HrmService();
    if (userId != null) {
        service.requestGetNotification(userId);
        service.setCallback(new ThreadTaskCallback() {

            @Override//from  w ww. j  a v  a2s.  com
            public void onSuccess(ThreadModel threadModel) {
                int count = threadModel.countAllNotification();
                if (count > 0) {
                    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    if (alarmSound == null) {
                        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
                        if (alarmSound == null) {
                            alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
                        }
                    }

                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                            getApplicationContext()).setSmallIcon(R.drawable.vnc_icon)
                                    .setContentTitle(getString(R.string.app_name))
                                    .setContentText(getString(R.string.notification_overall, count))
                                    .setSound(alarmSound).setAutoCancel(true);
                    // Creates an explicit intent for an Activity in your
                    // app
                    Intent resultIntent = new Intent(getApplicationContext(), LoginActivity.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(getApplicationContext());
                    // Adds the back stack for the Intent (but not the
                    // Intent
                    // itself)
                    stackBuilder.addParentStack(LoginActivity.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) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    // mId allows you to update the notification later on.
                    mNotificationManager.notify(Common.COMMON_ID, mBuilder.build());
                }
            }

            @Override
            public void onError() {

            }
        });
    }
}

From source file:com.demo.instantpush.gcm.MyGcmListenerService.java

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

private void sendNotification(String message) {
    Intent intent = new Intent(this, RequestActivity.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)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.example.paul.greenpooling11.MyFirebaseMessagingService.java

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, TripRequestPage.class);
    intent.putExtra("tripId", tripId);
    intent.putExtra("passengerId", passengerId);
    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)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Trip Request").setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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