简体   繁体   English

从代码启动时,活动忽略元数据

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

I've configured an activity in androidmanifest.xml:我在 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>

when this is run with this in the intent-filter当它在意图过滤器中运行时

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

it's displaying the splash screen fine but when I call it from a button click in the main activity:它可以正常显示启动画面,但是当我从主活动中的按钮单击调用它时:

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

it's ignoring all meta-data settings and flashing up a white screen.它忽略了所有元数据设置并闪烁白屏。

I've tried adding我试过添加

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

to this and tried to run it by calling:为此并尝试通过调用来运行它:

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

but this is just giving me:但这只是给了我:

No Activity found to handle Intent 

You have to call Finish() on the first activity or the TWA app doesn't display the splash screen.您必须在第一个活动上调用 Finish(),否则 TWA 应用程序不会显示初始屏幕。

Well, I am guessing that you are directly adding it to the Manifest file, Xamarin Android usually does it through attributes in the correct Activity file Below is an example of how to add an IntentFilter and a MetaData .好吧,我猜你是直接将它添加到 Manifest 文件中,Xamarin Android 通常通过正确的 Activity 文件中的属性来完成下面是如何添加IntentFilterMetaData的示例。

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

Goodluck, feel free to get back if you have queries祝你好运,如果您有任何疑问,请随时回复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM