본문 바로가기

개발관련 정보/안드로이드

테스트용 런처 함께만들기

너무 오랜만이네요

 

앱을 개발할 때 테스트용 아이콘과 운영용 아이콘을 동시에 생성할 수 있습니다.

 

1. AndroidMenifest.xml

<application
...
..>
       <activity
            android:name="com.ecsoft.testapp.SplashScreenTest"
            android:windowSoftInputMode="adjustResize"
            android:configChanges="locale"
            android:launchMode="singleInstance"
            android:clearTaskOnLaunch="true"
            android:taskAffinity=""
            android:excludeFromRecents="true"
            android:label="@string/app_name_test"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
            <intent-filter>

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity
            android:name="com.ecsoft.testapp.SplashScreen"
            android:windowSoftInputMode="adjustResize"
            android:configChanges="locale"
            android:launchMode="singleInstance"
            android:clearTaskOnLaunch="true"
            android:taskAffinity=""
            android:excludeFromRecents="true"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        
</application>

 

2. 인트로용 Activity 자바파일을 작성하고

SplashScreen.java

package com.ecsoft.testapp;

public class SplashScreen extends Activity {

	...
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.intro);

		initMode(false);

	}

	/**
	 * 테스트의 경우 빌드일부터 일정 기간까지만 앱 사용을 허용한다.
	 * @return
	 */
	private boolean testValidRunning() {
		boolean ret = true;
		long today = System.currentTimeMillis();
		long validDays = (24 * 60 * 60 * 1000);

		// 운영버전인경우 테스트 유효기간을 두지 않는다.
		if(Constant.ISREAL()) return ret;

		myLog.e(TAG, "*** testValidRunning!");

		// 사용 유효기간 검토
		try {
			Date buildDate = BuildConfig.BUILD_TIME;
			long buildTs = buildDate.getTime() + (validDays * 30); // 30일간의 테스트 유효기간.
			String bd = Common.getDate(buildTs);

			myLog.d(TAG, "*** testValidRunning! "+today + " "+ Common.getDate(today));
			myLog.d(TAG, "*** testValidRunning! "+buildTs + " "+ Common.getDate(buildTs));

			if(today>buildTs) {
				ret = false;
				Common.alertMessage(this,
						getResources().getString(R.string.app_name),
						getResources().getString(R.string.expire_test_valid_days, bd),
						getResources().getString(R.string.btn_ok),
						new Handler() {

							@Override
							public void handleMessage(Message msg) {
								super.handleMessage(msg);

								finish();
							}
						});
			} else {
				int days = (int) ((buildTs - today) / (24 * 60 * 60 * 1000));
				if(days<4)
					Toast.makeText(this, getResources().getString(R.string.expire_test_valid_days_str, days), Toast.LENGTH_SHORT).show();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}

		return ret;
	}

	public void initMode(boolean isTest) {

		String className = this.getClass().getName();

		if(isTest || "com.ecsoft.testapp.SplashScreenTest".equals(className)) {
			myLog.e(TAG, "*** initMode: "+className+ " Test MODE!");
			Constant.ISTEST = 1;
		} else {
			myLog.e(TAG, "*** initMode: "+className+ " Real MODE!");
			Constant.ISTEST = 0;
		}

		initSplash();

	}
    
	private void initSplash() {
		if(testValidRunning()) {
			// TODO 처리
		}
	}
    
	...
    
}

 

3. 작성된 인트로 Activity파일을 extends 한다.

SplashScreenTest.java

package com.ecsoft.testApp;

import android.os.Bundle;

/**
 * Created by ecsoft(James Hong) on 2019,March,11
 */
public class SplashScreenTest extends SplashScreen {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		initMode(true);

	}
}

 

이렇게 간단하게 고객에게 테스트환경과 운영환경을 별도로 테스트할 수 있도록 제공할 수 있습니다.

'개발관련 정보 > 안드로이드' 카테고리의 다른 글

암호를 만드는 키보드  (0) 2021.03.10
번역키보드 소개  (0) 2021.03.10
Single instance progress dialog  (0) 2019.05.22
메소드 버스 활용하기  (0) 2019.04.22
5.0 롤리팝에서 숫자 콤마 표현  (0) 2015.04.22