问题
I'm trying to launch my app as stated here: Launch custom android application from android browser
I've created intent-filter in my manifest:
<activity
android:name=".ui.BaseActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize">
<intent-filter>
<data android:scheme="http" android:host="somesite.com"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
But when I type in stock browser "somesite.com" - it loads "somesite.com" instead of launching my app. What's wrong?
P.S: this https://stackoverflow.com/a/13019256/1548085 doesn't help
回答1:
Typing a link in the browser doesn't start an intent: the browser just browses to that URL. The intent mechanism is only used when you follow (i.e. click) a link in the browser.
回答2:
This example launch my activity from android browser and display first 2 GET prams form URL
package com.example.openapp;
import java.util.List;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txt1 = (TextView) findViewById(R.id.textView1);
TextView txt2 = (TextView) findViewById(R.id.textView2);
try{
Uri data = getIntent().getData();
if(data != null){
String scheme = data.getScheme();
String host = data.getHost();
List<String> params = data.getPathSegments();
String first = params.get(0);
String second = params.get(1);
txt1.setText(first);
txt2.setText(second);
}
} catch (Exception e){
}
}
}
You need to add this in manifest and replace android host with your host:
<activity
android:name="com.example.openapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="example.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
回答3:
If you just put the "somesite.com" you have to put "http://somesite.com/" I realized that problem too as well.
来源:https://stackoverflow.com/questions/14713360/unable-to-launch-app-from-web-browser