1

Im currently disabling an application via setApplicationEnabledSetting(String, int, int)

The application is actually disabling itself. I would expect upon re-installation of the app, the app would re-enable itself, however this isnt the case.

Is there a particular setting required in the manifest to make this work. (Ive tried setting enabled=true)

Thanks

Im currently disabling all components apart from a broadcast receiver and am trying to catch the installation process to re-enable all the other components again. Which is nasty to say the least

McP
  • 813
  • 1
  • 8
  • 16

1 Answers1

0

One way to do this is to listen to package installation broadcasts and take action accordingly.

Example

Manifest:

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

Receiver:

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
            final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
            final String packageName = intent.getData().getSchemeSpecificPart();
            if (replacing && "my.package.name".equals(packageName)) {
                // Re-enable the other components
            }
        }
    }

}

Hope this helps.

ozbek
  • 20,955
  • 5
  • 61
  • 84
  • 1
    Thanks for the post. It doesnt directly answer the question, as this requires atleast one component to remain running, but it does provide the desired result. Also it would be best to use android.intent.action.PACKAGE_REPLACED or android.intent.action.MY_PACKAGE_REPLACED. Ill leave the question opened for a few days before I accept an answer. – McP Oct 30 '13 at 15:23
  • _It doesnt directly answer the question, as this requires atleast one component to remain running_ -- No additional component is required, you can the above filters to your existing broadcast receiver: _Im currently disabling all components **apart from a broadcast receiver**_ – ozbek Oct 30 '13 at 17:45