Example usage for android.media RingtoneManager TYPE_NOTIFICATION

List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION

Introduction

In this page you can find the example usage for android.media RingtoneManager TYPE_NOTIFICATION.

Prototype

int TYPE_NOTIFICATION

To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.

Click Source Link

Document

Type that refers to sounds that are used for notifications.

Usage

From source file:com.Beat.RingdroidEditActivity.java

private void afterSavingRingtone(CharSequence title, String outPath, File outFile, int duration) {
    long length = outFile.length();
    if (length <= 512) {
        outFile.delete();/*  www . ja va 2s.  c  om*/
        new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure)
                .setMessage(R.string.too_small_error).setPositiveButton(R.string.alert_ok_button, null)
                .setCancelable(false).show();
        return;
    }

    // Create the database record, pointing to the existing file path

    long fileSize = outFile.length();
    String mimeType = "audio/mpeg";

    String artist = "" + getResources().getText(R.string.artist_name);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, outPath);
    values.put(MediaStore.MediaColumns.TITLE, title.toString());
    values.put(MediaStore.MediaColumns.SIZE, fileSize);
    values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);

    values.put(MediaStore.Audio.Media.ARTIST, artist);
    values.put(MediaStore.Audio.Media.DURATION, duration);

    values.put(MediaStore.Audio.Media.IS_RINGTONE, mNewFileKind == FileSaveDialog.FILE_KIND_RINGTONE);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION);
    values.put(MediaStore.Audio.Media.IS_ALARM, mNewFileKind == FileSaveDialog.FILE_KIND_ALARM);
    values.put(MediaStore.Audio.Media.IS_MUSIC, mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC);

    // Insert it into the database
    Uri uri = MediaStore.Audio.Media.getContentUriForPath(outPath);
    final Uri newUri = getContentResolver().insert(uri, values);
    setResult(RESULT_OK, new Intent().setData(newUri));

    // Update a preference that counts how many times we've
    // successfully saved a ringtone or other audio
    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(PREF_SUCCESS_COUNT, successCount + 1);
    prefsEditor.commit();

    // If Ringdroid was launched to get content, just return
    if (mWasGetContentIntent) {
        sendStatsToServerIfAllowedAndFinish();
        return;
    }

    // There's nothing more to do with music or an alarm.  Show a
    // success message and then quit.
    if (mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC || mNewFileKind == FileSaveDialog.FILE_KIND_ALARM) {
        Toast.makeText(this, R.string.save_success_message, Toast.LENGTH_SHORT).show();
        sendStatsToServerIfAllowedAndFinish();
        return;
    }

    // If it's a notification, give the user the option of making
    // this their default notification.  If they say no, we're finished.
    if (mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION) {
        new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_success)
                .setMessage(R.string.set_default_notification)
                .setPositiveButton(R.string.alert_yes_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this,
                                RingtoneManager.TYPE_NOTIFICATION, newUri);
                        sendStatsToServerIfAllowedAndFinish();
                    }
                }).setNegativeButton(R.string.alert_no_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        sendStatsToServerIfAllowedAndFinish();
                    }
                }).setCancelable(false).show();
        return;
    }

    // If we get here, that means the type is a ringtone.  There are
    // three choices: make this your default ringtone, assign it to a
    // contact, or do nothing.

    final Handler handler = new Handler() {
        public void handleMessage(Message response) {
            int actionId = response.arg1;
            switch (actionId) {
            case R.id.button_make_default:
                RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this,
                        RingtoneManager.TYPE_RINGTONE, newUri);
                Toast.makeText(RingdroidEditActivity.this, R.string.default_ringtone_success_message,
                        Toast.LENGTH_SHORT).show();
                sendStatsToServerIfAllowedAndFinish();
                break;
            case R.id.button_choose_contact:
                chooseContactForRingtone(newUri);
                break;
            default:
            case R.id.button_do_nothing:
                sendStatsToServerIfAllowedAndFinish();
                break;
            }
        }
    };
    Message message = Message.obtain(handler);
    AfterSaveActionDialog dlog = new AfterSaveActionDialog(this, message);
    dlog.show();
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs,
        String type) {/*  ww  w . j a  v  a  2 s. co m*/
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;

    AppSettings settings = AppSettings.getInstance(context);

    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    int newFollowers = sharedPrefs.getInt("new_followers", 0);
    int newRetweets = sharedPrefs.getInt("new_retweets", 0);
    int newFavorites = sharedPrefs.getInt("new_favorites", 0);
    int newQuotes = sharedPrefs.getInt("new_quotes", 0);

    // set title
    if (newFavorites + newRetweets + newFollowers > 1) {
        title = context.getResources().getString(R.string.new_interactions);
    } else {
        title = context.getResources().getString(R.string.new_interaction_upper);
    }

    // set text
    String currText = sharedPrefs.getString("old_interaction_text", "");
    if (!currText.equals("")) {
        currText += "<br>";
    }
    if (settings.displayScreenName) {
        text = currText + "<b>" + interactor.getScreenName() + "</b> " + type;
    } else {
        text = currText + "<b>" + interactor.getName() + "</b> " + type;
    }
    sharedPrefs.edit().putString("old_interaction_text", text).commit();

    // set icon
    int types = 0;
    if (newFavorites > 0) {
        types++;
    }
    if (newFollowers > 0) {
        types++;
    }
    if (newRetweets > 0) {
        types++;
    }
    if (newQuotes > 0) {
        types++;
    }

    if (types > 1) {
        icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
    } else {
        if (newFavorites > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart_dark);
        } else if (newRetweets > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark);
        } else {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        }
    }

    // set shorter text
    int total = newFavorites + newFollowers + newRetweets + newQuotes;
    if (total > 1) {
        smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower);
    } else {
        smallText = text;
    }

    Intent markRead = new Intent(context, ReadInteractionsService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(Html.fromHtml(
                    settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText))
            .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent)
            .setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);

    if (context.getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(
                Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text)));
    }

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(4, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, text);
        }

        // Light Flow notification
        sendToLightFlow(context, title, text);
    }
}

