本文整理汇总了Java中android.media.Ringtone.play方法的典型用法代码示例。如果您正苦于以下问题:Java Ringtone.play方法的具体用法?Java Ringtone.play怎么用?Java Ringtone.play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.Ringtone
的用法示例。
在下文中一共展示了Ringtone.play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleChangePolicies
import android.media.Ringtone; //导入方法依赖的package包/类
private void handleChangePolicies(Application application) {
SharedPreferences sharedPref = application.getSharedPreferences(
application.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Uri sound = getTone(sharedPref);
if (notificationNeeded(application, sharedPref)) {
Log.i("TTM", "Changes found. Would fire!");
switch (sharedPref.getString("onChangeForm", "Banner")) {
case "None":
if (sound != null) {
Ringtone r = RingtoneManager.getRingtone(application.getApplicationContext(), sound);
r.play();
}
break;
case "Banner":
fireBanner(sound);
break;
}
} else {
Log.i("TTM", "Change check negative -> Won't fire any notification for change.");
}
}
示例2: maybePlaySound
import android.media.Ringtone; //导入方法依赖的package包/类
private void maybePlaySound() {
if (mSoundEnabled &&
(!mPowerManager.isInteractive() || !mSoundWhenScreenOffOnly)) {
try {
final Ringtone sfx = RingtoneManager.getRingtone(mContext,
Uri.parse(mSoundUri));
if (sfx != null) {
AudioAttributes attrs = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
sfx.setAudioAttributes(attrs);
sfx.play();
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
}
示例3: onStopTrackingTouch
import android.media.Ringtone; //导入方法依赖的package包/类
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
final int stream = (Integer) seekBar.getTag();
am.setStreamVolume(stream, seekBar.getProgress(), 0);
if (stream == AudioManager.STREAM_RING) {
volume_modes.check(seekBar.getProgress() > 0 ?
(VolumeTracker.isVibrateOn(this, am) ? R.id.rd_vol_4 : R.id.rd_vol_3) :
R.id.rd_vol_1);
}
Ringtone tone = ringtoneMap.get(stream);
if (tone!=null && playMusic) {
tone.setStreamType(stream);
tone.play();
}
mLastControlledSeekbar = seekBar;
}
示例4: onReceive
import android.media.Ringtone; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
//this will sound the alarm tone
//this will sound the alarm once, if you wish to
//raise alarm in loop continuously then use MediaPlayer and setLooping(true)
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null) {
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
ringtone.play();
//this will send a notification message
ComponentName comp = new ComponentName(context.getPackageName(),
AlarmService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
示例5: sendAntiTheftNotification
import android.media.Ringtone; //导入方法依赖的package包/类
/**
* TODO Should be moved. Produces Android notification
*
* @param ctx
* @param desc
* @param longdesc
* @param icon
* @param ty
*/
public static void sendAntiTheftNotification(Context ctx, String desc, String longdesc, int icon, SoulissTypical ty) {
Intent notificationIntent = new Intent(ctx, T4nFragWrapper.class);
notificationIntent.putExtra("TIPICO", ty);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = ctx.getResources();
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
builder.setContentIntent(contentIntent).setSmallIcon(android.R.drawable.stat_sys_warning)
.setLargeIcon(BitmapFactory.decodeResource(res, icon)).setTicker(desc)
.setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentTitle(desc).setContentText(longdesc);
Notification n = builder.build();
nm.notify(664, n);
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
Ringtone r = RingtoneManager.getRingtone(ctx, notification);
r.play();
} catch (Exception e) {
Log.e(Constants.Net.TAG, "Unable to play sounds:" + e.getMessage());
}
}
示例6: onReceive
import android.media.Ringtone; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
int currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,
-1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
int level = -1;
if (currentLevel >= 0 && scale > 0) {
level = (currentLevel * 100) / scale;
}
// batteryPercent.setText("Battery Level Remaining: " + level +
// "%");//
if (level < 4) {
Toast.makeText(getBaseContext(), "Changed Level" + level,
Toast.LENGTH_LONG).show();
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_ALARM);
Ringtone r = RingtoneManager.getRingtone(
getApplicationContext(), notification);
r.play();//
}
}
示例7: beep
import android.media.Ringtone; //导入方法依赖的package包/类
/**
* Beep plays the default notification ringtone.
*
* @param count Number of times to play notification
*/
public void beep(long count) {
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone notification = RingtoneManager.getRingtone(this.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) {
}
}
}
}
}
示例8: playNotification
import android.media.Ringtone; //导入方法依赖的package包/类
/**
* Play an audio notification.
*/
private void playNotification()
{
// Play a beep noise...
try
{
Uri notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
notification);
r.play();
}
catch (Exception e)
{
}
}
示例9: run
import android.media.Ringtone; //导入方法依赖的package包/类
@Override
public void run() {
if (sampleRingtonePos == silentPos) {
ringtoneManager.stopPreviousRingtone();
return;
}
if (defaultRingtone != null && defaultRingtone.isPlaying()) {
defaultRingtone.stop();
defaultRingtone = null;
}
Ringtone ringtone;
if (sampleRingtonePos == defaultRingtonePos) {
if (defaultRingtone == null) {
defaultRingtone = RingtoneManager.getRingtone(context,
uriForDefaultItem);
}
ringtone = defaultRingtone;
ringtoneManager.stopPreviousRingtone();
} else {
ringtone = ringtoneManager
.getRingtone(getRingtoneManagerPosition(sampleRingtonePos));
}
if (ringtone != null) {
ringtone.play();
}
}
示例10: notifyInApp
import android.media.Ringtone; //导入方法依赖的package包/类
public static void notifyInApp(final Snackbar snackbar, final Activity activity,
final Conversation conversation, boolean channel) {
final Set<String> inApp = AppPreferences.getAppPreferences()
.getInAppNotificationSettings();
if (AppPreferences.getAppPreferences().isInAppNotification()) {
int messageResId = channel
? R.string.notification_mentioned_title : R.string.notification_queried_title;
final String message = activity.getString(messageResId,
conversation.getId(), conversation.getServer().getTitle());
snackbar.display(message);
if (inApp.contains(activity.getString(R.string.notification_value_audio))) {
final Uri notification = RingtoneManager.getDefaultUri(TYPE_NOTIFICATION);
final Ringtone r = RingtoneManager.getRingtone(activity, notification);
r.play();
}
if (inApp.contains(activity.getString(R.string.notification_value_vibrate))) {
final Vibrator vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(500);
}
}
}
示例11: playNotificationSound
import android.media.Ringtone; //导入方法依赖的package包/类
private void playNotificationSound(Context ctxt)
{
final String soundPath = mPrefs.getString("pref_key_custom_ringtone", null);
if (soundPath != null && !soundPath.equals(""))
{
final Uri soundUri = Uri.parse(soundPath);
if (soundUri != null)
{
final Ringtone sfx = RingtoneManager.getRingtone(ctxt, soundUri);
if (sfx != null)
{
sfx.setStreamType(AudioManager.STREAM_NOTIFICATION);
sfx.play();
}
}
}
}
示例12: beep
import android.media.Ringtone; //导入方法依赖的package包/类
public void beep(long paramLong)
{
Uri localUri = RingtoneManager.getDefaultUri(2);
Ringtone localRingtone = RingtoneManager.getRingtone(this.cordova.getActivity().getBaseContext(), localUri);
if (localRingtone != null)
{
long l1 = 0L;
while (l1 < paramLong)
{
localRingtone.play();
long l2 = 5000L;
while ((localRingtone.isPlaying()) && (l2 > 0L))
{
l2 -= 100L;
try
{
Thread.sleep(100L);
}
catch (InterruptedException localInterruptedException)
{
}
}
l1 += 1L;
}
}
}
示例13: onReceive
import android.media.Ringtone; //导入方法依赖的package包/类
@Override
public void onReceive(Context arg0, Intent arg1) {
PendingIntent pIntent = PendingIntent.getActivity(arg0, 0,
new Intent(arg0, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP).putExtra(MainActivity.FROM_NOTIFICATION, true),
0);
NotificationManager notificationManager = (NotificationManager) arg0.getSystemService(MainActivity.NOTIFICATION_SERVICE);
NotificationCompat.Builder noti = new NotificationCompat.Builder(arg0);
noti.setContentTitle("Brain Rot")
.setContentText("Your cards await you (click to do them)...")
.setSmallIcon(R.drawable.brainrot_notification)
.setContentIntent(pIntent)
.build().flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti.build());
if (!MainActivity.isInForeground)
{
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(arg0, notification);
r.play();
} catch (Exception e) {}
}
}
示例14: notifyNewMensage
import android.media.Ringtone; //导入方法依赖的package包/类
private void notifyNewMensage(Chat chat){
notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getActivity(), ChatActivity.class);
intent.putExtra("name",chat.getName());
intent.putExtra("email", Base64Custom.decodeBase64(chat.getUserId()));
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(),0, intent,0);
NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(getContext());
builder.setContentIntent(pendingIntent);
builder.setTicker("Nova mensagem de "+chat.getName());
builder.setContentTitle("Mensagem de "+chat.getName());
builder.setContentText(chat.getMensageValue());
builder.setSmallIcon(R.drawable.ic_chat);
builder.setVibrate(new long[] { 200, 200, 200, 200, 200 });
Notification notification = builder.build();
notificationManager.notify(Integer.parseInt(chat.getUserId().replaceAll("[^0-9]", "")), notification);
try{
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone ringtone = RingtoneManager.getRingtone(getContext(),uri);
ringtone.play();
}catch (Exception e){
}
}
示例15: startAlarm
import android.media.Ringtone; //导入方法依赖的package包/类
/**
* 播放系统当前提示音
* @param context 上下文
*/
private static void startAlarm(Context context) {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (notification == null) return;
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
}