简体   繁体   English

在Android Ionic / Cordova上,如何从插件服务中启动CordovaActivity,并使其加载深度链接?

[英]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: 从cordova插件中,我正在启动一项服务,该服务有时必须使用WebView启动CordovaActivity:

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 MyWebActivity

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: 我试图在其中重新创建加载app.module.ts链接的地方,例如在app.module.ts定义的app.module.ts

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 以及通过ionic serve在webapp中通过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? 从Ionic应用程序中的android服务启动CordovaActivity并使其WebView根据Deeplink进行导航的正确方法是什么?

Many thanks for your attention! 非常感谢您的关注!

I was wrong in way I was writing the deeplink in loadUrl . 我在loadUrl编写loadUrl Correct string would be loadUrl("file:///android_asset/www/index.html#/q/6"); 正确的字符串应该是loadUrl("file:///android_asset/www/index.html#/q/6");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Android中的Cordova插件访问CordovaActivity appView? - How to get access to CordovaActivity appView from cordova plugin in android? 如何修复离子科尔多瓦建立谷歌服务插件的Android? - how to fix ionic cordova build android for google service plugin? 如何检测Android插件中的“最近”菜单中的Cordova应用已被删除? - How can I detect when a Cordova app has been removed from the recents menu, from within an Android plugin? 如何使用Ionic和Cordova从设备库中加载图像? - How can I load an image from the device gallery using Ionic and Cordova? 如何从Cordova插件中覆盖与Android生命周期相关的功能 - How to override Android lifecycle related functions from within a Cordova plugin 如何在Cordova Android应用程序中深度链接到特定页面? - How to deeplink to specific page in cordova android app? 从Cordova插件启动android活动 - Start android activity from cordova plugin 从 ionic 4 更新到 5 ionic cordova android livereload 错误-复制插件 - Updated from ionic 4 to 5 ionic cordova android livereload error - Copy Plugin Android Cordova 6.0 CordovaActivity无法加载外部网站 - android Cordova 6.0 CordovaActivity not loading external website 如何从不在Android中相同项目中的活动启动服务? - How can I start a service from an activity that is not in the same project in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM