2016-10-27 4 views
1

두 개의 URL이 있습니다. 예를 들어 12345http://host.com/abc/def/12345 경로 상 다른 활동 열기/접두사 및/abc/def

  1. http://host.com/abc/12345
  2. - 신분증입니다.

    이 URL에 대해 다른 활동을 열려고합니다.

    은 현재 내가 의 AndroidManifest.xml 옆 구현이 있습니다

    <activity 
        android:name=".ui.activities.Activity1" 
        android:windowSoftInputMode="adjustResize"> 
        <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:scheme="http" android:host="host.com" android:pathPrefix="/abc"/> 
        </intent-filter> 
    </activity> 
    <activity 
        android:name=".ui.activities.Activity2" 
        android:windowSoftInputMode="adjustResize"> 
        <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:scheme="http" android:host="host.com" android:pathPrefix="/abc/def"/> 
        </intent-filter> 
    </activity> 
    

    첫 번째 URL은 잘 작동 : 그것은 나를 다른 응용 프로그램 또는 내 activity1에를 사용하는 것이 좋습니다 안드로이드에 내가 누를 때.

    하지만 두 번째 URL을 누를 때 문제가 나타납니다 : 나를 다른 응용 프로그램 또는 내 activity1에 또는 내 activity2에를 사용하는 것이 좋습니다 안드로이드.

    제 질문은 : 활동 1을 제안 목록에서 제외시키는 방법이 있습니까?

    pathPattern으로 게임을 시도했는데 IntentFilter에서 URL을 제외하는 방법을 인터넷 검색하려했지만 실패했습니다.

+0

경로 접두사를/abc에서 Activity2로 변경해보십시오. –

+0

안녕하세요 @AshishShukla 내가 바꿀 수있는 것에 대해 제안 해 주시겠습니까? 왜냐하면 URL을 바꿀 수 없기 때문입니다. –

+0

당신은 당신의 대답을 게시 할 수 있습니다, 그것은 일부 사람들에게 도움이 될 것입니다 ... –

답변

1

`AndroidManifest.xml '을 통해 세련된 솔루션을 찾지 못했기 때문에 코드를 통해 "선택"로직의 일부를 구현하기로 결정했습니다. 매니페스트 파일에서

우리가 " http://host.com/abc/ ..."와 같은 모든 URL에 응답 UrlActivity 정의, 그래서 모양이 같은 것입니다 : 그래서 여기에 내가 무엇을

<activity 
    android:name=".ui.activities.UrlActivity" 
    android:screenOrientation="portrait" 
    android:windowSoftInputMode="adjustResize"> 
    <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:scheme="http" android:host="host.com" android:pathPrefix="/abc"/> 
    </intent-filter> 
</activity> 

그런 다음 우리는 인터페이스 Component를 (정의 어떤 이름을 선택할 수 있습니다 행동에 따라 달라집니다) 특별히 조정 된 UrlActivity. 단순한 경우 단순히 활동과 유사한 방법을 복제 할 수 있습니다. 당신의 UrlActivity 당신의 URI를 검색하고 선택 해당 구성 요소의 구현에 그런

public interface Component { 
    void onStart(); 
    void onStop(); 
} 

예를 들면 다음과 같습니다. 예를 들어 :

private Component component; 

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Uri uri = getIntent().getData(); 
    List<String> segments = uri.getPathSegments(); 

    if (segments.contains("def")) { 
     component = new Component2(...); 
    } else { 
     component = new Component1(...); 
    } 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
    component.onStart(); 
} 

@Override 
protected void onStop() { 
    super.onStop(); 
    component.onStop(); 
} 

이 솔루션이 가진 장점은 @KamranAhmed 솔루션 비교 : 확장 성, 감소 중복을.또한 하나의 결함이 있습니다. 코드를 더 작성하고이 솔루션의 적절한 아키텍처에 대해 생각해야합니다. 따라서 @KamranAhmed 접근법보다 실제로 더 어렵습니다. 그러나 저에게는 더 건조하고 유연합니다.

+0

좋은 접근 방식 ... –

0

나는이 같은 몇 가지 일을 수행해야한다고 생각 :

<activity android:windowSoftInputMode="adjustResize"  
      android:name=".ui.activities.Activity1" > 
     <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:scheme="http" android:host="host.com" 
        android:pathPattern="http://host.com/abc/12345" 
        android:pathPrefix="/abc/12345"/> 
     </intent-filter> 
    </activity> 
    <activity android:windowSoftInputMode="adjustResize" android:name=".ui.activities.Activity2"> 
     <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:scheme="http" android:host="host.com" 
        android:pathPattern="http://host.com/abc/def/12345" 
        android:pathPrefix="/abc/def/12345"/> 
     </intent-filter> 
    </activity> 

가 당신을 도와줍니다 희망을 ...

나는 더 나은 방법을 생각할 수 없다
+0

죄송합니다. 12345는 특정 ID가 아니기 때문에이 솔루션이 도움이되지 않습니다. 모든 ID (임의의 숫자)를 추상 구현합니다. –

0

하지만,이 작품 :

<activity 
    android:name=".ui.activities.Activity1" 
    android:windowSoftInputMode="adjustResize"> 
    <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="test.com" 
      android:pathPattern="/abc/1.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/2.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/3.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/4.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/5.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/6.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/7.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/8.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/9.*" 
      android:scheme="http"/> 
     <data 
      android:host="host.com" 
      android:pathPattern="/abc/0.*" 
      android:scheme="http"/> 
    </intent-filter> 
</activity> 
<activity 
    android:name=".ui.activities.Activity2" 
    android:windowSoftInputMode="adjustResize"> 
    <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="host.com" 
      android:pathPattern="/abc/def/.*" 
      android:scheme="http"/> 
    </intent-filter> 
</activity> 
+0

답변 해 주셔서 감사합니다. 나는 그것을 점검 할것이다. –

+0

효과가 있었나요? –

+0

안녕하세요, 네, 도움이 될 것입니다. 그러나 해킹 비트처럼 보입니다. 어쨌든, 매니페스트에 정상적인 패턴을 구현하는 데 더 좋은 선택이 없다고 생각합니다. 그래서이 대답을 받아 들일 것입니다. 그 동안 나는 다른 해결책을 사용했으나 매니 페스트를 완전히는 사용하지 않았습니다. –