简体   繁体   中英

Activity is ignoring meta-data when launched from code

I've configured an activity in 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.

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 .

 [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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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