无法为android通知设置铃声
我正在开发一个需要为通知设置铃声的应用程序,因为我正在使用铃声选择器,它会在选择器上显示铃声列表,我可以选择铃声,但在下次设置铃声时,铃声选择器不会显示以前选择的铃声,并且通知会附带默认铃声。我陷入困境,找不到任何解决办法。提前谢谢 这是我的密码无法为android通知设置铃声,android,notifications,Android,Notifications,我正在开发一个需要为通知设置铃声的应用程序,因为我正在使用铃声选择器,它会在选择器上显示铃声列表,我可以选择铃声,但在下次设置铃声时,铃声选择器不会显示以前选择的铃声,并且通知会附带默认铃声。我陷入困境,找不到任何解决办法。提前谢谢 这是我的密码 public class ActivitySettings extends Activity { Context mContext; // making TypeFace object global for setting custom
public class ActivitySettings extends Activity {
Context mContext;
// making TypeFace object global for setting custom font to various Views
Typeface objTypeFace;
// variables for toggle button values
boolean notification;
// declaring toggle button objects
ToggleButton toggleNotification;
// Key for Checking whteher notification is on or off
public static final String PREFS_NOTIFICATION = "Notification";
Uri uri1,ringtone;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.activity_settings);
mContext = this;
// getting font object
objTypeFace = Typeface.createFromAsset(getBaseContext().getAssets(),
"fonts/HelveticaNeueLTStd-Md.ttf");
// getting all textview objects from xml layout
TextView txtHeading = (TextView) findViewById(R.id.Setting_txtHeading);
txtHeading.setTypeface(objTypeFace);
TextView txtNotification = (TextView) findViewById(R.id.Setting_txtnotification);
txtNotification.setTypeface(objTypeFace);
TextView txtTone = (TextView) findViewById(R.id.Setting_txtsettone);
txtTone.setTypeface(objTypeFace);
TextView txtSyncContact = (TextView) findViewById(R.id.Setting_txtSynContact);
txtSyncContact.setTypeface(objTypeFace);
// getting all buttons object from xml layout
Button btnBack = (Button) findViewById(R.id.btnBack);
toggleNotification = (ToggleButton) findViewById(R.id.Setting_togglenotification);
// adding click events to various buttons
btnBack.setOnClickListener(clickButtons);
txtTone.setOnClickListener(clickButtons);
toggleNotification.setOnClickListener(clickButtons);
// getting values of toggle buttons from shared prefrence
notification = CommonUtility.getNotificationFromPrefernce(mContext,
PREFS_NOTIFICATION);
} // on create ends
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
// setting toggle buttons according to various values
if (notification) {
toggleNotification.setChecked(true);
} else {
toggleNotification.setChecked(false);
}
} // method ends
// Click Listener for various buttons
public OnClickListener clickButtons = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.Setting_txtsettone:
// code for setting notification tones
Intent tmpIntent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
startActivityForResult(tmpIntent, 123);
break;
case R.id.btnBack:
finish();
break;
case R.id.Setting_togglenotification:
if (toggleNotification.isChecked()) {
notification = true;
CommonUtility.setNotificationPrefernce(mContext,
PREFS_NOTIFICATION, notification);
} else {
notification = false;
CommonUtility.setNotificationPrefernce(mContext,
PREFS_NOTIFICATION, notification);
// Clear all notification
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancelAll();
}
break;
}
}
}; // click events ends
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && rerequestCode==123) {
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null) {
String ringTonePath = uri.toString();
RingtoneManager.setActualDefaultRingtoneUri(
mContext,
RingtoneManager.TYPE_RINGTONE,
uri);
System.out.println("SElected tone uri is ///////"
+ uri);
}
}
}
} // final class ends
在logcat中我得到了这个错误,但在Google上我找不到任何解决方案
03-13 19:33:55.189: E/DatabaseUtils(403): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
03-13 19:33:55.189: E/DatabaseUtils(403): at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13090)
03-13 19:33:55.189: E/DatabaseUtils(403): at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
03-13 19:33:55.189: E/DatabaseUtils(403): at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
03-13 19:33:55.189: E/DatabaseUtils(403): at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
03-13 19:33:55.189: E/DatabaseUtils(403): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
03-13 19:33:55.189: E/DatabaseUtils(403): at android.os.Binder.execTransact(Binder.java:388)
03-13 19:33:55.189: E/DatabaseUtils(403): at dalvik.system.NativeStart.run(Native Method)
03-13 19:33:55.319: D/AbsListView(19933): unregisterIRListener() is called
我还没有看过你的代码,但我的第一个猜测是logcat的输出,它几乎准确地告诉你出了什么问题。您缺少所需的权限:
...this requires android.permission.INTERACT_ACROSS_USERS_FULL
编辑:好的,我检查了权限,这很糟糕。您将无法使用此权限,因为它是签名级别的权限。您在代码中使用的某些东西对普通开发人员来说是有限的。您可能已经解决了这个问题,但对于任何感兴趣的人来说,我也遇到了同样的问题(这在三星设备上似乎更常见),我发现的解决方案是授予读取外部存储权限
附带说明:只有当您的应用程序是本机应用程序时,才能在用户之间进行完整的交互。否则,我已将此权限添加到我的应用程序manifest.xml中,但它不起作用。是的,我已经注意到并编辑了我的答案,请发布更多您的logcat输出。您还可以发布更多吗?我需要查看权限问题的具体位置,为此,我需要查看SecurityException前后的大量logcat输出。