来自另一个人的开放应用程序问

时间:2012-05-30 09:10:28

标签: java android android-package-managers

我正在创建一个应用程序,在其中我获得手机上的安装应用程序列表,然后点击并从我的应用程序打开这些应用程序。但是在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);

                            }

                        }

                    }

                });

2 个答案:

答案 0 :(得分:0)

如果您从后台启动应用,则必须在Intent对象中使用FLAG_ACTIVITY_NEW_TASK设置FLAG_FROM_BACKGROUNDaddFlags

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

中提取包名称和活动名称

答案 1 :(得分:0)

我无法确定你的问题是什么,你必须粘贴更多代码!!

但是你必须看到this教程,因为它处理与你相同的问题

  1. 在列表视图中列出手机上所有已安装的应用
  2. 通过调用其启动意图启动单击的应用程序
  3. 下载它附带的代码