1

So i have a simple app and a content provider which looks like this :

    <provider
            android:name="org.kustom.api.Provider"
            android:authorities="${applicationId}.kustom.provider"
            android:exported="true"
            android:enabled="false"
            tools:ignore="ExportedContentProvider">
        <intent-filter>
            <action android:name="org.kustom.provider.WALLPAPERS"/>
            <action android:name="org.kustom.provider.WIDGETS"/>
            <action android:name="org.kustom.provider.KOMPONENTS"/>
            <action android:name="org.kustom.provider.LOCKSCREENS"/>
        </intent-filter>
    </provider>

I want to disable this by default and enable it when license checker succeeds. I am using flutter so,I have already made a methodchannel which enables and disables content provider but it is not working.

Here's my methodchannel

package dev.dhanraj.kwgt.test.dashboard;

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import android.content.ContextWrapper;
import android.widget.Toast;

public class MainActivity extends FlutterActivity {
  private static final String CHANNEL = "dev.dhanraj.kwgt.test.dashboard";

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
  super.configureFlutterEngine(flutterEngine);
    new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
        .setMethodCallHandler(
          (call, result) -> {
            // Note: this method is invoked on the main thread.
            if (call.method.equals("enable")) {
              ContextWrapper aContext = new ContextWrapper(getApplicationContext());
              aContext.getPackageManager().setComponentEnabledSetting(new android.content.ComponentName(aContext, "org.kustom.api.Provider"), android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 1);
              result.success(null);
              Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
            } else{
              result.notImplemented();
            }
          }
        );
          }
  }

It makes a toast of done but doesn't affects ContentProvider as i can still see my assets in kwgt

1 Answers1

1

Thanks to Mike for figuring out the issue i was actually using COMPONENT_ENABLED_STATE_DISABLED and this should have been COMPONENT_ENABLED_STATE_ENABLED instead.