android– 如何在安装或删除其他应用程序时使我的应用程序接收广播

android– 如何在安装或删除其他应用程序时使我的应用程序接收广播,第1张

概述我想创建一个可以在安装或删除设备上的其他应用程序接收广播的应用程序.我的代码在表现:<receiverandroid:name=".apps.AppListener"><intent-filterandroid:priority="100"><actionandroid:name="android.intent.action.PACKAGE_INSTALL"/>

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

我的代码

在表现:

<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中:

import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.Intent;import androID.util.Log;public class AppListener extends broadcastReceiver {@OverrIDepublic voID onReceive(Context context, Intent arg1) {    // Todo auto-generated method stub    Log.v(TAG, "there is a broadcast");    }}

但我无法收到任何广播.我认为这个问题是由于应用权限,任何想法?

谢谢你的帮助.

@H_403_24@解决方法:

在你的清单中:

<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标记之前添加该行

<data androID:scheme="package"/>

所以你的清单应该是这样的:

<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意图,如果它实际可用.

总结

以上是内存溢出为你收集整理的android – 如何在安装或删除其他应用程序时使我的应用程序接收广播全部内容,希望文章能够帮你解决android – 如何在安装或删除其他应用程序时使我的应用程序接收广播所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1103838.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存