如何检测设备上是否安装了新应用?

时间:2014-03-21 07:21:11

标签: android

CleanMaster应用程序如何检测到设备上已安装新应用程序?每当我安装一个新应用程序时,我会弹出一个询问是否要将应用程序移动到SD卡的弹出窗口。

我正在尝试编写类似的行为但无法找到方法来执行此操作。

3 个答案:

答案 0 :(得分:4)

ACTION_PACKAGE_ADDED广播意图,但正在安装的应用程序没有收到此信息。

<receiver android:name=".MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <data android:scheme="package" />
    </intent-filter>
</receiver>

答案 1 :(得分:1)

Android提供String android.content.Intent.ACTION_PACKAGE_ADDED ="android.intent.action.PACKAGE_ADDED"广播操作:设备上已安装新的应用程序包。数据包含包的名称。请注意,新安装的软件包不会收到此广播。

您可以为此BroadcastReceiver写一个Intent.ACTION_PACKAGE_ADDED

答案 2 :(得分:1)

为此你需要写一个这样的接收器类

public class AppInstallReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(final Context context, Intent intent) {
            //Perform Your opeartion

        }

    }

并在清单中注册。

  <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>
相关问题