Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取用户从应用程序列表中选择的应用程序的名称(android)_Android_Onactivityresult - Fatal编程技术网

获取用户从应用程序列表中选择的应用程序的名称(android)

获取用户从应用程序列表中选择的应用程序的名称(android),android,onactivityresult,Android,Onactivityresult,制作一个android应用程序,我有这个意图设置,让用户从所有应用程序列表中进行选择,它工作正常 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); Intent pickIntent = new Intent(Intent.ACTION_

制作一个android应用程序,我有这个意图设置,让用户从所有应用程序列表中进行选择,它工作正常

            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);            
            Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
            pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
            startActivityForResult(pickIntent, 0);
我还添加了一个onActivityResult()方法,没有在其中编写任何代码。在onActivityResult()方法中需要什么代码才能获取用户选择的应用程序的包名

(或我可以启动所选应用程序的任何其他信息)


或者你可以直接启动触觉(数据);因此,您可以启动用户选择的应用程序。

thnx很多!我找了一整天都没找到这个
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == 0 && resultCode == Activity.RESULT_OK && data != null) {
        ComponentName componentName = data.getComponent();
        final String packageName = componentName.getPackageName();
        final String activityName = componentName.getClassName();
    }
}