2011-04-20 6 views
3

안드로이드 브라우저에서 내 활동을 시작하려면 어떻게해야합니까?android에서 브라우저에서 활동을 시작하는 방법은 무엇입니까?

나는 링크가 있다고 말하면, http://a.b.com입니다. 사용자가 안드로이드 브라우저에 URL을 입력하면 활동을 열어야합니다. 내 안드로이드 매니페스트에 다음과 같은 인 텐트 필터가 있습니다

<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="a.b.com"/> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT"/> 
    <category android:name="android.intent.category.BROWSABLE"/> 
</intent-filter> 
+0

귀하의''안에''가 있습니까? – Aleadam

+0

예 ................. –

+0

android : scheme = "http"으로 활동을 시작하는 방법을 알고 싶습니다. 전에 성공하지 못했습니다! : ( – Jorgesys

답변

2
+0

나는 인터넷에서 응답을 검색하고 모두 당신이 할 필요가 매니 페스트에 의도 필터를 제공합니다. 하지만 O를 부여 했음에도 불구하고 나는 결과를 얻지 못했습니다. 브라우저에 URL을 입력하면 앱이 시작되지 않습니다. ... –

+0

여기에 있습니다. 정확한 코드를 사용하고 있지만 작동하지 않습니다. 나도 여러 기사, 게시물, 스레드를 읽고 모두 말하지만 위의 코드는 우리가 필요로하는 것입니다. 답을 찾았습니까? – mrd

0

(질문의 제목에 집착하지 마십시오을 대답은 관련이..) 이 예제는 매니페스트에이를 추가하고 안드로이드 호스트 재치를 교체해야 할 첫번째 2 GET 유모차 형태의 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){ 
     }  
    } 
} 

을 안드로이드 브라우저에서 내 활동을 시작하고 표시 귀하의 호스트 :

 <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> 
관련 문제