5

내가 내 응용 프로그램에서 딥 링크를 지원 한 Google 크롬 그래서블록 모바일 웹 사이트 내 응용 프로그램 안드로이드 딥 링크 엽니 다 -

<activity android:name=".DeepLinkActivity" android:noHistory="true"></activity> 
    <activity-alias 
     android:name="com.example.Launcher" 
     android:targetActivity=".DeepLinkActivity"> 
     <intent-filter android:autoVerify="true"> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="https" /> 
      <data android:scheme="http" /> 
      <data android:scheme="@string/SCHEMA" /> 
      <data android:host="@string/WEB_DOMAIN" /> 
      <data android:host="@string/WWW_WEB_DOMAIN" /> 
      <data android:path="/" /> 
      <data android:path="/x" android:pathPattern="/x/.*" /> 
     </intent-filter> 
    </activity-alias> 

때마다 안드로이드 응용 프로그램은 응용 프로그램 또는 웹으로 열라는 메시지가 www.example.com에 사용자가 클릭이 괜찮아요,하지만 내 사용자가 모바일 사이트에있을 때 앱에서 열어야하는지는 원치 않습니다. 나는 많은 stackoverflow 게시물을 통과했지만 모두가 가능한하지만 여전히 많은 웹 사이트 가이 시나리오를 처리 말한다.

이 동작은 사용자 동작에 달려 있습니다. 사용자가 링크를 클릭하면 사용자가 브라우저에 URL을 입력하는 동안 Chrome이 선택기를 표시하지만 그렇지 않은 경우 동작합니다.

+2

아마 그 모바일 사이트는 다른 URL을 사용합니까? – Divers

+0

모바일 사이트와 앱에 동일한 URL이 없습니다. – Tasneem

+0

해당 사이트 및 앱을 표시 할 수 있습니까? – Divers

답변

6

많은 연구 끝에 나는 그것을 해결했습니다. 어느 쪽이든 사용할 수 있습니다. 모바일 웹 사이트에서

손잡이 : 당신은 크롬으로 사용자를 렌더링 할 경우 그들은 당신의 msite에있을 때 그래서 항상 당신이

  • GoogleChrome을 모든 URL을 리디렉션하여이 작업을 수행 할 수 있습니다 : // 이동? url = https://www.example.com
  • 인 텐트 : //www.example.com/x#Intent; scheme = https; package = com.android.chrome; S.browser_fallback_url = https://www/example.com/x;action=android.intent.action.VIEW;end;

    • 이 pathpattern = 사용하여 모든 링크 처리 모든 딥 링크 처리 할 수있는 하나의 투명 활동 작성 응용 프로그램에

    핸들 '을. *'

  • 리디렉션 사용자 앱에서 처리하고 싶지 않은 URL에 대해서는 Chrome으로 돌아갑니다.

정확한 로직을 모르지만 효과가 있습니다.

의 AndroidManifest.xml

<activity 
      android:name=".DeepLinkActivity" 
      android:noHistory="true" 
      android:theme="@style/Theme.Transparent"> 
      <intent-filter android:autoVerify="true"> 
       <action android:name="android.intent.action.VIEW" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
       <category android:name="android.intent.category.BROWSABLE" /> 
       <data android:scheme="https" /> 
       <data android:scheme="http" /> 
       <data android:scheme="@string/SCHEMA" /> 
       <data android:host="@string/WEB_DOMAIN" /> 
       <data android:host="@string/WWW_WEB_DOMAIN" /> 
       <data android:pathPattern="/.*" /> 
      </intent-filter> 
     </activity> 

DeepLinkActivity는

@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    try { 
     if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { 
      Uri uri = getIntent().getData(); 
      if (uri == null) throw new IllegalArgumentException("Uri can not be null"); 
      Intent intent = null; 
      if (getString(R.string.SCHEMA).equals(uri.getScheme()) || uri.toString().matches(Links.REGEX)) { 
       intent = linkIntent(uri); 
      } 
      if (intent == null) SystemUtil.launchUrlInDefaultBrowser(uri, this); else startActivity(intent); 

     } 
    } catch (IllegalArgumentException e) { 
     Toast.makeText(this, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); 
    } catch (Exception e) { 
     Toast.makeText(this, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); 
    } finally { 
     finish(); 
    } 
} 

/** 
* This will open the provided url in browser except the current app. 
* @param url Uri 
* @param context Activity Context 
*/ 
public static void launchUrlInDefaultBrowser(Uri url, Context context) { 
    try { 
     ResolveInfo packageInfo = null; 
     final Intent browserIntent = new Intent(Intent.ACTION_VIEW); 
     browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     browserIntent.setData(url); 
     // Try to find anything that we can launch the URL with. Pick up the first one that can. 
     final List<ResolveInfo> resolveInfoList = context.getPackageManager().queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY); 
     if (!resolveInfoList.isEmpty()) { 
      for (ResolveInfo list : resolveInfoList) { 
       if (!BuildConfig.APP_PACKAGE_NAME.equals(list.activityInfo.packageName)) { 
        packageInfo = list; 
        break; 
       } 
      } 
     } 
     if (packageInfo != null) { 
      browserIntent.setClassName(packageInfo.activityInfo.packageName, packageInfo.activityInfo.name); 
      context.startActivity(browserIntent); 
     } else { 
      Toast.makeText(context, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); 
     } 
    } catch (Exception e) { 
     Toast.makeText(context, R.string.can_not_open_url, Toast.LENGTH_SHORT).show(); 
    } 
} 
+1

이러한 솔루션은 나에게 거대한 해킹처럼 보입니다. Google이 기본 브라우저를 다른 곳으로 전환하기로 결정한 경우 (예전처럼)? 사용자가 다른 (사용자 정의) 모바일 브라우저를 사용하면 어떻습니까? 장치 제조업체가 기본 브라우저로 다른 것을 설치하면 어떻게 될까요? – SergGr

+0

네, 해킹이지만 잘 작동합니다. 의도 문제는 Chrome에서만 발생합니다. – Tasneem