如何在安装或删除其他应用程序时让我的应用程序接收广播 [英] How to make my app receive broadcast when other applications are installed or removed

查看:26
本文介绍了如何在安装或删除其他应用程序时让我的应用程序接收广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个可以在安装或删除设备上的其他应用程序时接收广播的应用程序.

I want to make an app that can receive broadcast when other apps on the device are installed or removed.

我的代码

在清单中:

<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");
    }
}

但是我收不到任何广播.我认为这个问题是由应用权限引起的,知道吗?

but I can't receive any broadcast. I think this problem is due to app permissions, 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>

在 intent-filter 标签前添加一行

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 Intent 是否真的可用.

Am not sure about the PACKAGE_REMOVED intent in that if its actually is available.

这篇关于如何在安装或删除其他应用程序时让我的应用程序接收广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