2013-02-05 47 views
0

我尝试启动我的应用程序的说明这里:Launch custom android application from android browser
我创建intent-filter在我的清单:无法从网络浏览器启动应用程序

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

但是,当我在股票浏览器中键入“somesite .com“ - 它加载”somesite.com“,而不是启动我的应用程序。怎么了?
P.S:此https://stackoverflow.com/a/13019256/1548085不利于

回答

2

在浏览器中键入链​​接并不意味着:浏览器只是浏览到该URL。意图机制仅在遵循(即单击)浏览器中的链接时使用。

0

这个例子从Android的浏览器中启动我的活动,并显示第一二送童车形式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){ 
     }  
    } 
} 

您需要在清单中添加这和您的主机取代的Android主机:

 <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> 
相关问题