Listen for app installed / upgraded broadcast message in Android

前端 未结 4 1384
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 05:59

Using Lookout app (https://play.google.com/store/apps/details?id=com.lookout), I see every time I install or upgrade app, it\'ll automatically scan this app to ensure it\'s

相关标签:
4条回答
  • 2020-12-06 06:43

    You need to have two applications, one of them monitors the other app's installation and upgrades.

    0 讨论(0)
  • 2020-12-06 06:46

    You can try this receiver and permission. (But this seem only work in /system/app)^^"

    <receiver
        android:name="com.your.receiver"
        android:enabled="true"
        android:exported="true" >
                <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>
     <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
    
    0 讨论(0)
  • 2020-12-06 06:46

    Android won't send your a broadcast that you're being installed, but Google Play will. This won't help if your app is loaded through Amazon or through the debugger, but it does allow you to run code if your app is installed through Google Play: https://developers.google.com/android/reference/com/google/android/gms/tagmanager/InstallReferrerReceiver

    0 讨论(0)
  • 2020-12-06 06:47

    If you are installing an application A, all other applications on the device will get the Intent that application A is the newly installed application but not A itself as it doesn't seem of any use. Now A will get broadcasts if other apps are later installed or changed.

    If you want to find out at when your app was installed or some other app's the last install or update time, you can always use PackageManager:

    PackageManager pm = context.getPackageManager();
    ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
    String appFile = appInfo.sourceDir; 
    long installed = new File(appFile).lastModified();
    

    here app.package.name is the package name of the app you want to find out the install time. If you want to use it for your app, pass in your app's package name.

    0 讨论(0)
提交回复
热议问题