获取应用程序的用户在应用程序列表中选择的名称(机器人) [英] get name of the app the user chose from app list (android)

查看:161
本文介绍了获取应用程序的用户在应用程序列表中选择的名称(机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做一个Android应用程序,我有这个意图设置,让所有的应用程序的列表,用户可从中选择,它工作正常。

 意图mainIntent =新的意图(Intent.ACTION_MAIN,NULL);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            意图pickIntent =新的意图(Intent.ACTION_PICK_ACTIVITY);
            pickIntent.putExtra(Intent.EXTRA_INTENT,mainIntent);
            startActivityForResult(pickIntent,0);
 

我还增加了一个onActivityResult()方法,而无需编写任何code在里面。 C $ c执行我需要的onActivityResult()方法是什么$,以获取应用程序的用户选择的包叫什么名字?

(或任何其他资料,我可以启动选择的应用程序)

解决方案

  @覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
    如果(要求code == 0安培;&安培;结果code == Activity.RESULT_OK和放大器;&安培;!数据= NULL){
        组件名组件名= data.getComponent();
        最后弦乐的packageName = componentName.getPackageName();
        最后弦乐activityName = componentName.getClassName();
    }
}
 

或者你可以startActivity(数据);这样你就可以启动该应用程序,用户选用。

making an android app, i have this intent setup to let the user choose from a list of all apps and it works ok.

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

i have also added the an onActivityResult() method without writing any code in it. What code do i need in the onActivityResult() method to get the package name of the app the user chose?

(or any other information with which i can launch the chosen app)

解决方案

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

or you can just startActivity(data); so you can launch which app that user choosed.

这篇关于获取应用程序的用户在应用程序列表中选择的名称(机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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