我正在開發一個應用程序,需要設置鈴聲通知,因爲我使用的鈴聲選擇器,它顯示選擇器上的鈴聲列表,我可以選擇鈴聲,但又設置鈴聲下次,鈴聲選擇器不顯示先前選擇的鈴聲,並且通知還帶有默認鈴聲。我陷入了困境,無法找到任何解決方案。提前致謝。無法設置鈴聲通知android
這裏是我的代碼
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中我得到這個錯誤,但在谷歌我沒有找到任何解決這個
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
我已經添加了此許可我的應用程序的manifest.xml,但它是不工作的好友 –
是的,我已經注意到並編輯我的答案,請張貼更多的logcat輸出。 –
@ Xaver Kapeller:我已經更新了我的logcat輸出 –