2

I have to log when the user installs my app, for that I have registered ACTION_PACKAGE_ADDED broadcast in manifest and created a receiver. but the receiver is not triggering after installing the app. I have tried with registering broadcast ACTION_PACKAGE_ADDED instead of PACKAGE_ADDED, and it works. I have read most of the SO questions regarding this and tried, but nothing works for me.I giving my code below

Manifest

 <receiver android:name=".AppInstallReceiver">
        <intent-filter android:priority="1">
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>

Recevier

 @Override
public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
        String packageName = intent.getDataString();
        Log.i("Installed:", packageName + "package name of the program");
    }
    Log.d(TAG, "Action: " + intent.getAction());
    Uri data = intent.getData();
    Log.d(TAG, "The DATA: " + data);

}

Is there any problem with this code ?

droidev
  • 7,352
  • 11
  • 62
  • 94
  • I think it will work only after you start your app. because without starting app your broadcast receiver will not get initialized. – Garjpreet Singh Oct 27 '15 at 07:15
  • I have read it somewhere, is there any other solution to do this ? – droidev Oct 27 '15 at 07:18
  • No, actually it also depends on your device's ROM as almost every device has its own customized Android OS. So there is no solution until you have a rooted device. – Garjpreet Singh Oct 27 '15 at 07:29
  • @coderz there is some methods it seems.. Check this link http://stackoverflow.com/a/6051021/2769892 – droidev Oct 27 '15 at 18:03

0 Answers0