Open my Android app from URL link from browser

2019-02-15 16:12发布

问题:

i know my question is been asked for many times here but i tried all the answers and still have the problem my problem is that i want my application to be opened throw url from the mobile browser

here is what i write in the mainfeast.xml file

       <activity
        android:name=".Login"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:host="" android:scheme="mpay2park" />
        </intent-filter>

and still can't solve this issue what I want to know that if I should write anything in the Login.java activity or not and what is the URLthat I should to write for this

Thank you

回答1:

You can use below manifest file to open abc://xyz.com from browser addressbar :

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.sample.openfrombrowser.MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleInstance" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="xyz.com"
                android:scheme="abc" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="google.co.in"
                android:pathPrefix="/"
                android:scheme="http" />
            <data
                android:host="www.google.co.in"
                android:pathPrefix="/"
                android:scheme="http" />
        </intent-filter>
    </activity>
</application>

This will ask option(with your application name) in dialog to open this url.

hope so this will work for you.

Enjoy.



回答2:

I solve my problem ,here is what i write on mainfest file

  <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="mpay2park"/>
        </intent-filter>

and I change the android browser and open my like from opera mini and it works perfect for me



标签: android url