Ken*_*fer 10 android android-intent android-package-managers
我有一个应用程序,它保存设备上安装的内部开发应用程序的日志.安装后,将调用Intent.PACKAGE_ADDED的广播接收器,并使用以下代码记录包名称:
public class NewInstallReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Bundle b = intent.getExtras();
int uid = b.getInt(Intent.EXTRA_UID);
String[] packages = context.getPackageManager().getPackagesForUid(uid);
ApplicationService appService = new ApplicationService(context);
appService.ApplicationInstalled(packages);
}
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是当使用Intent.PACKAGE_REMOVED的广播接收器时,通过唯一ID(UID)对包的所有引用都会返回空信息(如您已经卸载的那样,正如您所期望的那样).我有一个临时解决方案,但它不是很优雅,对于下一个版本,我希望有更清晰的代码.代码应如何工作的示例:
public class RemoveApplicationReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Bundle b = intent.getExtras();
int uid = b.getInt(Intent.EXTRA_UID);
String[] packages = context.getPackageManager().getPackagesForUid(uid);
ApplicationService appService = new ApplicationService(context);
appService.ApplicationRemoved(packages);
}
}
Run Code Online (Sandbox Code Playgroud)
所以回顾一下,问题是:
删除程序后,如何在广播接收器中为Intent.PACKAGE_REMOVED引用包名称.
谢谢
And*_*eas 15
软件包名称位于您从BroadcasReceiver获取的Intent中,使用"getData()"函数,还有已安装/未安装软件包的ComponentMame.
| 归档时间: |
|
| 查看次数: |
10588 次 |
| 最近记录: |