2013-07-28 1 views
4

의도 필터가있는 webview에서 내 앱의 특정 활동으로 리디렉션 할 특정 URL이 있습니다. How to implement my very own URI scheme on Android은 브라우저 페이지에서이 작업을 수행하는 방법을 설명했지만 웹보기를 통해 해당 URL에 액세스 할 때 동일한 인 텐트 필터가 작동하지 않습니다. 이러한 웹보기 링크를 잡기 위해이 인 텐트 필터에 추가해야 할 다른 것이 있습니까?인 텐트 필터로 안드로이드 webview 리디렉션

<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="myurl.com/stuff" android:scheme="http"></data> 
    </intent-filter>` 

답변

4

나는 텐트 필터와 webviews 그냥 매니페스트의 의도를 선언과 함께 일 없어 그리고 나는 그들이이 안되는 것 같아요. (왜 그런지 궁금합니다 ...) 웹 뷰에서 열어서 의도를 만들려고 할 때 URL을 잡는 방법이라고 생각합니다.

그런 활동 레지스터 매니페스트에 다음과 같이

<activity android:name=".PretendChat"> 
     <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="chat" ></data> 
      <data android:scheme="testing"></data> 
      <data android:pathPattern=".*"></data> 
     </intent-filter> 
    </activity> 

당신은 다음과 같은 링크를 클릭 할 때 열리는 PretendChat 활동 기대 "테스트 : 채팅 //"는 웹보기의 내부 . 이 문제가 발생하려면 에 webview에서 사용중인 webview 클라이언트에 다음 코드가 필요합니다. webview를 시작하는 활동의 이름을 WebviewActivity라고 가정합니다.

private class TestWebViewClient extends WebViewClient  { 


    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 

     try { 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setData(Uri.parse(url)); 
      WebviewActivity.this.startActivity(intent); 


     } catch(ActivityNotFoundException e) { 

      Log.e(LOGTAG,"Could not load url"+url); 
     } 

     return super.shouldOverrideUrlLoading(view, url);  


    } 
} 
+0

이 솔루션은 웹보기를 제어 할 수있는 경우에만 사용할 수 있습니다. 즉, 웹보기 개체 구현 소스 코드를 재정의하는 경우에만 사용할 수 있습니다. 이 webview가 컴파일/jar/libarary 형식 일 때 수정하면 소스 코드가 없습니다. 그러면 특정 URL을 기반으로하는 몇 가지 활동으로 리디렉션되는 방식입니다. –