'backbutton'에 해당되는 글 1건

  1. 2015.12.21 [ionic] Android 호환성

[ionic] Android 호환성

모바일 2015. 12. 21. 17:59

이번에는 Android와 관련된 내용입니다.


1. cross-walk, User-Agent 관련

이건 이전 글로 대체합니다.

http://resisa.tistory.com/170


2. 푸시 관련

여러가지 푸시 플러그인이 있는데 저는 아래 플러그인으로 최종 선택하였습니다.

아래 플러그인이 사용도 가장 심플하고 다른 플러그인에서 안되는 기능도 됩니다.

https://github.com/Code1Tech/phonegap-plugin-push


푸시에서 GCM토큰을 받아오는 초기화 코드의 경우 앱 실행 타이밍과 연관이 있습니다. 입이 실행 되자마자 해당 초기화 코드가 실행되면 토큰을 정상적으로 가져오지 못합니다. 그래서 setTimeout()를 사용하여 2.5초 정도의 딜레이를 주고 실행시키고 있습니다. 2초정도로 했을 경우 특정 디바이스에서 토큰을 받아오지 못하는 현상이 있어 해당 시간을 늘렸습니다.


요구사항 중 앱이 실행 중인 경우에도 푸시가 왔으면 좋겠다는 의견이 있었습니다. iOS 푸시에서는 앱이 실행 중일 때는 푸시가 올 수 없습니다. 그래서 일반적으로 iOS에서는 앱이 실행 중일 경우 푸시가 오는 것처럼 앱내에서 구현을 해주고 있습니다.

여튼 안드로이드에서 앱이 실행 중일 경우 푸시가 오도록 하려면 위의 플러그인을 사용하여야 하며 아래 코드를 추가해주어야 합니다.


- GCMIntentService.java

@Override  

 public void onMessageReceived(String from, Bundle extras) {

            // if we are in the foreground and forceShow is `false` only send data

            if (!forceShow && PushPlugin.isInForeground()) {

                Log.d(LOG_TAG, "foreground");

                extras.putBoolean(FOREGROUND, true);

                PushPlugin.sendExtras(extras);

            }

            // if we are in the foreground and forceShow is `true`, force show the notification if the data has at least a message or title

            else if (forceShow && PushPlugin.isInForeground()) {

                Log.d(LOG_TAG, "foreground force");

                extras.putBoolean(FOREGROUND, true);

                PushPlugin.sendExtras(extras);

                showNotificationIfPossible(getApplicationContext(), extras);

            }

            // if we are not in the foreground always send notification if the data has at least a message or title

            else {

                Log.d(LOG_TAG, "background");

                extras.putBoolean(FOREGROUND, false);


                showNotificationIfPossible(getApplicationContext(), extras);

            }

    }


3. ThemeableBrowser Plugin

iframe내에 링크가 걸려 있을 경우 인앱브라우저 화면에서 아무런 버튼도 보이지 않는 현상이 있습니다. 직접 해당 플러그인을 사용하는 코드에서는 상관없지만 iframe내의 링크의 경우에 해당하는 내용입니다. 아래처럼 자바 코드에 close관련된 부분만 변경하여 넣어줬습니다.

 public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {

            final Options features = parseFeature("{ closeButton: { image: 'close', imagePressed: 'close_pressed', align: 'right', event: 'closePressed'}}");

}


4. MenuButton 관련

Android에서는 메뉴 버튼과 뒤로 가기 버튼이 있어 해당 부분에 대해서도 신경을 써줘야 합니다. 아래 링크로 대신합니다. 메뉴 버튼의 경우 기기에 따라서 다르게 동작합니다.


- CordovaWebViewImpl.java

https://forum.ionicframework.com/t/android-hardware-menu-button-not-working-with-cordova-5-1-1-and-ionic-1-1-0/33128/3



Posted by resisa
,