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.example.android.basicsyncadapter.SyncAdapter.java

/**
 * Called by the Android system in response to a request to run the sync adapter. The work required to read data from the network,
 * parse it, and store it in the content provider is done here. Extending AbstractThreadedSyncAdapter ensures that all methods
 * within SyncAdapter run on a background thread. For this reason, blocking I/O and other long-running tasks can be run
 * <em>in situ</em>, and you don't have to set up a separate thread for them.
 *
 * <p>This is where we actually perform any work required to perform a sync. {@link android.content.AbstractThreadedSyncAdapter}
 * guarantees that this will be called on a non-UI thread, so it is safe to peform blocking I/O here.
 *
 * <p>The syncResult argument allows you to pass information back to the method that triggered the sync.
 *//*  w  w w .j  av  a 2 s  . co m*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.i(TAG, "Beginning network synchronization");
    try {
        InputStream stream = null;

        try {
            //Log.i(TAG, "Streaming data from network: " + FEED_URL);
            //stream = downloadUrl(location);
            stream = downloadUrl(FEED_URL);
            updateLocalFeedData(stream, syncResult);
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    } catch (MalformedURLException e) {
        Log.e(TAG, "Feed URL is malformed", e);
        syncResult.stats.numParseExceptions++;
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error reading from network: " + e.toString());
        syncResult.stats.numIoExceptions++;
        return;
    } catch (XmlPullParserException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (ParseException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (RemoteException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    }
    Log.i(TAG, "Network synchronization complete");

    //Throw notification

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Alerta de cicln tropical")
            .setContentText("Hello World!").setAutoCancel(true).setLights(0xff00ff00, 300, 100)
            .setPriority(Notification.PRIORITY_MAX);

    Intent resultIntent = new Intent(getContext(), EntryListActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //Add sound
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    //Add vibrate pattern
    long[] pattern = { 0, 200, 500 };

    mBuilder.setVibrate(pattern);
    mBuilder.setSound(alarmSound);
    mBuilder.setContentIntent(resultPendingIntent);

    int mNotificationId = 001;
    NotificationManager mNotifyMgr = (NotificationManager) getContext()
            .getSystemService(Service.NOTIFICATION_SERVICE);
    mNotifyMgr.notify(mNotificationId, mBuilder.build());

    //Wake screen
    /*WakeLock screenOn = ((PowerManager)getContext().getSystemService(Service.POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK| PowerManager.ACQUIRE_CAUSES_WAKEUP, "example");
    screenOn.acquire();
            
    long endTime = System.currentTimeMillis() + 6*1000;
    while (System.currentTimeMillis() < endTime) {
    synchronized (this) {
        try {
            wait(endTime - System.currentTimeMillis());
        } catch (Exception e) {
        }
    }
    }
            
    screenOn.release();*/
}

From source file:com.xyproto.archfriend.ArchFriendActivity.java

public void btnNews_clicked(View view) throws InterruptedException, ExecutionException, ParseException {
    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
    nb.setContentTitle("Waaaaoooaaaaa!");
    nb.setContentText("OJOJOJOJOJOJ!");
    nb.setSmallIcon(R.drawable.archfriend_tiny_bw_logo2013);
    nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // nb.setLargeIcon(bitmap);
    Notification noti = nb.build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, noti);
    populateNews();//www . j  av a 2 s . co  m
}

From source file:de.damdi.fitness.activity.start_training.RecoveryTimerManager.java

private synchronized void startTimer(final RecoveryTimerKind timerKind) {
    // create notification
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle(timerKind.contentTitleRunning)
            .setSmallIcon(R.drawable.icon_dumbbell_small)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_dumbbell));

    final boolean doVibrate = mVibrationEnabled;
    final boolean doBeep = mNotificationSoundEnabled;
    int maxInSec = timerKind.timerDurationInSec;
    final int max = 10 * maxInSec;
    mSetTimer = new Timer();

    TimerTask task = new TimerTask() {
        private int counter = 0;

        @Override/*www  .ja  va 2s .co  m*/
        public void run() {
            // update progress if still running
            if (counter < max) {
                mNotificationBuilder.setTicker(timerKind.tickerRunning);
                mNotificationBuilder.setProgress(max, counter, false);
                mNotificationBuilder.setUsesChronometer(true);
                // Displays the progress bar for the first time.
                mNotifyManager.notify(0, mNotificationBuilder.build());

                counter++;
            } else {
                mNotificationBuilder.setProgress(max, max, false);
                //mNotificationBuilder.setNumber(max);

                // change message if progress is finished
                mNotificationBuilder.setContentTitle(timerKind.contentTitleFinished);
                mNotificationBuilder.setTicker(timerKind.tickerFinished);

                // let phone vibrate (unless user disabled this feature)
                if (doVibrate) {
                    long[] vibrationPattern = { 0, 300 };
                    mNotificationBuilder.setVibrate(vibrationPattern);
                }
                // make a notification sound (unless user disabled this feature)
                if (doBeep) {
                    Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    mNotificationBuilder.setSound(defaultSound);
                }
                mNotificationBuilder.setAutoCancel(true);
                mNotifyManager.notify(RECOVERY_TIMER_NOTIFICATION_ID, mNotificationBuilder.build());
                mSetTimer.cancel();

            }

        }
    };

    long period = 100;
    long delay = 0;
    mSetTimer.scheduleAtFixedRate(task, delay, period);
}

From source file:com.fimo_pitch.main.MainActivity.java

