딥링크 작업 하다 약간의 맨붕이 와서 정리함.

 

AndroidManifest.xml

<!-- 중요 --> 이 부분 AOS 8 / 12 / 14 버전은 singleTask 없을 경우 첫번째 Scheme 전송시 정상 동작 하지만 두번째 Scheme 전송하면 아무 데이터도 안들어온다. onCreate 자체가 호출이 안됨.

그래서. launchMode="singleTask" 추가해서 onNewIntent를 통해서 받아서 처리해야됨.

 

Deep Link : 통상적으로 App to App 또는 Web to App Scheme 데이터 전송시 사용한다.

App Link : IOS에서는 Universal-Link 와 동일한 방식임. 웹 에서 특정 페이지 진입시 앱이 자동 실행되면서 해당 페이지로 바로 이동되는 기능임.

*** Android의  App Link IOS의 Universal-Link는 웹서버에 json 형태의 파일을 세팅해 줘야된다.  (이건 별도로 다루겠음)

 

<activity
            android:name=".MainActivity"
            android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
            android:exported="true"
            android:launchMode="singleTask"  <!-- 중요 -->
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <!-- WEB2App Uri Scheme & host -->
                <data android:scheme="insuranceapp" />
                <data
                    android:host="open"
                    android:scheme="insuranceapp" />
            </intent-filter>
            
            <!-- App Link 적용 -->
            <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:host="m.insure.xxxx.co.kr"  <!-- App Link 적용 도메인 -->
                    android:pathPattern="/static/applink/.*" <!-- 적용할 도메인 Path -->
                    android:scheme="https" />
            </intent-filter>
</activity>

 

MainActivity.java

public class MainActivity extends AppCompatActivity {
						..........
	@Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        
        // App이 실행되어 있는 상태에서 Scheme 호출시 onNewIntent 파라메터의 intent를 넘겨줘야됨.
        appLinkIntent(intent);
    }
    
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
                        ...........
        // Todo : App to App (Scheme)
        //Scheme 링크로 처음 실행 될때는 onCreate 에서 getIntent()로 파라메터 전송
        Intent schemeIntent = getIntent();
        appLinkIntent(schemeIntent);
                        ...........
     }
     
     private void appLinkIntent(Intent schemeIntent) {

        if (schemeIntent != null) {
            String action = schemeIntent.getAction();
            Uri uri = schemeIntent.getData();
            
            if (uri != null) {
            	String scheme = uri.getScheme();   // App Link용 
                String host = uri.getHost();	   // Deep Link용
                
                // App Link
                if (scheme.equals("http") || scheme.equals("https")) {
                    mIWebview.setLoadUrl(uri.toString());
                    return;
                }
                
                switch (host) {
                    case "open" :   
                        String target_url = uri.getQueryParameter("target_url");
                        
                        if (target_url != null) {
                            String url = new String(Base64.decode(target_url, Base64.NO_WRAP));
                            mIWebview.setLoadUrl(url);
                            return;
                        }
                        break;
                    default:
                        Log.d("schemeIntent default", host);
                }
            }
        }
    }
}

+ Recent posts