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.cityfreqs.littlesirecho.MainActivity.java

private void initLittleSirEcho() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(LISTENER_STRING);/*from w ww  . j av a2  s.  c  om*/
    LSEsr = new LSEServiceReceiver();

    LocalBroadcastManager.getInstance(this).registerReceiver(LSEsr, new IntentFilter(LISTENER_STRING));
    soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    setAwakeView();
    startHourPicker = (NumberPicker) findViewById(R.id.start_hour_picker);
    startHourPicker.setMinValue(0);
    startHourPicker.setMaxValue(11);
    startHourPicker.setValue(DEFAULT_AWAKE_START);
    startHourPicker.setWrapSelectorWheel(false);
    // stop numpad auto appearing
    startHourPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    // set listener here instead of implementing at activity level
    startHourPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            if (picker == startHourPicker) {
                if (newVal != userAwakeStart) {
                    userAwakeStart = newVal;
                    setAwakeView();
                }
            }
        }
    });

    endHourPicker = (NumberPicker) findViewById(R.id.end_hour_picker);
    endHourPicker.setMinValue(12);
    endHourPicker.setMaxValue(23);
    endHourPicker.setValue(DEFAULT_AWAKE_END);
    endHourPicker.setWrapSelectorWheel(false);
    // stop numpad auto appearing
    endHourPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    // set listener here instead of implementing at activity level
    endHourPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            if (picker == endHourPicker) {
                if (newVal != userAwakeEnd) {
                    userAwakeEnd = newVal;
                    setAwakeView();
                }
            }
        }
    });
}

From source file:cl.telematica.android.alimentame.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *//*from  ww  w.ja  v  a2s  .  com*/
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails)
            .setContentText(getString(R.string.geofence_transition_notification_text))
            .setVibrate(new long[] { 100, 250, 100, 500 })
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.aylanetworks.aura.GcmIntentService.java

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

    // Find the launcher class for our application
    PackageManager pm = getPackageManager();
    String packageName = getPackageName();
    Intent query = new Intent(Intent.ACTION_MAIN);
    Class launcherClass = null;//www  .  j  av  a 2  s .c  o  m
    query.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> foundIntents = pm.queryIntentActivities(query, 0);
    for (ResolveInfo info : foundIntents) {
        if (TextUtils.equals(info.activityInfo.packageName, packageName)) {
            launcherClass = info.activityInfo.getClass();
        }
    }

    if (launcherClass == null) {
        Log.e(TAG, "Could not find application launcher class");
        return;
    }

    Intent appIntent = new Intent(this, launcherClass); // main activity of Ayla Control/aMCA
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, appIntent, 0);

    //Determine the sound to be played
    Uri soundUri = null;
    if (sound == null) {
        // NOP
        //PushNotification.playSound("bdth.mp3");
    } else if (sound.equals("none")) {
        // NOP
    } else if (sound.equals("default")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
    } else if (sound.equals("alarm")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // TYPE_NOTIFICATION or TYPE_ALARM
    } else {
        boolean playedSound;
        playedSound = PushNotification.playSound(sound);
        if (playedSound == false) {
            soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
        }
    }

    // @formatter:off
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            //.setSound(soundUri)
            .setSmallIcon(R.drawable.ic_push_icon).setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFFff0000, 500, 500) // flashing red light
            .setContentText(msg).setAutoCancel(true)
            //.setPriority(Notification.FLAG_HIGH_PRIORITY)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS);
    // @formatter:on

    if (soundUri != null) {
        mBuilder.setSound(soundUri);
    }
    mBuilder.setPriority(PRIORITY_MAX);
    mBuilder.setContentIntent(contentIntent);

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

From source file:com.pulp.campaigntracker.gcm.GcmIntentService.java

@SuppressWarnings("unchecked")
private void sendNotification(GCM msg) {

    if (msg != null) {

        int index = 1;

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

        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(msg.getMessage());
        bigText.setBigContentTitle(msg.getTitle());

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

        mNotificationCount = mAppPref.getInt("Notif_Number_Constant", 0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notification_app_icon).setContentTitle(msg.getTitle())
                .setStyle(bigText).setContentText(msg.getMessage()).setSound(uri)
                .setNumber(mNotificationCount + 1);

        mAppPref.edit().putInt("Notif_Number_Constant", (mNotificationCount + 1)).commit();

        try {/*from   w w w  .ja  v  a2s .  c  o m*/
            if ((ArrayList<UserNotification>) ObjectSerializer
                    .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, "")) == null) {
                notifyList = new ArrayList<UserNotification>();
            } else {
                notifyList = (ArrayList<UserNotification>) ObjectSerializer
                        .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, ""));
            }
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        notification = new UserNotification();
        notification.setTitle(msg.getTitle());
        notification.setMessage(msg.getMessage());
        notification.setNotifyTime(System.currentTimeMillis());
        notifyList.add(notification);

        try {
            mAppPref.edit().putString(ConstantUtils.NOTIFICATION, ObjectSerializer.serialize(notifyList))
                    .commit();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Intent newIntent = null;

        ConstantUtils.SYNC_INTERVAL = 30 * 60 * 1000;

        //         if (mAppPref.getString(ConstantUtils.USER_ROLE, "")
        //               .equals(LoginData.)) {
        //            newIntent = new Intent(getBaseContext(),
        //                  UserMotherActivity.class);
        //            Intent i = new Intent(this, PeriodicService.class);
        //            this.startService(i);

        //         } else {
        newIntent = new Intent(getBaseContext(), SplashScreen.class);
        Intent i = new Intent(this, PeriodicService.class);
        this.startService(i);

        //         }

        PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, 0, newIntent, 0);
        mBuilder.setAutoCancel(true);
        mBuilder.setContentIntent(contentIntent);

        mNotificationManager.notify(index, mBuilder.build());
        Intent intent = new Intent();
        intent.setAction("googleCloudMessage");
        sendBroadcast(intent);

    }
}

