안드로이드 개발 질문/답변
(글 수 45,052)
package com.example.android.apis.view;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import java.util.List;
//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;
public class Grid1 extends Activity {
GridView mGrid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadApps(); // do this in onresume?
setContentView(R.layout.grid_1);
mGrid = (GridView) findViewById(R.id.myGrid);
mGrid.setAdapter(new AppsAdapter());
}
private List<ResolveInfo> mApps;
private void loadApps() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
}
public class AppsAdapter extends BaseAdapter {
public AppsAdapter() {
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i;
if (convertView == null) {
i = new ImageView(Grid1.this);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new GridView.LayoutParams(50, 50));
} else {
i = (ImageView) convertView;
}
ResolveInfo info = mApps.get(position);
i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));
return i;
}
public final int getCount() {
return mApps.size();
}
public final Object getItem(int position) {
return mApps.get(position);
}
public final long getItemId(int position) {
return position;
}
}
}
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Grid1.html
API DEMO 를 이용하여 프로그램 안 Activity 별로 아이콘을 받아와서 표시하는것 까지는 했는데요...
그 아이콘 클릭해서 Activity 뛰우는게 안되네요..ㅠㅠ
mGrid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
// TODO Auto-generated method stub
startActivity(new Intent(Intent.ACTION_VIEW));
}
});
이런식으로 했는데 안되네요..ㅠㅠ
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
이 부분을
Intent mainIntent = new Intent(Intent.ACTION_VIEW, null);
로 수정했습니다.
고수님들 방법좀 가리켜주세요...
추가>
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
CATEGORY_LAUNCHER -> CATEGORY_DEFAULT 로 변경 했더니....
팝업창식으로 실행이 되서 클릭하면 실행은 가능해 지내요...
이 팝업창 안뜨고 실행하는 방법 없나요..??ㅠㅠ
추가>
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
CATEGORY_LAUNCHER -> CATEGORY_DEFAULT 로 변경 했더니....
팝업창식으로 실행이 되서 클릭하면 실행은 가능해 지내요...
이 팝업창 안뜨고 실행하는 방법 없나요..??ㅠㅠ
2010.07.15 14:37:20
아이콘을 클릭시 액션을 발생시키려면
아이콘(ImageView)에 setOnClickListener를 달아주시고
onClickListener를 설정해주신다음
그안에 startActivity를 해주시면 될꺼같네요
2010.07.15 15:55:40
07-15 06:51:14.943: INFO/ActivityManager(59): Displayed activity kr.kmk.household/.HouseholdActivity: 6101 ms (total 6101 ms)
07-15 06:51:15.004: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000A04_00000000 [ 29 ipp] (51 ins) at [0x3e4448:0x3e4514] in 594232 ns
07-15 06:51:16.533: WARN/IntentResolver(59): resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT
07-15 06:51:16.533: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.LAUNCHER] }
위에 오류가 발생하네요...ㅠㅠ
2010.07.15 16:42:03
intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
startActivity(intent);
그리고 home 소스를 참고 하시면 될거 같은데요..
2010.07.16 11:10:05
startActivity(intent);
intent는 ....어떤 팩키지의 클래스를 실행
-Intent.ACTION_RUN
-intent.setClassName(팩키지이름, 클래스이름);
-팩키지 이름 = ResolveInfo.activityInfo.packageName
-클래스 이름 = ResolveInfo.activityInfo.name
mGrid.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Intent in = new Intent(Intent.ACTION_RUN);
in.setClassName(mApps.get(position).activityInfo.packageName,
mApps.get(position).activityInfo.name );
startActivity(in);
}
});
이렇게 하면 되겠네요...
intent는 ....어떤 팩키지의 클래스를 실행
-Intent.ACTION_RUN
-intent.setClassName(팩키지이름, 클래스이름);
-팩키지 이름 = ResolveInfo.activityInfo.packageName
-클래스 이름 = ResolveInfo.activityInfo.name
mGrid.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Intent in = new Intent(Intent.ACTION_RUN);
in.setClassName(mApps.get(position).activityInfo.packageName,
mApps.get(position).activityInfo.name );
startActivity(in);
}
});
이렇게 하면 되겠네요...



