Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listen for app installed / upgraded broadcast message in Android

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 not malicious.

Follow Lookout, I write a simple app which listen broadcast message whenever each app is installed or upgraded. AFAIK, there are some type of IntentFilter for broadcast message, it is:

  • Intent.ACTION_PACKAGE_ADDED
  • Intent.ACTION_PACKAGE_CHANGED
  • Intent.ACTION_PACKAGE_INSTALL

I hope Intent.ACTION_PACKAGE_ADDED is the answer but it's wrong (ACTION_PACKAGE_ADDED: 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.) while ACTION_PACKAGE_INSTALL is deprecated.

Can anyone tell me a better way? Any help is welcome.

like image 467
anticafe Avatar asked Apr 24 '12 11:04

anticafe


People also ask

What is broadcast message in Android?

Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.

Can one app send a broadcast to another app?

For example, the Android system sends broadcasts when various system events occur, such as when the system boots up or the device starts charging. Apps can also send custom broadcasts, for example, to notify other apps of something that they might be interested in (for example, some new data has been downloaded).

Does broadcast receiver work in background?

The alternative is to register the receiver in the AndroidManifest. This ensures that the BroadcastReceiver runs all the time, even when the app is backgrounded. I chose this option because I want my application to receive Bluetooth events even when the app isn't in use (i.e. backgrounded). In my AndroidManifest.


2 Answers

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" />
like image 194
Deyu瑜 Avatar answered Sep 30 '22 20:09

Deyu瑜


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

like image 36
JohnnyLambada Avatar answered Sep 30 '22 19:09

JohnnyLambada