2010-03-05 5 views
4

사용자가 특정 URL을 탐색 할 때 응용 프로그램을 시작하려고합니다. 나는 몇 가지 예를 발견했으며 그들은 모두 매니 페스트에서 동일한 것들을 가지고 있지만 그것은 나를 위해 일하지 않습니다. 나는 인 텐트 필터를 리시버뿐만 아니라 액티비티 밑에 두었다. 활동에 따라, 나는 onNewIntent을 사용하고 리시버에서 때, 나는 onReceiveIntent를 사용하여 시도했을 때, 간단한 Log.i 호출로 둘 경우 URL에서 활동 시작

<intent-filter> 
    <action android:name="android.intent.action.VIEW"></action> 
    <category android:name="android.intent.category.DEFAULT"></category> 
    <category android:name="android.intent.category.BROWSABLE"></category> 
    <data android:host="www.urbandictionary.com" android:scheme="http"></data> 
</intent-filter> 

볼 수

: 여기

내 매니페스트 조각입니다 해고 됐는지 아닌지. 나는 운이별로 없다.

+0

관련 질문 :이 방법을 사용 http://stackoverflow.com/questions/2448213/how-to-implement-my-very-own-uri-schema-on-android – Casebash

답변

7

나는 나의 manifest.xml 파일이 사용

<activity android:name=".SomeName"> 
    <intent-filter> 
     <category android:name="android.intent.category.ALTERNATIVE" /> 
     <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.com" android:scheme="http" /> 
    </intent-filter> 
</activity> 

이 활동 SomeName을 시작합니다. 나는 안드로이드에서 www를 사용하지 않는다 : 호스트 부분은 아마 차이를 만들 것이다.

가 활동하면 (예를 들어)를 사용하여 .COM 뒤에 데이터를 얻을 수 있습니다 시작하면 :

Uri data = getIntent().getData(); 
if(data != null && data.getPathSegments().size() >= 2){ 
    List<String> params = data.getPathSegments(); 
    String somestuff = params.get(0); 
} 

편집 : 당신이 활동 내에서 호스트를 확인 할 수 wan't 경우,

data.getHost(); 
+0

은 안드로이드이 작품 사탕 과자? –

+0

예, 작동합니다;) –

+0

여기를 안내해주세요. http://stackoverflow.com/q/29116574/1071545 –