我正在开发一个需要设置铃声通知的应用程序,因为我正在使用铃声选择器,它显示选择器上的铃声列表,我能够选择铃声,但下次再次设置铃声,铃声选择器不显示以前选择的铃声和通知附带默认铃声。我陷入其中,无法找到任何解决方案。提前谢谢。
这是我的代码
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
答案 0 :(得分:0)
好吧,我没有查看你的代码,但我的第一个猜测是logcat输出,它几乎可以告诉你什么是错误的。您缺少必要的权限:
...this requires android.permission.INTERACT_ACROSS_USERS_FULL
编辑:好的我检查了许可,这非常糟糕。您无法使用此权限,因为它是签名级别权限。您在代码中使用的东西对普通开发人员来说是有限的。
答案 1 :(得分:0)
你可能已经解决了这个问题,但是对于任何有兴趣的人 - 我都有同样的问题(在三星设备上似乎更常见),我发现的解决方案是给予READ_EXTERNAL_STORAGE权限。
作为旁注:INTERACT_ACROSS_USERS_FULL似乎只有在您的应用程序是本地应用时才有效,否则我