Android Broadcast Receiver Error: Class not found exception

我的未来我决定 提交于 2019-11-30 21:06:03
manu

from the android documentation on "android:exported" attribute for a receiver:

Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and "false" if not. If "false", the only messages the broadcast receiver can receive are those sent by components of the same application or applications with the same user ID. The default value depends on whether the broadcast receiver contains intent filters. The absence of any filters means that it can be invoked only by Intent objects that specify its exact class name. This implies that the receiver is intended only for application-internal use (since others would not normally know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the broadcast receiver is intended to receive intents broadcast by the system or other applications, so the default value is "true"

Since your receiver has child intents the default value for android:exported is true. Just state this explicitly and it should function fine.

ie,

<receiver android:name=".FirstRunBroadcastReceiver" android:exported="true">
<intent-filter>
    <action android:name="android.intent.action.PACKAGE_REPLACE"/>
    <data android:scheme="package" android:path="com.name.pkg.app_name">
</intent-filter>

Is package declaration in your FirstRunBroadcastReceiver class as follows?

package com.name.pkg.app_name;

According to your exception stack it should be so.

I am a newbie with android development and my solution was a simple one caused my stupidity. I had renamed my broadcastreceiver file and when I tried to run the application I received the classdefnotfound error. I ended up cleaning and rebuilding the project and the error was removed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!