简体   繁体   English

如何检测设备上已安装新应用?

[英]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_ADDEDBroadcastReceiver

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.

相关问题 Android设备如何检测已安装应用程序? - How does an Android device detect that an app has already been installed? 如何检测应用程序是否已安装超过一天? - How to detect if app has been installed for more than a day? 使用移动网页 - PHP 和 JS 检测设备上是否安装了 Android 应用 - Detect if Android app has been installed on the device using a mobile web page - PHP and JS 如何检测设备上是否已安装Android App? - How to detect, if Android App was already installed at the device? Android:检测附近的设备是否安装了某些应用 - Android: detect if nearby device has certain app installed 如何检测应用程序是否安装在物理设备与虚拟设备/模拟器上? - How to detect if app is installed on a Physical Device Vs Virtual Device / Emulator? 如何知道应用是否已在android中成功安装 - How to know if an app has been installed successfully in android 是否可以记录设备上已安装的任何应用程序启动的次数? - Is there a way to log the number of times ANY installed app on my device has been launched? 如何检查新指纹是否已添加到设备? - How to check if a new fingerprint has been added to device? 如何检测Android手机是否已安装特定应用? - How to detect whether or not an Android phone has a specific app installed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM