【问题标题】:Activity is ignoring meta-data when launched from code从代码启动时,活动忽略元数据
【发布时间】:2022-01-25 19:23:41
【问题描述】:

我在 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>

当 this 在意图过滤器中运行时

<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 

【问题讨论】:

    标签: android xamarin android-intent android-manifest trusted-web-activity


    【解决方案1】:

    您必须在第一个 Activity 上调用 Finish(),否则 TWA 应用程序不会显示启动屏幕。

    【讨论】:

      【解决方案2】:

      好吧,我猜你是直接将它添加到Manifest文件中,Xamarin Android通常通过正确的Activity文件中的属性来完成 下面是如何添加IntentFilterMetaData 的示例。

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

      祝你好运,如有疑问请随时回复

      【讨论】:

        猜你喜欢
        • 2018-08-25
        • 2020-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-28
        • 2013-07-10
        相关资源
        最近更新 更多