本文整理汇总了Java中android.media.Ringtone类的典型用法代码示例。如果您正苦于以下问题:Java Ringtone类的具体用法?Java Ringtone怎么用?Java Ringtone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ringtone类属于android.media包,在下文中一共展示了Ringtone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPowerNotificationRingtone
import android.media.Ringtone; //导入依赖的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: handleDataReceived
import android.media.Ringtone; //导入依赖的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();
}
});
}
示例3: beep
import android.media.Ringtone; //导入依赖的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();
}
}
}
}
}
});
}
示例4: getRingtoneName
import android.media.Ringtone; //导入依赖的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;
}
示例5: getRingtoneTitle
import android.media.Ringtone; //导入依赖的package包/类
private String getRingtoneTitle() {
DebugLog.logMethod();
String ringtoneUri = getPreferenceManager().getSharedPreferences().getString(
KEY_NOTIFICATION_RINGTONE,
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()
);
Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(ringtoneUri));
String ringtoneTitle = ringtone.getTitle(getActivity());
// Prevent memory leaks
ringtone.stop();
return ringtoneTitle;
}
示例6: 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.");
}
}
示例7: 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);
}
}
}
示例8: getRingtoneName
import android.media.Ringtone; //导入依赖的package包/类
/**
* Get the title of the ringtone from the uri of ringtone.
*
* @param context instance of the caller
* @param uri uri of the tone to search
* @return title of the tone or return null if no tone found.
*/
@Nullable
public static String getRingtoneName(@NonNull Context context,
@NonNull Uri uri) {
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
if (ringtone != null) {
return ringtone.getTitle(context);
} else {
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);
String title = null;
if (cur != null) {
title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE));
cur.close();
}
return title;
}
}
示例9: initializeRingtonePreference
import android.media.Ringtone; //导入依赖的package包/类
private void initializeRingtonePreference() {
Preference.OnPreferenceChangeListener ringtoneChangedListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
if ("".equals(value)) {
preference.setSummary(R.string.silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(ReminderPreferences.this, value == null
? RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION)
: Uri.parse((String) value));
preference.setSummary(ringtone == null ? "" : ringtone.getTitle(ReminderPreferences.this));
}
return true;
}
};
String ringtoneKey = getString(R.string.p_rmd_ringtone);
Preference ringtonePreference = findPreference(ringtoneKey);
ringtonePreference.setOnPreferenceChangeListener(ringtoneChangedListener);
ringtoneChangedListener.onPreferenceChange(ringtonePreference, PreferenceManager.getDefaultSharedPreferences(this)
.getString(ringtoneKey, null));
}
示例10: onPreferenceChange
import android.media.Ringtone; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (isListPreference(preference)) {
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else if (isRingtonePreference(preference)) {
if (TextUtils.isEmpty(stringValue)) {
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = getRingtone(preference, stringValue);
if (ringtone == null) {
preference.setSummary(null);
} else {
preference.setSummary(getRingtoneTitle(preference, ringtone));
}
}
} else {
preference.setSummary(stringValue);
}
return true;
}
示例11: shortPath
import android.media.Ringtone; //导入依赖的package包/类
public String shortPath(String path) {
if(isPathRingtone(mContext, path)) {
Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path));
// Just verified that the ringtone exists... not checking for null
return ringtone.getTitle(mContext);
}
if(path == null) {
return "";
}
if(path.length() == 0) {
return "xDrip Default";
}
String[] segments = path.split("/");
if (segments.length > 1) {
return segments[segments.length - 1];
}
return path;
}
示例12: shortPath
import android.media.Ringtone; //导入依赖的package包/类
private String shortPath(String path) {
try {
if (path != null) {
if (path.length() == 0) {
return "xDrip Default";
}
Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path));
if (ringtone != null) {
return ringtone.getTitle(mContext);
} else {
String[] segments = path.split("/");
if (segments.length > 1) {
return segments[segments.length - 1];
}
}
}
return "";
} catch (SecurityException e) {
// need external storage permission?
checkStoragePermissions("Need permission to access audio files");
return "";
}
}
示例13: beep
import android.media.Ringtone; //导入依赖的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) {
}
}
}
}
}
});
}
示例14: initSeekBar
import android.media.Ringtone; //导入依赖的package包/类
private void initSeekBar(int stream_type, Ringtone tone, int iconRes, boolean enabled) {
if (enabled) {
View v = getLayoutInflater().inflate(R.layout.volume_sider_item, volume_sliders_container, false);
((ImageView) v.findViewById(R.id.vs_icon)).setImageResource(iconRes);
final SeekBar seek = (SeekBar) v.findViewById(R.id.vs_seek);
seek.setTag(stream_type);
seek.setMax(am.getStreamMaxVolume(stream_type));
seek.setProgress(am.getStreamVolume(stream_type));
seek.setOnSeekBarChangeListener(this);
ringtoneMap.put(stream_type, tone);
volume_sliders_container.addView(v);
if (mLastControlledSeekbar == null) {
mLastControlledSeekbar = seek;
}
}
}
示例15: 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;
}