From source file:com.ringdroid.RingdroidEditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_USE_ALL) {
        return new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.ring_picker_title)
                .setSingleChoiceItems(R.array.set_ring_option, 0, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        ring_button_type = whichButton;
                    }/*from www .  j ava  2  s  .c  om*/
                }).setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        int ring_type = 0;
                        if (ring_button_type == 3) {
                            Intent intent = new Intent();
                            Uri currentFileUri = Uri.parse(mFilename);
                            intent.setData(currentFileUri);
                            intent.setClass(RingdroidEditActivity.this,
                                    com.ringdroid.ChooseContactActivity.class);
                            RingdroidEditActivity.this.startActivity(intent);
                            return;
                        } else if (ring_button_type == 0) {
                            ring_type = RingtoneManager.TYPE_RINGTONE;
                        } else if (ring_button_type == 1) {
                            ring_type = RingtoneManager.TYPE_NOTIFICATION;
                        } else if (ring_button_type == 2) {
                            ring_type = RingtoneManager.TYPE_ALARM;
                        }
                        // u = Const.mp3dir + ring.getString(Const.mp3);
                        Uri currentFileUri = null;
                        if (!mFilename.startsWith("content:")) {
                            String selection;
                            selection = MediaStore.Audio.Media.DATA + "=?";//+"='"+DatabaseUtils.sqlEscapeString(mFilename)+"'";
                            String[] selectionArgs = new String[1];
                            selectionArgs[0] = mFilename;

                            Uri head = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                            Cursor c = getExternalAudioCursor(selection, selectionArgs);
                            if (c == null || c.getCount() == 0) {
                                head = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
                                c = getInternalAudioCursor(selection, selectionArgs);
                            }
                            startManagingCursor(c);
                            if (c == null || c.getCount() == 0)
                                return;
                            c.moveToFirst();
                            String itemUri = head.toString() + "/"
                                    + c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
                            currentFileUri = Uri.parse(itemUri);
                        } else {
                            currentFileUri = Uri.parse(mFilename);
                        }
                        RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this, ring_type,
                                currentFileUri);
                        Toast.makeText(RingdroidEditActivity.this,
                                "" + getResources().getStringArray(R.array.set_ring_option)[ring_button_type],
                                Toast.LENGTH_SHORT).show();
                    }
                }).setNegativeButton(R.string.alertdialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                }).create();
    }
    return super.onCreateDialog(id);
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void sendTestNotification(Context context) {

    if (!TEST_NOTIFICATION) {
        return;//from  www . j a v a 2 s  .  c om
    }

    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    String shortText = "Test Test";
    String longText = "Here is a test for Test's notifications";

    Intent resultIntent = new Intent(context, RedirectToMentions.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }

    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

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

    Intent reply = null;
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "daiv" + " ").build();

    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
            replyPending).addRemoteInput(remoteInput).build();

    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);

    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());

    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());

    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void sendTestNotification(Context context) {

    if (!TEST_NOTIFICATION) {
        return;/* www .ja  v a2s.com*/
    }

    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences(
            "com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    String shortText = "Test Talon";
    String longText = "Here is a test for Talon's notifications";

    Intent resultIntent = new Intent(context, RedirectToMentions.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }

    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

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

    Intent reply = new Intent(context, NotificationCompose.class);
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ")
            .build();

    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
            replyPending).addRemoteInput(remoteInput).build();

    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);

    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());

    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());

    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean playBackDefaultNotification(TaskManagerParms taskMgrParms,
        EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) {
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return false;
    }//from   w w  w.  j  a  va 2s  .  c om
    Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context,
            RingtoneManager.TYPE_NOTIFICATION);
    //      Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id,
                PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION, "", uri.getEncodedPath(), "-1", "-1");
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "Default notification does not exists";
    }

    return true;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Plays the default system notification ringtone.
 * /*from w w w  . j ava2 s .c  om*/
 * @param context
 */
public static void media_soundPlayNotificationDefault(Context context) {
    try {
        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(context, soundUri);
        r.play();

    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Error playing default notification sound (" + e.getMessage() + ")", e);
        }
    }
}

From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java

private void playBackDefaultNotification() {
    //      Thread th=new Thread(){
    //         @Override
    //         public void run() {
    //            Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    //            if (uri!=null) {
    ////               Ringtone rt=RingtoneManager.getRingtone(mContext, uri);
    ////               rt.play();
    ////               SystemClock.sleep(1000);
    ////               rt.stop();
    //               MediaPlayer player = MediaPlayer.create(mContext, uri);
    //               if (player!=null) {
    //                  int dur=player.getDuration();
    //                  player.start();
    //                  SystemClock.sleep(dur+10);
    //                  player.stop();
    //                  player.reset();
    //                  player.release();
    //               }
    //            }
    //         }/*from w ww  .  j a va2 s .c o  m*/
    //      };
    //      th.start();
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        MediaPlayer player = MediaPlayer.create(mContext, uri);
        if (player != null) {
            int dur = player.getDuration();
            player.start();
            SystemClock.sleep(dur + 10);
            player.stop();
            player.reset();
            player.release();
        }
    }
}

From source file:com.nest5.businessClient.Initialactivity.java

public void playSound(Context context)
        throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDataSource(context, soundUri);
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        mMediaPlayer.setLooping(false);/*from   w w  w . j a  v a2  s .co m*/
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    }
}