启动TwalauncherActivity作为主要Activity时,我已经在Android App中集成了Trusted Web Activity,App没有打开,它突然停止并自动关闭。
我已点击this链接来添加“受信任的网络活动”。
Logcat:-
FATAL EXCEPTION: main
Process: com.therightdoctors.cathlab, PID: 2906
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.therightdoctors.cathlab/com.therightdoctors.cathlab.TwaLauncherActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=android.support.customtabs.action.CustomTabsService }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=android.support.customtabs.action.CustomTabsService }
TwaLauncherActivity.java:-
package com.therightdoctors.dpmpatient;
import android.net.Uri;
import android.os.Bundle;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AppCompatActivity;
public class TwaLauncherActivity extends AppCompatActivity
implements TwaSessionHelper.TwaSessionCallback {
private static final String TWA_ORIGIN = "https://dpmp.therightdoctors.com";
private static final String TARGET_URL = TWA_ORIGIN;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twa_launcher);
Uri originUri = Uri.parse(TWA_ORIGIN);
TwaSessionHelper twaSessionHelper = TwaSessionHelper.getInstance();
twaSessionHelper.setTwaSessionCallback(this);
twaSessionHelper.bindService(this, originUri);
}
@Override
protected void onDestroy() {
super.onDestroy();
TwaSessionHelper twaSessionHelper = TwaSessionHelper.getInstance();
twaSessionHelper.setTwaSessionCallback(null);
}
public void openTwa() {
TwaSessionHelper twaSessionHelper = TwaSessionHelper.getInstance();
// Set an empty transition from TwaLauncherActivity to the TWA splash screen.
CustomTabsIntent customTabsIntent = twaSessionHelper.createIntentBuilder()
.setStartAnimations(this, 0, 0)
.build();
Uri openUri = Uri.parse(TARGET_URL);
twaSessionHelper.openTwa(this, customTabsIntent, openUri);
}
@Override
public void onTwaSessionReady() {
openTwa();
}
@Override
public void onTwaSessionDestroyed() {
}
@Override
public void onTwaOpened() {
finishAndRemoveTask();
}
}
答案 0 :(得分:0)
链接的演示已过时(随着演示here的移动,链接当前也已断开)
这是支持库中更新LauncherActivity的当前代码。
支持TWA的最新版本的支持库暂时托管在JitPack中。
它将在不久的将来合并到官方支持库中。