[英]How to detect that new app has been installed on the device?
How does CleanMaster app detect that a new app has been installed on the device? CleanMaster应用程序如何检测到设备上已安装新应用程序? Whenever I install a new app, I get a popup asking if I want to move the app to SD card. 每当我安装新应用程序时,我都会弹出一个对话框,询问是否要将应用程序移至SD卡。
I am trying to code similar behaviour but cannot find a way to do it. 我正在尝试编写类似的行为,但找不到解决方法。
There is the ACTION_PACKAGE_ADDED Broadcast Intent, but the application being installed doesn't receive this. 有ACTION_PACKAGE_ADDED广播意图,但是正在安装的应用程序未收到此消息。
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Android provides String android.content.Intent.ACTION_PACKAGE_ADDED ="android.intent.action.PACKAGE_ADDED"
Broadcast Action: A new application package has been installed on the device. Android提供了String android.content.Intent.ACTION_PACKAGE_ADDED ="android.intent.action.PACKAGE_ADDED"
广播操作:设备上已安装新的应用程序包。 The data contains the name of the package. 数据包含包的名称。 Note that the newly installed package does not receive this broadcast. 请注意,新安装的程序包不会收到此广播。
You can write a BroadcastReceiver
receiving the Intent.ACTION_PACKAGE_ADDED
for that. 您可以Intent.ACTION_PACKAGE_ADDED
编写一个接收Intent.ACTION_PACKAGE_ADDED
的BroadcastReceiver
。
For this You need to write a receiver class like this 为此,您需要编写这样的接收器类
public class AppInstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
//Perform Your opeartion
}
}
And register it in manifest like. 并以清单形式注册。
<receiver android:name="com.example.AppInstallReceiver" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.