Implement Play Asset Delivery In flutter

Issue

How to implement on-demand Play Asset Delivery in flutter through methodchannels.

Actually i am trying to make a dashboard for some app which accesses assets using ContentProvider so i thought play asset delivery might work here.
I know that same can be achieved using deferred components and I have already tried deferred components which is provided by flutter.
You can find it here

Currently, there is an issue with flutter which causes assets to not load when deferred. You can find a link to the issue here.

I do not have any idea of native language and this is the only option I have right now which is implementing a methodchannel so any help would be appreciated

Solution

I dont think you can achieve the same thing using play asset delivery. You can try a workaround for this
Disable android:enabled by default by adding android:enabled="false" in your content provider and then use below methodchannel to enable it later

package dev.blah.blah;

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();
            }
          }
        );
          }
  }

Answered By – Dhanraj Priyadarshi

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *