2011-06-04 111 views
14

我正在使用程序包管理器列出已安装应用程序的应用程序。我可以获取点击项目的包名称,但是我想根据包来启动细节屏幕。因此,例如,如果海豚浏览器在列表中被选中,您会看到下面的图像。我怎样才能做到这一点?Android启动应用程序详细信息页面

enter image description here

最终解决方案设定目标为Gingerbread API 9级,并设置你分钟为API级别7

final int apiLevel = Build.VERSION.SDK_INT; 
Intent intent = new Intent(); 
if (apiLevel >= 9) { 
    //TODO get working on gb 
    //Toast.makeText(SDMove.this, "Gingerbread Not Currently Supported", Toast.LENGTH_LONG).show(); 
    startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 
          Uri.parse("package:" + pli.pkg.packageName))); 
} else { 
    final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName"); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 
    intent.putExtra(appPkgName, pli.pkg.packageName); 
    startActivity(intent); 
} 

回答

10

这是一个全面运行的应用程序,其中列出了所有已安装的应用程序,其中ListActivity。当您单击包名称时,会打开应用程序详细信息。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Intent for getting installed apps. 
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

    // Get installed apps 
    List<ResolveInfo> appList = this.getPackageManager().queryIntentActivities(mainIntent, 0); 

    // Make new list for package names and fill the list. 
    List<String> packageNameList = new ArrayList<String>(); 
    for (ResolveInfo resolveInfo : appList) { 
     packageNameList.add(resolveInfo.activityInfo.packageName); 
    } 

    // Set the list adapter. 
    setListAdapter(new ArrayAdapter<String>(this, R.layout.simple, packageNameList)); 
} 

public void onListItemClick(ListView l, View v, int position, long id) 
{ 
    // Get the TextView that was clicked. 
    TextView view = (TextView)v; 

    // Get the text from the TextView. 
    String packageName = (String)view.getText(); 

    // Open AppDetails for the selected package. 
    showInstalledAppDetails(packageName); 
} 

public void showInstalledAppDetails(String packageName) { 
    final int apiLevel = Build.VERSION.SDK_INT; 
    Intent intent = new Intent(); 

    if (apiLevel >= 9) { 
     intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
     intent.setData(Uri.parse("package:" + packageName)); 
    } else { 
     final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName"); 

     intent.setAction(Intent.ACTION_VIEW); 
     intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 
     intent.putExtra(appPkgName, packageName); 
    } 

    // Start Activity 
    startActivity(intent); 
} 

记得有main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@android:id/empty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="No apps installed"/> 
</LinearLayout> 

simple.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</TextView> 
布局文件夹

。希望这个作品:)

+0

是否有明确的许可或为此?我不断收到与我尝试的任何东西关闭的力量,我只是试着将你的方法设置为桌面时钟等简单的东西。我把你的方法然后运行showInstalledAppDetails(“com.android.deskclock”);但无论我尝试它的力量关闭我正在运行项目精英gb根扎d1,但应用程序我已设置为2.2作为我的最小sdk,但不知道为什么我每次强制关闭 – GFlam 2011-06-04 23:23:47

+0

我得到它在我的2.2模拟器上运行,但是当我尝试“com.android.deskclock”时,“检索包时发生异常:com.android.deskclock”。尝试另一个应用,例如“com.android.settings”,在模拟器中工作。包名是正确的非常重要:)如果你没有得到它的工作,你可以从LogCat发布堆栈跟踪。 – khellang 2011-06-05 01:56:56

+0

是刚做了一个新的项目与2.3作为目标这种方法部队关闭,但下面的代码与你一样工作2.3,但我需要它在2.2,因为我正在编写这个应用程序的2.2 ROM。反正张贴在第二的logcat的没有看到真的有什么,但也许你会 – GFlam 2011-06-05 02:10:38

9

试试这个:

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:your.package.here"))); 

和替换“包:your.package.here“与真正的包你想查看...

+0

这只是2.3 ... – khellang 2011-06-04 20:09:47

+0

工作在2.2应用程序的任何东西吗? – GFlam 2011-06-04 20:18:44

+0

这个答案好多了:) – 2013-08-26 08:12:11

相关问题