无法使用BroadcastReceiver接收ACTION_PACKAGE_ADDED / ACTION_PACKAGE_REMOVED

时间:2014-03-10 00:01:30

标签: android android-intent broadcastreceiver

我已经编写了一个启动器 - 一切正常但我似乎无法在外部安装或卸载应用程序时更新屏幕(例如,使用“设置”)。

这是我的清单:

<receiver android:name=".Receiver">
    <intent-filter>
        <action android:name="ACTION_PACKAGE_ADDED"/>
        <action android:name="ACTION_PACKAGE_REMOVED"/>
    </intent-filter>
</receiver>

我确实有一个警告说“导出的接收器不需要许可”(即使通过阅读我也不太了解。)

在我的BroadcastReceiver中,不调用onReceive()方法。

public class Receiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context ctx, Intent intent) {
        Log.d("iHome", "received action!"); // replaced by refresh method
    }    
}

我还尝试注册(在onCreate中)并动态注销(在onDestroy中)广播接收器,但似乎也没有任何效果。

1 个答案:

答案 0 :(得分:0)

替换动作名称
android.intent.action.PACKAGE_REMOVED

并且

android.intent.action.PACKAGE_ADDED