簡體   English   中英

受信任的Web活動無法啟動活動ComponentInfo Service Intent必須明確:Intent

[英]Trusted web activity Unable to start activity ComponentInfo Service Intent must be explicit: Intent

當啟動TwalauncherActivity作為主要Activity時,我已經在Android App中集成了Trusted Web Activity,該App沒有打開,它突然停止並自動關閉。

我已點擊鏈接添加“受信任的網絡活動”。

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

鏈接的演示已過時(由於演示已移至此處 ,鏈接當前也已斷開)

這是支持庫中更新LauncherActivity的當前代碼。

支持TWA的最新版本的支持庫暫時托管在JitPack中

它將在不久的將來合並到官方支持庫中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM