本文整理汇总了Java中android.media.RingtoneManager类的典型用法代码示例。如果您正苦于以下问题:Java RingtoneManager类的具体用法?Java RingtoneManager怎么用?Java RingtoneManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RingtoneManager类属于android.media包,在下文中一共展示了RingtoneManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPowerNotificationRingtone
import android.media.RingtoneManager; //导入依赖的package包/类
private void setPowerNotificationRingtone(Intent intent) {
final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
final String toneName;
final String toneUriPath;
if ( uri != null ) {
final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri);
toneName = ringtone.getTitle(getActivity());
toneUriPath = uri.toString();
} else {
// silent
toneName = getString(R.string.power_notifications_ringtone_silent);
toneUriPath = POWER_NOTIFICATIONS_SILENT_URI;
}
mPowerSoundsRingtone.setSummary(toneName);
CMSettings.Global.putString(getContentResolver(),
CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath);
}
示例2: showUpdateNotAvailableNotification
import android.media.RingtoneManager; //导入依赖的package包/类
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(contentIntent)
.setContentTitle(title)
.setContentText(content)
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setSmallIcon(smallIconResourceId)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setOnlyAlertOnce(true)
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
示例3: sendNotification
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, QuakeActivity.class);//**The activity that you want to open when the notification is clicked
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_error_outline_white_24dp)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
示例4: handleDataReceived
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Handles incoming data events from the mesh - toasts the contents of the data.
*
* @param e event object from mesh
*/
private void handleDataReceived(MeshManager.RightMeshEvent e) {
final MeshManager.DataReceivedEvent event = (MeshManager.DataReceivedEvent) e;
runOnUiThread(new Runnable() {
@Override
public void run() {
// Toast data contents.
String message = new String(event.data);
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
// Play a notification.
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(MainActivity.this, notification);
r.play();
}
});
}
示例5: showNotification
import android.media.RingtoneManager; //导入依赖的package包/类
public NotificationCompat.Builder showNotification() {
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationId = (int) new Date().getTime();
mNotifyManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(getActivity());
mBuilder.setContentTitle("Sending mail to " + this.company.getCompanyName())
.setContentText("Sending...")
.setSound(defaultSoundUri)
.setSmallIcon(R.drawable.ic_stat_name);
mBuilder.setProgress(100, 100, true);
// Displays the progress bar for the first time.
mNotifyManager.notify(notificationId, mBuilder.build());
return mBuilder;
}
示例6: beep
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Beep plays the default notification ringtone.
*
* @param count Number of times to play notification
*/
public void beep(final long count) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().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) {
Thread.currentThread().interrupt();
}
}
}
}
}
});
}
示例7: showUpdateAvailableNotification
import android.media.RingtoneManager; //导入依赖的package包/类
static void showUpdateAvailableNotification(Context context, String title, String content, UpdateFrom updateFrom, URL apk, int smallIconResourceId) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntentUpdate = PendingIntent.getActivity(context, 0, UtilsLibrary.intentToUpdate(context, updateFrom, apk), PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(contentIntent)
.setContentTitle(title)
.setContentText(content)
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setSmallIcon(smallIconResourceId)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setOnlyAlertOnce(true)
.setAutoCancel(true)
.addAction(R.drawable.ic_system_update_white_24dp, context.getResources().getString(R.string.appupdater_btn_update), pendingIntentUpdate);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
示例8: getRingtoneName
import android.media.RingtoneManager; //导入依赖的package包/类
@NonNull public static String getRingtoneName(@NonNull Context context, @Nullable Uri uri) {
String title = context.getString(R.string.sound_chooser_summary);
if (uri != null) {
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
if (ringtone != null) {
return ringtone.getTitle(context);
} else {
try (Cursor cur = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?",
new String[]{uri.getLastPathSegment()}, null)) {
if (cur != null) {
title = cur.getString(1);
if (InputHelper.isEmpty(title)) {
title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE));
}
}
} catch (Exception ignored) {}
}
}
return title;
}
示例9: displayNotification
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Muestra que ha habido una nueva notificación
* @param notification
* @param data
*/
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("notificacion","notificacion");
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)
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setSmallIcon(R.mipmap.ic_launch)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
示例10: onReceive
import android.media.RingtoneManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Intent intent2 = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setAutoCancel(true) //Automatically delete the notification
.setSmallIcon(R.drawable.water_bottle_flat) //Notification icon
.setContentIntent(pendingIntent)
.setContentTitle("Time to hydrate")
.setContentText("Drink a glass of water now")
.setCategory(Notification.CATEGORY_REMINDER)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(defaultSoundUri);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(0, notificationBuilder.build());
Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show();
}
示例11: onActivityResult
import android.media.RingtoneManager; //导入依赖的package包/类
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (resultCode == Activity.RESULT_OK && requestCode == 5) {
Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
SharedPreferences myPrefs = this.getSharedPreferences(SettingConstants.PREFERENCES, MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
if (uri != null) {
prefsEditor.putString(SettingConstants.SOUNDFILE, uri.toString());
prefsEditor.apply();
Log.d(TAG, "Chosen sound: " + uri.toString());
Answers.getInstance().logCustom(new CustomEvent("Sound")
.putCustomAttribute("uri", uri.toString()));
} else {
prefsEditor.putString(SettingConstants.SOUNDFILE, "");
prefsEditor.apply();
}
TextView soundTV = (TextView) findViewById(R.id.textViewCurrentSound);
soundTV.setText(myPrefs.getString(SettingConstants.SOUNDFILE, SettingConstants.SOUNDFILE_DEFAULT));
}
}
示例12: getNotifications
import android.media.RingtoneManager; //导入依赖的package包/类
public Map<String, String> getNotifications() {
RingtoneManager manager = new RingtoneManager(getActivity());
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
Map<String, String> list = new HashMap<>();
while (cursor.moveToNext()) {
String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());
list.put(notificationTitle, notificationUri.toString());
}
list.put(getString(R.string.ringtone_vk), Settings.get()
.notifications()
.getDefNotificationRingtone());
return list;
}
示例13: getTone
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Get the tone from {@link RingtoneManager} for any given type. It will add title as the key and
* uri of the sound as value in given hashmap.
*
* @param context instance of the caller
* @param type type of the ringtone from {@link RingtonePickerDialog.Builder#TYPE_NOTIFICATION},
* {@link RingtonePickerDialog.Builder#TYPE_RINGTONE} or {@link RingtonePickerDialog.Builder#TYPE_ALARM}
* @param ringTonesList Hash map in which alarm tone will be added.
*/
private static void getTone(Context context,
int type,
@NonNull HashMap<String, Uri> ringTonesList) {
RingtoneManager mRingtoneMgr = new RingtoneManager(context);
mRingtoneMgr.setType(type);
Cursor ringsCursor = mRingtoneMgr.getCursor();
while (ringsCursor.moveToNext()) {
ringTonesList.put(ringsCursor.getString(RingtoneManager.TITLE_COLUMN_INDEX),
Uri.parse(ringsCursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/"
+ ringsCursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
}
ringsCursor.close();
}
示例14: sendNotification
import android.media.RingtoneManager; //导入依赖的package包/类
/**
* Method send notification
*
* @param message message object
*/
private void sendNotification(Message message) {
Intent intent = new Intent(this, ChatActivity.class);
intent.putExtra("message", message);
intent.putExtra("id", message.getSender());
intent.putExtra("name", name);
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("Chat cDa")
.setContentText(message.getMessage())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
示例15: sendNotification
import android.media.RingtoneManager; //导入依赖的package包/类
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int requestCode = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_name)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 0;
notificationManager.notify(notificationId, notificationBuilder.build());
}