BroadcastReceiver for Package_Install not working

泪湿孤枕 提交于 2019-12-08 08:02:02

问题


@Override
public void onReceive(Context context, Intent intent) {

    // TODO Auto-generated method stub
    Toast.makeText(context, "Package Received", Toast.LENGTH_SHORT).show();
    Log.d("Package Installing", "Package Installing");
    String action=intent.getAction();
    if(action.equals(intent.ACTION_PACKAGE_INSTALL))
    {
        Toast.makeText(context, "Package Added", Toast.LENGTH_SHORT).show();
        Log.d("Package INstalling", "Package Installed");
    }
}

//My Manifest File:

<receiver android:name="com.example.anotherbroadcastreceiverexample.MyReceiver" android:enabled="true">
            <intent-filter><action android:name="android.intent.action.PACKAGE_INSTALL"/></intent-filter>

    </receiver>

回答1:


Could you try to modify your Manifest in the following way:

<intent-filter>
    <action android:name="android.intent.action.PACKAGE_INSTALL" />
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <data android:scheme="package"/>
</intent-filter>

UPDATE:

Check not PACKAGE_INSTALL check action PACKAGE_ADDED.



来源:https://stackoverflow.com/questions/15132023/broadcastreceiver-for-package-install-not-working

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