【问题标题】:Trusted web activity Unable to start activity ComponentInfo Service Intent must be explicit: Intent受信任的 Web 活动无法启动活动 ComponentInfo 服务意图必须是明确的:意图
【发布时间】:2019-02-08 04:49:49
【问题描述】:

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

我已关注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();
    }
}

【问题讨论】:

  • 你在AndroidManifest.xml文件中定义了activity吗?

标签: java android trusted-web-activity


【解决方案1】:

链接的演示已过时(链接目前也已损坏,因为演示已被移动here

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

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

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

【讨论】:

    猜你喜欢
    • 2015-03-06
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    相关资源
    最近更新 更多