android package restarted broadcast not working

删除回忆录丶 提交于 2019-12-11 01:58:12

问题


I am developing an app which needs a broadcast when app opens every time. I had registered the receiver in manifest like this.

<receiver android:name="package.broadcast.example" >
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_RESTARTED" />
        <data android:scheme="package"/>
    </intent-filter>
</receiver>

But i cant able to receive the broadcast. I spent 3 hours on this still i cant find wats the mistake. Can anyone refer me the working example of this broadcast. Thanks.


回答1:


Restarted Application/Package does not receive broadcast...

check the following link for details you can check this link

http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_RESTARTED




回答2:


do u have the following code which extends BroadcastReceiver, if not than try the following code:

         public class AutoConnection extends BroadcastReceiver {

     @Override
     public void onReceive(Context context, Intent intent) {
        if ((intent.getAction() != null)
                && (intent.getAction()
                        .equals("android.intent.action.PACKAGE_RESTARTED"))) {
            Toast.makeText(context, "Pacakge Restarted",
                    Toast.LENGTH_LONG).show();


        }
    }

     }

and in android manifest file add the following code:

       <receiver android:name=".AutoConnection" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_RESTARTED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>


来源:https://stackoverflow.com/questions/12724391/android-package-restarted-broadcast-not-working

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