Android/Android 기초
[Android] 패키지 명으로 외부 앱 실행 안됨 해결 / 안드로이드 11 이상 타켓 시 Manifest 추가
태크민
2023. 8. 28. 23:48
패키지명을 받아서 앱을 띄워주어야 할 때가 있다.
사용자의 휴대폰에 해당 앱이 깔려있다면 실행하고, 깔려있지 않고 Google Play는 이용할 수 있다면 구글 플레이의 앱 상세 페이지로, 만약에 그렇지도 않다면 구글 플레이 웹에서 앱 상세 페이지로 이동 시키는 함수이다.
try{
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
catch (Exception e){
e.printStackTrace();
String url = "market://details?id=" + packageName;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
하지만 안드로이드 11을 타겟팅한다고 하시면 메니페스트에서 하나를 추가해주어야 한다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="내 프로젝트 패키지명">
<!-- !!여기!! -->
<queries>
<package android:name="실행하고싶은 외부앱 패키지명" />
</queries>
<!-- !!추가!! -->
<application
/>
이렇게
<queries 태그안쪽에 패키지 적어서 추가해줘야 외부 앱을 실행시킬 수 있다.