簡體   English   中英

從代碼啟動時,活動忽略元數據

[英]Activity is ignoring meta-data when launched from code

我在 androidmanifest.xml 中配置了一個活動:

<activity android:name="com.google.androidbrowserhelper.trusted.LauncherActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name">
        <meta-data
           android:name="android.support.customtabs.trusted.DEFAULT_URL"
           android:value="https://www.xxxx.com/app" />
        <meta-data android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE" android:resource="@drawable/icon"/>
        <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR" android:resource="@color/splash"/>
        <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION" android:value="3000"/>
        <meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY" android:value="${applicationId}.fileprovider"/>

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.support.customtabs.action.CustomTabsService" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="xxxx.com" android:pathPrefix="/app" />
        </intent-filter>
    </activity>

當它在意圖過濾器中運行時

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

它可以正常顯示啟動畫面,但是當我從主活動中的按鈕單擊調用它時:

Intent intent = new Intent(this, typeof(Com.Google.Androidbrowserhelper.Trusted.LauncherActivity));
intent.SetData(Android.Net.Uri.Parse("https://www.xxxx.com/app/"));
StartActivity(intent);

它忽略了所有元數據設置並閃爍白屏。

我試過添加

<action android:name="com.mycompany.product.VIEW" />

為此並嘗試通過調用來運行它:

Intent intent = new Intent("com.mycompany.product.VIEW", Android.Net.Uri.Parse("https://www.xxxx.com/app/"));
StartActivity(intent);

但這只是給了我:

No Activity found to handle Intent 

您必須在第一個活動上調用 Finish(),否則 TWA 應用程序不會顯示初始屏幕。

好吧,我猜你是直接將它添加到 Manifest 文件中,Xamarin Android 通常通過正確的 Activity 文件中的屬性來完成下面是如何添加IntentFilterMetaData的示例。

 [Activity(....)]
 [IntentFilter(new[]{Intent.ActionSearch})] // 
 [MetaData("android.app.searchable", Resource="@xml/searchable")]
 public class MainActivity : AppCompatActivity
 { ...... }

祝你好運,如果您有任何疑問,請隨時回復

暫無
暫無

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

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