当我调用 RingtoneManager.setActualDefaultRingtoneUri 方法来设置来电时的新铃声并且这次播放旧铃声但新铃声在后面更新并下次播放时,我收到以下警告消息。
W/BackupManagerService(61):dataChanged 但没有参与者 pkg='com.android.providers.settings' uid=10037
呼叫监听器
class MyCallListener extends PhoneStateListener {
Uri newUri = null;
Uri oldUri = null;
Context context;
public MyCallListener(Context context) {
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
Log.i("RandomRingtone:CallListener", "State : " + state);
Log.i("RandomRingtone:CallListener", "IncomingNumber : "
+ incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.i("RandomRingtone:CallListener", "Changing Ringtone");
Log.i("RandomRingtone:CallListener",
"Old Ringtone : "
+ RingtoneManager.getActualDefaultRingtoneUri(
context, RingtoneManager.TYPE_RINGTONE));
File k = new File("/sdcard/", "01 - Chinna Chinna.mp3");
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "My Song title");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg");
values.put(MediaStore.Audio.Media.ARTIST, "Some Artist");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
.getAbsolutePath());
// Line below is major because we need to delete old entry
context.getContentResolver().delete(
uri,
MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath()
+ "\"", null);
newUri = context.getContentResolver().insert(uri, values);
oldUri = RingtoneManager.getActualDefaultRingtoneUri(context,
RingtoneManager.TYPE_RINGTONE);
// On call you replace the ringtone with your own mUri
RingtoneManager.setActualDefaultRingtoneUri(context,
RingtoneManager.TYPE_RINGTONE, newUri);
// Settings.System.putString(context.getContentResolver(),
// Settings.System.RINGTONE, newUri.toString());
Log.i("RandomRingtone:CallListener",
"New Ringtone : "
+ RingtoneManager.getActualDefaultRingtoneUri(
context, RingtoneManager.TYPE_RINGTONE));
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i("RandomRingtone:CallListener", "Restore the default ringtone");
Log.i("RandomRingtone:CallListener",
"Old Ringtone : "
+ RingtoneManager.getActualDefaultRingtoneUri(
context, RingtoneManager.TYPE_RINGTONE));
// Restore the default ringtone
RingtoneManager.setActualDefaultRingtoneUri(context,
RingtoneManager.TYPE_RINGTONE, oldUri);
// Settings.System.putString(context.getContentResolver(),
// Settings.System.RINGTONE, oldUri.toString());
Log.i("RandomRingtone:CallListener",
"New Ringtone : "
+ RingtoneManager.getActualDefaultRingtoneUri(
context, RingtoneManager.TYPE_RINGTONE));
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
广播接收器
public class StartServicesAtStartUp extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.w("DEBUG", "StartServicesAtStartUp");
TelephonyManager mTelephonyMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
MyCallListener callListener = new MyCallListener(context);
mTelephonyMgr
.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
Log.w("DEBUG", "Call Listener Added....");
}
}
安卓清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.randomringtone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- <activity
android:label="@string/app_name"
android:name=".RandomRingtoneActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> -->
<!--
<receiver android:name="MyPhoneReceiver" >
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
-->
<receiver android:name="StartServicesAtStartUp" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
我被困在这个问题上。任何帮助表示赞赏。
提前致谢。
问候, 迪帕克