1

웹 링크가 특정 방식으로 시작되고 끝나는 애플리케이션 활동으로 웹 링크를 시작하는 방법이 있습니까?특정 방식으로 시작하고 끝나는 웹 링크의 Android 앱 활동 시작

사용자가 특정 웹 사이트에 대한 웹 링크를 클릭하면 (예 : 페이스 북이나 이메일을 통해 공유되고 웹 사이트 주소로 시작되지만 '이야기'로 끝나는 경우에만) 활동을 시작하려고합니다. .html ". 그래서 예를 들어 http://www.storyofmathematics.com/ 앱을 열 수 있지만 것 http://www.storyofmathematics.com/story.html

+1

String/Link를 가져 와서 "특정 문자열"과 일치하는지 확인하거나 [patterns] (http://developer.android.com/reference/java/util)을 사용하여 원하는대로 검사하면됩니다. /regex/Pattern.html) – hrskrs

+0

의도 필터 내에서 그렇게 할 수 있습니까? 앱과의 링크를 시작하는 옵션은 일치하는 경우에만 나타납니다. 예 : RobertEves92

+0

끈을 가져 가야하는 모든 것의 전나무. 그것을 파싱하거나,'patters (regex)'를 사용하여 원하는대로 필터하거나 나누십시오. 그것이 당신의 필요와 일치하는지 확인한 다음 원하는대로하십시오. – hrskrs

답변

1

이 활동 내에서 정규식을 실행하여

<activity 
     android:name=".WebActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 

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

그런 다음 적절한 텐트 필터와 매니페스트에 활동을 추가하여 달성 할 수

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class WebActivity extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Intent intent = getIntent(); 

     if (intent.getDataString().matches(
       "http:\\/\\/((www.)?)storyofmathematics.com\\/.*story.html")) { 
      // is match - do stuff 
     } else { 
      // is not match - do other stuff 
     } 
    } 
}