Android的启动应用程序的详细信息页面 [英] Android launch applications detail page

查看:143
本文介绍了Android的启动应用程序的详细信息页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,我列出已安装的应用程序包管理器的应用程序。我可以得到包名的项目点击,但我想,然后推出基于包的细节画面。因此,举例来说,如果海豚浏览器在列表中被选中,你会再看看下面的图片。我怎样才能做到这一点?

最终解决方案设定目标为姜饼 API 9级,并设置为最小API级别7

 最终诠释apiLevel = Build.VERSION.SDK_INT;
意向意图=新的意图();
如果(apiLevel> = 9){
    // TODO获得工作GB
    //Toast.makeText(SDMove.this,姜饼目前支持,Toast.LENGTH_LONG).show();
    startActivity(新意图(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                             Uri.parse(套餐+ pli.pkg.packageName)));
} 其他 {
    最后弦乐appPkgName =(apiLevel == 8PKG: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(意向);
}
 

解决方案

下面是一个 ListActivity ,列出了所有安装的应用程序完全正常的应用程序。当你点击一个包名称,它会打开应用程序的详细信息。

 公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    //意图获取安装的应用程序。
    意图mainIntent =新的意图(Intent.ACTION_MAIN,NULL);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    //获取安装的应用程序
    名单< ResolveInfo> 。APPLIST = this.getPackageManager()queryIntentActivities(mainIntent,0);

    //使程序包名新的列表,并填写列表。
    名单<字符串> packageNameList =新的ArrayList<字符串>();
    对于(ResolveInfo resolveInfo:APPLIST){
        packageNameList.add(resolveInfo.activityInfo.packageName);
    }

    //设置列表适配器。
    setListAdapter(新ArrayAdapter<字符串>(这一点,R.layout.simple,packageNameList));
}

公共无效onListItemClick(ListView的L,视图V,INT位置,长ID)
{
    //获取被点击的TextView的。
    TextView的视图=(TextView中)V;

    //从TextView的文本。
    字符串的packageName =(字符串)view.getText();

    //打开AppDetails所选软件包。
    showInstalledAppDetails(的packageName);
}

公共无效showInstalledAppDetails(字符串的packageName){
    最终诠释apiLevel = Build.VERSION.SDK_INT;
    意向意图=新的意图();

    如果(apiLevel> = 9){
        intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse(套餐+的packageName));
    } 其他 {
        最后弦乐appPkgName =(apiLevel == 8PKG:com.android.settings.ApplicationPkgName);

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

    //开始活动
    startActivity(意向);
}
 

记得有的main.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <的ListView
        机器人:ID =@机器人:ID /列表
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT/>
    < TextView的机器人:ID =@机器人:ID /空
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=未安装的应用程序/>
< / LinearLayout中>
 

simple.xml

 < XML版本=1.0编码=UTF-8&GT?;
<的TextView
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent>
< / TextView的>
 

布局文件夹。希望这个作品:)

I'm working on an application where I list the installed applications with the package manager. I can get the package name of the item clicked, but I'd like to then launch the details screen based on the package. So for instance if Dolphin Browser were selected in the list, you would then see the following image. How can I do this?

Final solution set your target as Gingerbread API level 9 and set your min as API level 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);
}

解决方案

Here is a fully working app with a ListActivity that lists all installed apps. When you click a package name, it opens the app details.

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);
}

Remember to have 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>

and 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>

in your layout folder. Hope this works :)

这篇关于Android的启动应用程序的详细信息页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