- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个提醒应用程序,允许用户从我使用 android 首选项实现的设置选项中设置通知所需的铃声。
铃声对话框与列表一起显示,我选择的铃声已更新,但所选铃声未设置为通知。它始终以设备的默认铃声进行通知。
我引用并尝试了类似问题的答案,但它不起作用
Preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Settings">
<RingtonePreference
android:name="RingtonePreference"
android:summary="Select a ringtone"
android:title="Ringtones"
android:key="@string/ringtonePref"
android:defaultValue="content://settings/system/notification_sound"
/>
</PreferenceCategory>
</PreferenceScreen>
Prefrence.java
public class Preferences extends PreferenceActivity implements OnPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
String ringtonePreference;
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
ringtonePreference = prefs.getString("ringtonePref",
"DEFAULT_RINGTONE_URI");
}
@Override
protected void onResume() {
super.onResume();
RingtonePreference pref = (RingtonePreference) findPreference(getString(R.string.ringtonePref));
pref.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
updateRingtoneSummary((RingtonePreference) preference, Uri.parse((String) newValue));
return true;
}
private void updateRingtoneSummary(RingtonePreference preference, Uri ringtoneuri) {
// TODO Auto-generated method stub
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneuri);
if (ringtone != null)
preference.setSummary(ringtone.getTitle(this));
else
preference.setSummary("Silent");
}
}
MainActivity.java
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_settings:
Intent intent = new Intent(this, Preferences.class);
startActivity(intent);
return true;
case R.id.menu_about:
Intent i = new Intent(this, About.class);
startActivity(i);
}
return super.onMenuItemSelected(featureId, item);
}
NotificationService.java
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId);
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
Notification note=new Notification(R.drawable.ic_icon, title, System.currentTimeMillis());
note.setLatestEventInfo(this, title, "You have a task to be done!", pi);
note.flags |= Notification.FLAG_AUTO_CANCEL;
int id = (int)((long)rowId);
mgr.notify(id, note);
最佳答案
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// DO NOT ever call getBaseContext() unless you know what you're doing. "this" or "getApplicationContext() is perfect. Google the difference.
String ringtonePreference = prefs.getString("ringtonePref", "DEFAULT_RINGTONE_URI");
// The key of preference was "@string/ringtonePref" which is useless since you're hardcoding the string here anyway.
Uri ringtoneuri = Uri.parse(ringtonePreference);
考虑使用 DEFAULT_NOTIFICATION_URI
而不是 DEFAULT_RINGTONE_URI
。
NotificationCompat.Builder b = new NotificationCompat.Builder(context)
.setSound(ringtoneuri)
...
关于java - 从 Android 首选项设置铃声不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36177407/
我正在使用 NotificationManager 构建器在我的应用程序中显示警报。我知道 notify 方法的第一个参数是一个 id,如果它已经可见,框架将更新通知,但是如果我将警报设置为播放铃声或
我想在我的应用程序中使用 iPhone 的铃声。这可能吗?请帮助我解决这一点, 谢谢 最佳答案 您无法以编程方式使用或更改可用的铃声。很抱歉这么说,但苹果实在太保守了。 关于iphone - 如何在应
我正在尝试禁用 vim 上的错误铃声,包括视觉和音频。但是我不能让他们离开。 我的 vimrc 中有以下内容: " Disable annoying beeping set noerrorbells
我的应用程序播放闹钟。在 Android 声音设置中,此声音由“铃声音量” slider 控制,而不是由“闹钟音量” slider 控制。如何更改由“闹钟音量”控制的声音? public void
我想做的是创建类似应用程序的警报。主要编码完成。目前它播放一首添加到我的 apk(原始文件夹)中的歌曲。 我想添加一个功能,让用户可以选择他/她自己的歌曲作为闹钟声音。它可以是来自 SD 卡、内部的文
我想从我的应用程序中从云端下载 mp3 文件,然后将下载的音频文件设置为铃声。我通过 stackoverflow 尝试了很多解决方案,并花了很多时间在谷歌中搜索,但没有任何好的结果。 更新: 我已经解
我正在尝试添加某种回声命令,使我的菜单在准备好供用户输入时发出蜂鸣声或铃声。如果有任何可能的帮助,我将不胜感激,谢谢! loop=y while [ "$loop" = y ] do clear
我开始使用以下方式播放声音:(工作) RingtoneManager.getRingtone(this, Uri.parse(callerRing)).play(); 并尝试使用以下方式停止播放声音:
我如何在 React Native 中获取系统铃声列表,例如铃声、通知铃声,以便我可以让用户选择将它们设置为通知铃声? 我查看了一些库,如 react-native-ringtone-manager
我的应用程序必须能够在收到推送通知时无论如何播放警报声。 有没有办法配置 Audio Session 来播放声音: 并且不遵守无声开关(可能会遵守路线) 在推送消息到达时(可以是无声的)并且应用程序是
我正在尝试在我的 PhoneGap 应用程序中播放 mp3 音调。在 iOS 上运行良好,但在 Android (4.2.2) 上无法播放铃声。 html js: document.getE
我想将我的资源文件夹中的铃声设置为默认铃声。现在我发现这是不可能的,因为无法从外部访问 Assets 。因此,我必须将文件从我的 Assets 复制到 SD,或者我使用内容提供程序。我认为最后一个是更
我想在我的 Android 应用程序中播放来自(铃声)URI 的声音。但是,我想以任意音量播放此声音,并且系统音量(例如媒体和铃声音量)不会影响播放。 我一直在翻阅 API 文档,但不知所措。这在 A
我是一名优秀的程序员,十分优秀!