< 개발 환경 > |
안드로이드/Android Application 정보를 얻어 오자.!!
안드로이드 Application 정보를 얻는 방법 입니다.
package arabiannight.tistroy.com.appinfo; import java.util.List; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; public class TestAppInfomationActivity extends Activity { private final String CATEGORY_MAIN = "android.intent.action.MAIN"; private final String CATEGORY_GMP = "android.intent.category.ARABIANNIGHT"; private ListgroupApps; private ApplicationInfo appInfo; private PackageManager manager; private ComponentName componentName; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView mIconImage = (ImageView) findViewById(R.id.iv_icon); appInfo = new ApplicationInfo(); manager = getPackageManager(); Intent intent = new Intent(CATEGORY_MAIN); intent.addCategory(CATEGORY_GMP); groupApps = manager.queryIntentActivities(intent, PackageManager.GET_INTENT_FILTERS); for(int a = 0 ; a < groupApps.size() ; a++) { appInfo = new ApplicationInfo(); appInfo.setAppId(groupApps.get(a).activityInfo.applicationInfo.loadDescription(manager)+""); appInfo.setAppName(groupApps.get(a).activityInfo.applicationInfo.loadLabel(manager)+""); appInfo.setPackageName(groupApps.get(a).activityInfo.applicationInfo.packageName); appInfo.setIcon(groupApps.get(a).activityInfo.applicationInfo.loadIcon(manager)); componentName = new ComponentName(groupApps.get(a).activityInfo.applicationInfo.packageName, groupApps.get(a).activityInfo.name); appInfo.setComponentName(componentName); Log.d("GROUP", "appId = " + appInfo.getAppId()); Log.d("GROUP", "appIcon = " + appInfo.getIcon()); Log.d("GROUP", "appName = " + appInfo.getAppName()); Log.d("GROUP", "appPackageName = " + appInfo.getPackageName()); Log.d("GROUP", "appComponentName = " + appInfo.getComponentName()); mIconImage.setBackgroundDrawable(appInfo.getIcon()); } } } //
ApplicationInfo 클래스 입니다.
package arabiannight.tistroy.com.appinfo; import android.content.ComponentName; import android.graphics.drawable.Drawable; public class ApplicationInfo { private Drawable icon = null; private String packageName = null; private ComponentName componentName = null; private String appName = null; private String appId = null; public Drawable getIcon() { return icon; } public void setIcon(Drawable icon) { this.icon = icon; } public String getPackageName() { return packageName; } public void setPackageName(String packageName) { this.packageName = packageName; } public ComponentName getComponentName() { return componentName; } public void setComponentName(ComponentName componentName) { this.componentName = componentName; } public String getAppName() { return appName; } public void setAppName(String appName) { this.appName = appName; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } }
AndroidManifest.xml 파일에 해당 <category android:name="android.intent.category.ARABIANNIGHT" /> intent filter를 추가해서 Application 정보를 얻어 올 수 있습니다.!!
결과화면 :
06-04 12:54:17.195: D/GROUP(29778): appId = APP001 06-04 12:54:17.195: D/GROUP(29778): appIcon = android.graphics.drawable.BitmapDrawable@4051fa00 06-04 12:54:17.195: D/GROUP(29778): appName = TestAppInfomation 06-04 12:54:17.195: D/GROUP(29778): appPackageName = arabiannight.tistroy.com.appinfo 06-04 12:54:17.195: D/GROUP(29778): appComponentName = ComponentInfo{arabiannight.tistroy.com.appinfo/arabiannight.tistroy.com.appinfo.TestAppInfomationActivity}
'Android > 일반' 카테고리의 다른 글
안드로이드/Android 에뮬레이터(Emulater) 사용법 (2) | 2012.07.10 |
---|---|
안드로이드/Android Interface를 사용한 Call Back Method 구현 하기~!! (0) | 2012.06.15 |
안드로이드/Android 잠든 단말을 깨우자! PushWakeLock !! (2) | 2012.05.31 |
안드로이드/Android 아이콘 사이즈~!! (0) | 2012.05.28 |
안드로이드/Android 언어 설정 하기! (6) | 2012.04.20 |