본문 바로가기

Android

[android]intent parseUri()로 class 호출하기

case0. Intent.parseUri() (Uri안에 있는 Extra Parsing Type)

Intent.class 참조

// add EXTRA
if (uri.startsWith("S.", i)) b.putString(key, value);
else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
else throw new URISyntaxException(uri, "unknown EXTRA type", i);


case1. class 호출(명시적)


String uri = "intent:#Intent;component=패키지명/.세부패키지명.클래스명;i.data=인트형데이터;end";
Intent intent = new Intent();
try {
intent = Intent.parseUri(uri, 0);
} catch (URISyntaxException e) {
e.printStackTrace();
}
startActivity(intent);



case2. class 호출(암시적)

반드시 Manifest에서 받는 class부분의 intent-filter에서 action을 정의해 주어야함


<intent-filter>
<action android:name="액션명"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>


String uri = "intent:#Intent;action=액션명;S.data=문자형데이터;end";
Intent intent = new Intent();
try {
intent = Intent.parseUri(uri, 0);
} catch (URISyntaxException e) {
e.printStackTrace();
}
startActivity(intent);



case3. 특정 url 이동(Web)

반드시 Manifest에서 받는 class부분의 intent-filter에서 action을 정의해 주어야함


<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.BROWSABLE"></category>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:scheme="스키마이름"></data>
</intent-filter>


String uri = "http://웹주소#Intent;launchFlags=0x10000000;end";
// 0x10000000 = FLAG_ACTIVITY_NEW_TASK
Intent intent = new Intent();
try {
intent = Intent.parseUri(uri, 0);
} catch (URISyntaxException e) {
e.printStackTrace();
}
startActivity(intent);