0

我正在制作一个应用程序,在其中我获得手机上安装应用程序的列表,然后我从我的应用程序中点击并打开这些应用程序。但是这里提出的问题CATEGORY_LAUNCHER给出了空指针

我的 logcat 输出::

05-30 14:34:33.876: E/Handler(14042): Failed to handle callback; interface not implemented, callback:android.view.View$PerformClick@40e35d70
05-30 14:34:33.876: E/Handler(14042): java.lang.NullPointerException
05-30 14:34:33.876: E/Handler(14042):   at com.AppFavorits.GetAllApp$1$1.onClick(GetAllApp.java:83)
05-30 14:34:33.876: E/Handler(14042):   at android.view.View.performClick(View.java:3538)
05-30 14:34:33.876: E/Handler(14042):   at android.widget.CompoundButton.performClick(CompoundButton.java:105)
05-30 14:34:33.876: E/Handler(14042):   at android.view.View$PerformClick.run(View.java:14330)
05-30 14:34:33.876: E/Handler(14042):   at android.os.Handler.handleCallback(Handler.java:607)
05-30 14:34:33.876: E/Handler(14042):   at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 14:34:33.876: E/Handler(14042):   at android.os.Looper.loop(Looper.java:154)
05-30 14:34:33.876: E/Handler(14042):   at android.app.ActivityThread.main(ActivityThread.java:4974)
05-30 14:34:33.876: E/Handler(14042):   at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:34:33.876: E/Handler(14042):   at java.lang.reflect.Method.invoke(Method.java:511)
05-30 14:34:33.876: E/Handler(14042):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 14:34:33.876: E/Handler(14042):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 14:34:33.876: E/Handler(14042):   at dalvik.system.NativeStart.main(Native Method)

我的代码:: 更新

 final Dialog dialog = new Dialog(GetAllApp.this);
                    dialog.setContentView(R.layout.maindialog);
                    dialog.setTitle("This is my custom dialog box");
                    dialog.setCancelable(true);
                    //there are a lot of settings, for dialog, check them all out!

                    //set up text
                    final RadioButton rdoDialogopen = (RadioButton)dialog.findViewById(R.id.rdoDialogopen);
                    final RadioButton rdoDialogfav = (RadioButton)dialog.findViewById(R.id.rdoDialogfav);
                    final RadioButton rdoDialogopenNfav = (RadioButton)dialog.findViewById(R.id.rdoDialogopenNfav);

                rdoDialogopen.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        if (rdoDialogopen.isChecked() == true) {
                            if(lstpinfo.get(position).pname !=null)
                            {
                            Intent i = new Intent(Intent.ACTION_MAIN);
                            PackageManager manager = getPackageManager();
                            i = manager.getLaunchIntentForPackage(lstpinfo
                                    .get(position).pname);
                            i.addCategory(Intent.CATEGORY_LAUNCHER);
                            startActivity(i);

                            }

                        }

                    }

                });
4

2 回答 2

0

如果您从后台启动应用程序,则必须在您的 Intent 对象中设置FLAG_ACTIVITY_NEW_TASKFLAG_FROM_BACKGROUND使用:addFlags

Intent intent25 = new Intent(Intent.ACTION_MAIN).addCategory(
Intent.CATEGORY_LAUNCHER).setClassName("_APP_PACKAGE_NAME",
"_APP_PACKAGE_NAME.ACTIVITY_NAME").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(new ComponentName("APP_PACKAGE_NAME",
"APP_PACKAGE_NAME.ACTIVITY_NAME"));
getApplicationContext().startActivity(intent25);

我在考虑你知道我们如何从中提取包名称和活动名称PackageManager

于 2012-05-30T09:27:26.397 回答
0

我不知道你的问题是什么,你必须粘贴更多代码!

但是您必须查看教程,因为它处理与您相同的问题

  1. 在列表视图中列出手机上所有已安装的应用程序
  2. 通过调用其启动意图来启动单击的应用程序

下载它附加的代码

于 2012-05-30T11:36:29.963 回答