在开发者控制台中,我收到一些有关以下异常的错误报告:
java.lang.RuntimeException: Unable to instantiate receiver com.cypressworks.changelogviewer.InstallReciever: java.lang.ClassNotFoundException: com.cypressworks.changelogviewer.InstallReciever in loader dalvik.system.PathClassLoader[/mnt/asec/com.cypressworks.changelogviewer-1/pkg.apk]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1773)
at android.app.ActivityThread.access$2400(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:845)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.cypressworks.changelogviewer.InstallReciever in loader dalvik.system.PathClassLoader[/mnt/asec/com.cypressworks.changelogviewer-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764)
... 10 more
用户添加了消息,当他在市场上更新应用程序时发生此错误。
我自己从未经历过这个例外,尽管我猜测原因。接收方收听android.intent.action.PACKAGE_REPLACE
和android.intent.action.PACKAGE_ADDED
。当应用程序本身更新时,广播将被发送到接收方,但在它接收时,它已被删除。
我的猜测是否合理以及如何避免此错误?
这是清单条目:
<receiver
android:name=".InstallReciever"
android:exported="false"
android:enabled="true">
<intent-filter>
<action
android:name="android.intent.action.PACKAGE_REPLACED" />
<action
android:name="android.intent.action.PACKAGE_ADDED" />
<data
android:scheme="package" />
</intent-filter>
</receiver>
以下是代码:
public class InstallReciever extends BroadcastReceiver {
@Override
public void onReceive(final Context c, final Intent intent) {
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(c);
//Checking some preferences...
//Creating a notification
final String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) c
.getSystemService(ns);
final int icon = R.drawable.icon;
final CharSequence tickerText = c.getString(R.string.notification_text);
final long when = System.currentTimeMillis();
final Notification notification = new Notification(icon, tickerText,
when);
final CharSequence contentText = c.getString(R.string.app_name);
final Intent notificationIntent = new Intent(c,
ChangeListActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent contentIntent = PendingIntent.getActivity(c, 0,
notificationIntent, 0);
notification.setLatestEventInfo(c, tickerText, contentText,
contentIntent);
mNotificationManager.notify(0, notification);
}
}