2011-07-05 10 views
0

現在のすべてのアプリケーションを表示するアプリケーションを開発中です。 Iアプリのパッケージ名を取得し、良いthatsの午前ではなく、特定のアプリケーションは、私はそれを行う必要がありますどのように名前を付け、私は次のコードを使用しています:ように、また、チェックボックスにこれらのアプリケーション名を表示する方法を教えてくださいパッケージ名からアプリケーション名のリストを表示するには

Context context = this.getApplicationContext(); 
ActivityManager mgr = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE); 

List<RunningTaskInfo> tasks = mgr.getRunningTasks(30); 

List<ActivityManager.RunningAppProcessInfo> tasksP = mgr.getRunningAppProcesses(); 

int numOfTasks = tasks.size(); 

for(int i = 0; i < numOfTasks; i++){ 
    ActivityManager.RunningAppProcessInfo task = tasksP.get(i); 

    PackageInfo myPInfo = null; 
    try { 
     myPInfo = getPackageManager().getPackageInfo(task.processName, 0); 
    } catch (NameNotFoundException e) { 
     e.printStackTrace(); 
    } 
    Toast.makeText(location.this, 
      task.processName, 
      Toast.LENGTH_LONG).show(); 
} 

を私は望むアプリを殺すことができます。

答えて

4

お使いの携帯電話にインストールされたアプリケーションを取得するためにこのコードを試してみてください。

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
    final List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities(mainIntent, 0); 

    List<String> componentList = new ArrayList<String>(); 

    for (ResolveInfo ri : pkgAppsList) { 
     if (ri.activityInfo != null) { 
      String app_name=ri.activityInfo.loadLabel(getPackageManager()).toString(); 
      Log.d("Apps Name", ""+ri.activityInfo.loadLabel(getPackageManager()).toString()); 
     } 
    } 
} 

さらに参考のために、このリンクをチェックしてください:

Installed Application Details

2
Intent filter = new Intent(Intent.ACTION_MAIN); 
    filter.addCategory(Intent.CATEGORY_LAUNCHER); 
    Context context = getApplicationContext(); 

    PackageManager manager = getPackageManager(); 


    List<ResolveInfo> infos = getPackageManager().queryIntentActivities(filter,0); 

    List<Intent> filters = new ArrayList<Intent>(); 
    filters.add(filter); 

    ComponentName component = new ComponentName(context.getPackageName(), MainActivity.class.getName()); 
    List<ComponentName> activities = new ArrayList<ComponentName>(); 


    //ComponentName[] components = new ComponentName[] {new ComponentName("//com.neo.application", "com.neo.application.Application"), component}; 


     try { 
     manager.getApplicationInfo(//PACKAGE_NAME);//just Ctrl+space it u'll get the package names. 
    } catch (NameNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
関連する問題