private void makeNotification(Context context, String title, String content) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri)
            .setPriority(Notification.PRIORITY_HIGH).setContentText(content);
    Intent resultIntent = new Intent(context, MainActivity.class);
    userModel = getUserModel();// w  ww.  j a  va  2s . c o m
    resultIntent.putExtra(CONSTANT.KEY_USER, userModel);
    resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true");
    TaskStackBuilder stackBuilder = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(FirstActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(ZAQ500);
    } else {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(500);
    }
}

From source file:at.flack.receiver.EMailReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from w  w  w  . ja  va 2  s  . c  o  m
    try {
        if (bundle.getString("type").equals("mail")) {
            sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (!sharedPrefs.getBoolean("notification_mail", true))
                return;
            notify = sharedPrefs.getBoolean("notifications", true);
            vibrate = sharedPrefs.getBoolean("vibration", true);
            headsup = sharedPrefs.getBoolean("headsup", true);
            led_color = sharedPrefs.getInt("notification_light", -16776961);
            boolean all = sharedPrefs.getBoolean("all_mail", true);

            if (notify == false)
                return;

            NotificationCompat.Builder mBuilder = null;
            boolean use_profile_picture = false;
            Bitmap profile_picture = null;

            String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail")
                    : bundle.getString("senderName");

            try {
                profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                        ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300);
                use_profile_picture = true;
            } catch (Exception e) {
                use_profile_picture = false;
            }

            Resources res = context.getResources();

            int lastIndex = bundle.getString("subject").lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                        .setColor(0xFFFF5722)
                        .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail))
                        .setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {

                if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10
                        || bundle.getString("subject").length() == 9)) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (bundle.getString("subject").charAt(0) == '%'
                        && bundle.getString("subject").length() >= 120
                        && bundle.getString("subject").length() < 125) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (all) { // normal message
                    mBuilder = new NotificationCompat.Builder(context)
                            .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                            .setColor(0xFFFF5722).setContentText(bundle.getString("subject"))
                            .setAutoCancel(true).setStyle(
                                    new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject")));

                    if (use_profile_picture && profile_picture != null) {
                        mBuilder = mBuilder.setLargeIcon(profile_picture);
                    } else {
                        mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                    }
                } else {
                    return;
                }
            }
            // }
            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(alarmSound);
            mBuilder.setLights(led_color, 750, 4000);
            if (vibrate) {
                mBuilder.setVibrate(new long[] { 0, 100, 200, 300 });
            }

            Intent resultIntent = new Intent(context, MainActivity.class);
            resultIntent.putExtra("MAIL", bundle.getString("senderMail"));

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            if (Build.VERSION.SDK_INT >= 16 && headsup)
                mBuilder.setPriority(Notification.PRIORITY_HIGH);
            if (Build.VERSION.SDK_INT >= 21)
                mBuilder.setCategory(Notification.CATEGORY_MESSAGE);

            final NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (!MainActivity.isOnTop)
                mNotificationManager.notify(9, mBuilder.build());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM
 * message.//w ww  .  ja v a2  s  . c o m
 *
 * @param message GCM message received.
 */

private void sendNotificationForTakeBreak(String message, String fromId, String toId) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction("takeBreak");
    intent.putExtra("fromId", fromId);
    intent.putExtra("toId", toId);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Intent intentAccept = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT);
    //
    Intent intentDecline = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline,
            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(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setAutoCancel(true);

    notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
    notificationBuilder.setAutoCancel(true);

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

    notificationManager.notify((int) new Date().getTime(), notificationBuilder.build());

}

From source file:com.remobile.dialogs.Notification.java

/**
 * Beep plays the default notification ringtone.
 *
 * @param count Number of times to play notification
 *//*ww w  .  j  a  va  2s  .  com*/
public void beep(final long count) {
    final Activity activity = this.cordova.getActivity();
    this.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone notification = RingtoneManager.getRingtone(activity.getBaseContext(), ringtone);

            // If phone is not set to silent mode
            if (notification != null) {
                for (long i = 0; i < count; ++i) {
                    notification.play();
                    long timeout = 5000;
                    while (notification.isPlaying() && (timeout > 0)) {
                        timeout = timeout - 100;
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }
        }
    });
}

From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java

/**
 * Send an alert to the user for the event e.
 * //from ww w.  j av a  2  s. co  m
 * @param e
 *          Event to notify to the user.
 */
private void sendAlert(Event e) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Time currentTime = new Time();
    currentTime.setToNow();

    long nbMin = e.getBeginTime().toMillis(false) / 60L / 1000L - currentTime.toMillis(false) / 60L / 1000L;

    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setContentTitle(e.getDetail(Event.COURSE) + " " + getString(R.string.begins_in) + " " + nbMin + " "
                    + getString(R.string.minutes))
            .setContentText(e.getDetail(Event.ROOM) + " - " + e.getDetail(Event.TITLE)).setAutoCancel(true);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String ringtone = preferences.getString(SettingsActivity.NOTIFY_RINGTONE, null);
    if (ringtone == null) {
        notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    } else {
        notificationBuilder.setSound(Uri.parse(ringtone));
    }
    notificationManager.notify(1, notificationBuilder.build());
}

From source file:com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService.java

/**
 * Generate a notification/*from   w  ww. j  a  va 2  s .c om*/
 * 
 * @param invitation invitation
 * @param title title
 * @param message message
 * @return the notification
 */
private Notification buildNotification(PendingIntent invitation, String title, String message) {
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(invitation);
    notif.setSmallIcon(R.drawable.ri_notif_chat_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(message);
    return notif.build();
}

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

public void notifyAnnouncement(String announcement, String URL) {
    Uri webpage = Uri.parse(URL);
    Intent contentIntent = new Intent(Intent.ACTION_VIEW, webpage);
    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   www  .  ja  v a 2  s .c  o m*/
    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());
}