티스토리 뷰




 < 개발 환경 > 
   SDK 버전 : 안드로이드 SDK 2.2  
   API LEVEL : 8 
   이클립스 버젼 : Indigo
   테스트단말 : 삼성갤럭시 S2



안드로이드/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 List groupApps;
	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}





파일첨부 : 






댓글
댓글쓰기 폼