我想打一个应用程序时,安装或删除其它应用程序,可以接收广播。 我的code
I want to make an app that can receive broadcast when another app installed or removed. my code
在manifset:
<receiver android:name=".apps.AppListener">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
</intent-filter>
</receiver>
在的AppListener:
in AppListener:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AppListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.v(TAG, "there is a broadcast");
}
}
但我不能接收任何广播。我觉得这个问题是关于permissins,任何想法?
but I can't receive any broadcast. I think this problem is about permissins, any idea?
感谢帮助。
在你的清单:
<receiver android:name=".apps.AppListener">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
</intent-filter>
</receiver>
意向过滤器标签之前添加行
Add the line before the intent-filter tag
<data android:scheme="package"/>
所以,你的表现应该是这样的:
So your manifest should look like this:
<receiver android:name=".apps.AppListener">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
我不知道有关PACKAGE_REMOVED意图,如果它实际上是可用的。
Am not sure about the PACKAGE_REMOVED intent in that if its actually is available.