从浏览器的URL链接打开我的Android应用程序

时间:2012-08-30 23:35:44

标签: android url

我知道我的问题在这里被多次询问但是我尝试了所有答案但仍然有问题 我的问题是我希望我的应用程序从移动浏览器中打开url

这是我在mainfeast.xml文件中写的内容

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

仍然无法解决这个问题 我想知道的是,如果我应该在Login.java活动中写任何东西,那么我应该为此写的是什么

谢谢

2 个答案:

答案 0 :(得分:2)

您可以使用以下清单文件从浏览器地址栏打开 abc://xyz.com

<?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>

这将在对话框中询问选项(带有您的应用程序名称)以打开此URL。

希望这对你有用。

享受。

答案 1 :(得分:0)

我解决了我的问题,这是我在清单文件上写的内容

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

我改变了android浏览器并从opera mini中打开了我的喜欢,它对我来说非常适合

相关问题