android.intent.action.PACKAGE_ADDED

String android.content.Intent.ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED"

Broadcast Action: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.

My include the following extras:

* EXTRA_UID containing the integer uid assigned to the new package.
* EXTRA_REPLACING is set to true if this is following an ACTION_PACKAGE_REMOVED broadcast for the same package.

This is a protected intent that can only be sent by the system

----------

当系统中新安装了一个软件或重新安装一个软件都会触发这个action的广播,
并发送intent给接收者,发送的intent中包话新安装应用的包名、系统指定给这个应用的ID、标识是否这个广播是在ACTION_PACKAGE_REMOVED广播发送之后发送的。

这种广播只能系统来发送。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要监听 Android 应用启动,可以使用 BroadcastReceiver 和 IntentFilter。具体步骤如下: 1. 创建一个 BroadcastReceiver 子类,实现 onReceive() 方法,该方法会在应用启动时被调用。 ```java public class AppInstallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) { String packageName = intent.getDataString().substring(8); // 获取应用包名 Log.d("AppInstallReceiver", "应用已安装:" + packageName); } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) { String packageName = intent.getDataString().substring(8); // 获取应用包名 Log.d("AppInstallReceiver", "应用已卸载:" + packageName); } } } ``` 2. 在 AndroidManifest.xml 中注册 BroadcastReceiver,并添加 IntentFilter。 ```xml <receiver android:name=".AppInstallReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> </intent-filter> </receiver> ``` 3. 在 Activity 或 Service 中注册 BroadcastReceiver。 ```java AppInstallReceiver receiver = new AppInstallReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addDataScheme("package"); registerReceiver(receiver, filter); ``` 这样,当有应用被安装或卸载时,AppInstallReceiver 的 onReceive() 方法会被调用,并输出相应的日志信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值