Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

android - launch application from browser url scheme

Thanks to many good posts, I have bee trying to launch my Android app from a browser link using the following code. Please help me adjust the manifest and href to call my application -

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.afs"
  android:versionCode="1"
  android:versionName="1.1">
  <supports-screens
  android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="false"
    android:resizeable="true"
    android:anyDensity="true"/>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-sdk android:minSdkVersion="9"></uses-sdk>
<application android:label="@string/app_name" android:icon="@drawable/afs"        android:debuggable="true">
      <activity android:name=".afs"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
         <intent-filter>
             <data android:scheme="afs.com.afs"/>
             <data android:name="android.intent.action.VIEW" />
             <category android:name="android.intent.category.DEFAULT" />
             <category android:name="android.intent.category.BROWSABLE" />
         </intent-filter>    
    </activity>
</application>

HTML code

<a href="afs.com.afs:75235">Launch Application</a>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Attributes from documentation scheme://host:port/path or pathPrefix or pathPattern.

You need to change define proprely scheme and host definition. If you don't specify scheme then all URI attributes will be ignored, and won't be applied.

You could use http URI scheme.

    <data android:scheme="http" android:host="afs.com.afs"/>

and in HTML

<a href="http://afs.com.afs:75235">Launch Application</a>

Or define own URL scheme.

    <data android:scheme="myapp" android:host="afs.com.afs"/>

and in HTML

<a href="myapp://afs.com.afs:75235">Launch Application</a>

PS.

Change this

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

to

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...