From source file:jahirfiquitiva.iconshowcase.services.NotificationsService.java

@SuppressWarnings("ResourceAsColor")
private void pushNotification(String content, int type, int ID) {

    Preferences mPrefs = new Preferences(this);

    String appName = Utils.getStringFromResources(this, R.string.app_name);

    String title = appName, notifContent = null;

    switch (type) {
    case 1://from w  w  w  .  j a  v  a 2s  . c o  m
        title = getResources().getString(R.string.new_walls_notif_title, appName);
        notifContent = getResources().getString(R.string.new_walls_notif_content, content);
        break;
    case 2:
        title = appName + " " + getResources().getString(R.string.news).toLowerCase();
        notifContent = content;
        break;
    }

    // Send Notification
    NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
    notifBuilder.setAutoCancel(true);
    notifBuilder.setContentTitle(title);
    if (notifContent != null) {
        notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notifContent));
        notifBuilder.setContentText(notifContent);
    }
    notifBuilder.setTicker(title);
    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notifBuilder.setSound(ringtoneUri);

    if (mPrefs.getNotifsVibrationEnabled()) {
        notifBuilder.setVibrate(new long[] { 500, 500 });
    } else {
        notifBuilder.setVibrate(null);
    }

    int ledColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.dark_theme_accent)
            : ContextCompat.getColor(this, R.color.light_theme_accent);

    notifBuilder.setColor(ledColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notifBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    Class appLauncherActivity = getLauncherClass(getApplicationContext());

    if (appLauncherActivity != null) {
        Intent appIntent = new Intent(this, appLauncherActivity);
        appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        appIntent.putExtra("notifType", type);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(appLauncherActivity);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(appIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        notifBuilder.setContentIntent(resultPendingIntent);
    }

    notifBuilder.setOngoing(false);

    notifBuilder.setSmallIcon(R.drawable.ic_notifications);

    Notification notif = notifBuilder.build();

    if (mPrefs.getNotifsLedEnabled()) {
        notif.ledARGB = ledColor;
    }

    notifManager.notify(ID, notif);
}

From source file:com.gcmandroid_uniqueid1010.nemo.NirapodNouvromon.gcm.MyGcmPushReceiver.java

private void sendNotification(String message, String title) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = 0;

    int icon = this.getResources().getIdentifier("app_icon", "drawable", this.getPackageName());

    if (alertClass_global.getIs_resolved() == 1) {
        icon = this.getResources().getIdentifier("danger", "drawable", this.getPackageName());
    }//from  ww w .j  ava  2  s .  co m
    if (alertClass_global.getIs_resolved() == 2) {
        icon = this.getResources().getIdentifier("relax", "drawable", this.getPackageName());
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
            //  .setSmallIcon(R.mipmap.ic_launcher)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message).setAutoCancel(true)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
}

From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyAnnouncement(String announcement) {
    Intent contentIntent = new Intent(this, MainActivity.class);
    contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS);
    contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, SettingsActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

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

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(announcement);//from   w  w  w .j av  a  2 s.  com
    notifStyle.setBigContentTitle(getString(R.string.notif_announcement_title));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_announcement_title)).setContentText(announcement)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off,
                    getString(R.string.notif_action_options), settingsPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(NOTIFICATION_ID_ANNOUNCEMENT, notificationBuilder.build());
}

From source file:com.sourceauditor.sahomemonitor.GcmIntentService.java

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

    Intent notifyMainIntent = buildIntentForMainActifity(extras);

    // Figure out how to add extras for the URL and message
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyMainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.home_small).setContentTitle("Home Monitor Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setExtras(extras).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mBuilder.setPriority(Notification.PRIORITY_MAX);
    mBuilder.setLights(0xFF0000, 500, 500);
    long[] pattern = new long[] { 0, 500, 0, 500, 0, 500, 0, 500, 0, 500 };
    mBuilder.setVibrate(pattern);/*  ww w . j  ava2 s .c o  m*/
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(soundUri);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.magnet.mmx.client.MMXWakeupIntentService.java

private void invokeNotificationForPush(GCMPayload payload) {
    // Launch the activity with action=MAIN, category=DEFAULT.  Make sure that
    // it has DEFAULT category declared in AndroidManifest.xml intent-filter.
    PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0,
            new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName())
                    .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED),
            PendingIntent.FLAG_UPDATE_CURRENT);
    // If title is not specified, use the app name (compatible with iOS push notification)
    String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle();
    Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent)
            .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title)
            .setContentText(payload.getBody());
    if (payload.getSound() != null) {
        // TODO: cannot handle custom sound yet; use notification ring tone.
        noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }//  w  w w. j  a va 2  s  . com
    if (payload.getIcon() != null) {
        noteBuilder.setSmallIcon(
                this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName()));
    } else {
        noteBuilder.setSmallIcon(this.getApplicationInfo().icon);
    }
    if (payload.getBadge() != null) {
        noteBuilder.setNumber(payload.getBadge());
    }
    NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    noteMgr.notify(sNoteId++, noteBuilder.build());
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private void playNotificationSound(Context context) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        Ringtone rt = RingtoneManager.getRingtone(context, uri);
        if (rt != null)
            rt.play();// w w  w.  j  a v  a 2  s .c o  m
    }
}