gpt4 book ai didi

java - 受信任的网络 Activity 无法启动 Activity ComponentInfo 服务 Intent 必须是明确的 : Intent

转载 作者:行者123 更新时间:2023-11-30 05:06:06 34 4
gpt4 key购买 nike

当启动 TwalauncherActivity 作为主 Activity 时,我在我的 Android 应用程序中集成了 Trusted Web Activity,应用程序没有打开,它突然停止并自动关闭。

我关注了this添加可信网络 Activity 的链接。

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

最佳答案

链接的演示已过时(链接目前也已断开,因为演示已移动 here)

这是更新的当前代码 LauncherActivity , 在支持库中。

支持 TWA 的支持库的最新版本托管在 JitPack 中暂时地。

近期会合并到官方支持库中。

关于java - 受信任的网络 Activity 无法启动 Activity ComponentInfo 服务 Intent 必须是明确的 : Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54573728/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com