我在应用程序中以编程方式设置通知铃声。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == Activity.RESULT_OK && requestCode == 5)
{
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Log.i("Speak", "I picked this ringtone " + uri);
if (uri != null)
{
RingtoneManager.setActualDefaultRingtoneUri(this, resultCode, uri);
Settings.System.putString(getContentResolver(), Settings.System.NOTIFICATION_SOUND, uri.toString());
notification_uri = uri.toString();
}
}
}
它在 Android 4.0.4 上运行良好。它在 Android 4.1.2 上使应用程序崩溃
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5, result=-1, data=Intent { (has extras) }} to activity {com.aa.me.vianet85/com.aa.me.vianet.activity.MainTabHost}: java.lang.NullPointerException: key == null
at android.app.ActivityThread.deliverResults(ActivityThread.java:3208)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3251)
at android.app.ActivityThread.access$1200(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4962)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: key == null
at android.os.Parcel.readException(Parcel.java:1431)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:420)
at android.content.ContentResolver.insert(ContentResolver.java:866)
at android.provider.Settings$NameValueTable.putString(Settings.java:683)
at android.provider.Settings$System.putString(Settings.java:945)
at android.media.RingtoneManager.setActualDefaultRingtoneUri(RingtoneManager.java:825)
at com.aa.me.vianet.activity.MainTabHost.onActivityResult(MainTabHost.java:552)
at android.app.Activity.dispatchActivityResult(Activity.java:5344)
at android.app.ActivityGroup.dispatchActivityResult(ActivityGroup.java:126)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3204)
... 11 more
java.lang.NullPointerException: key == null
at android.os.Parcel.readException(Parcel.java:1431)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:420)
at android.content.ContentResolver.insert(ContentResolver.java:866)
at android.provider.Settings$NameValueTable.putString(Settings.java:683)
at android.provider.Settings$System.putString(Settings.java:945)
at android.media.RingtoneManager.setActualDefaultRingtoneUri(RingtoneManager.java:825)
at com.aa.me.vianet.activity.MainTabHost.onActivityResult(MainTabHost.java:552)
at android.app.Activity.dispatchActivityResult(Activity.java:5344)
at android.app.ActivityGroup.dispatchActivityResult(ActivityGroup.java:126)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3204)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3251)
at android.app.ActivityThread.access$1200(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4962)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
怎么了 ?