[英]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.