简体   繁体   中英

On Android Ionic/Cordova, how can I start a CordovaActivity from within the service of a plugin, and have it load a deeplink?

From a cordova plugin, I'm starting a service which at some point has to start a CordovaActivity with a WebView:

public class MyServiceForSettingDocument extends Service {



    public IBinder onBind(Intent intent){
        return null;
    }

    public int onStartCommand(Intent intent, int flags, int startId){

        startActivity(new Intent(this, MyWebActivity.class));

        return START_STICKY;
    }
}

and MyWebActivity is

public class MyWebActivity extends CordovaActivity {

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // enable Cordova apps to be started in the background
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
            moveTaskToBack(true);
        }

        loadUrl("file:///android_asset/www/index.html/#/q/6");        

    }
}

where I'm trying to recreate loading a deeplink, such as has been defined in app.module.ts like:

IonicModule.forRoot(MyApp, {}, {
      links:[{component:DocPage, name:"q", segment:"q/:id"}]
    }),

and which in the webapp through ionic serve would load though http://localhost:8100/#/q/6

I'm getting the error:

E/AndroidProtocolHandler: Unable to open asset URL: file:///android_asset/www/index.html/#/q/6

What is the proper way to launch a CordovaActivity from an android service in an Ionic app, and have its WebView navigate according to a deeplink?

Many thanks for your attention!

I was wrong in way I was writing the deeplink in loadUrl . Correct string would be loadUrl("file:///android_asset/www/index.html#/q/6");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM