-------------------------------------------------------------------------------------------------------------
// 패키지 매니져에서 설치된 앱 리스트 가져오기
final PackageManager pm = getPackageManager();
List<ApplicationInfo> list = pm.getInstalledApplications(0);
for (ApplicationInfo applicationInfo : list) {
String name = String.valueOf(applicationInfo.loadLabel(pm)); // 앱 이름
String pName = applicationInfo.packageName; // 앱 패키지
Drawable iconDrawable = applicationInfo.loadIcon(pm); // 앱 아이콘
}
---------------------------------------------------------------------------------------------------------------
위의 소스와 같이 name, pName 과 같은 변수에 for문에 의해 스마트폰의 앱 이름과 앱 패키지명이 입력되는거같은데
이렇게 name과 pName에 가져온 앱 이름과 앱 패키지명들을
리스트뷰 로 밑에 소스와같이활용하여
-----------------------------------------------------------------------------------------------------------------------------------
ArrayList<String> Items;
ArrayAdapter<String> Adapter;
ListView list;
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setcontentView(R.layout.main);
Items = new ArrayList<String>();
Items.add("~~");
Items.add("~~~");
Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, Items);
list = (ListView)findViewById(R.id.list);
list.setAdapter(Adapter);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
-----------------------------------------------------------------------------------------------------------------------------------------
첫번째 소스로 가져온 어플리케이션 이름들을 액티비티 화면에 리스트로 쭉~ 출력되게 하려면
리스트뷰와 어플리케이션 이름이 들어간 name변수를 어떻게 적용시켜야 할까요??
Items.add(""); 이 부분에 뭔가를 넣고 for문을 돌려야 하나요??ㅜㅜ
안드로이드 초보라 감이 안잡히네요...ㅠㅠ 고수님들 도와주시면 감사하겠습니다!!!
마시가네 님이 알려주신대로 단순히 이름만 출력해 보려고
public class AppViewActivity extends Activity {
/** Called when the activity is first created. */
ArrayList<String> Items;
ArrayAdapter<String> Adapter;
ListView list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final PackageManager pm = getPackageManager();
List<ApplicationInfo> list = pm.getInstalledApplications(0);
Items = new ArrayList<String>();
for (ApplicationInfo applicationInfo : list) {
Items.add(String.valueOf(applicationInfo.loadLabel(pm)));
}
Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, Items);
list = (List<ApplicationInfo>)findViewById(R.id.list);
((ListView) list).setAdapter(Adapter);
((ListView) list).setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
이렇게 해보았습니다. 근데 에러는 안뜨는데 런이 안되는데... 무슨문제가 있는걸까요?ㅠㅠ
단순히 앱 이름만 출력하는 거라면... 위 소스에서 앱 이름을 가져오는 소스를
Items = new ArrayList<String>();
for (ApplicationInfo applicationInfo : list) {
Items.add(String.valueOf(applicationInfo.loadLabel(pm)));
}
이런식으로만 작성하면 되겠네요.
근데 아마 단순히 이름만 출력하시려는 건 아닌거 같네요.
이름만 출력하시려는게 아니고 또 리스트 클릭시 설치된 앱에 어떠한 활동을 하시려면,
Custom Adapter 로 구글에서 검색을 해보시면 예제가 많이 나옵니다.