从我们自己的视图启动Android应用程序

时间:2011-08-10 10:42:16

标签: android

HIE ALL 我想在android中创建一个自定义主屏幕。我,在旋转木马视图中。我能够在轮播视图中显示应用程序图标但无法启动应用程序。我,点击特定的应用程序图标我需要启动应用程序,但我收到错误(强制关闭)。这是我得到的错误日志

08-10 16:04:31.570:ERROR / AndroidRuntime(1028):致命异常:主要 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):java.lang.ClassCastException:java.lang.Integer 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.carouseldemo.main.MainActivity $ 1.onItemClick(MainActivity.java:75) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.carouseldemo.controls.CarouselAdapter.performItemClick(CarouselAdapter.java:261) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.carouseldemo.controls.Carousel.onSingleTapUp(Carousel.java:1076) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.GestureDetector.onTouchEvent(GestureDetector.java:557) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.carouseldemo.controls.Carousel.onTouchEvent(Carousel.java:327) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.View.dispatchTouchEvent(View.java:3766) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1671) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.app.Activity.dispatchTouchEvent(Activity.java:2086) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1655) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.view.ViewRoot.handleMessage(ViewRoot.java:1785) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.os.Handler.dispatchMessage(Handler.java:99) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.os.Looper.loop(Looper.java:123) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):在android.app.ActivityThread.main(ActivityThread.java:4627) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at java.lang.reflect.Method.invokeNative(Native Method) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at java.lang.reflect.Method.invoke(Method.java:521) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 08-10 16:04:31.570:ERROR / AndroidRuntime(1028):at dalvik.system.NativeStart.main(Native Method)

enter image description here

最初我只拍了六张照片。

请帮助

提前谢谢 datta

2 个答案:

答案 0 :(得分:1)

您在MainActivity的第75行获得了ClassCastException:

 java.lang.ClassCastException: java.lang.Integer

确保您使用的参数确实是一个整数。

答案 1 :(得分:0)

要从您的应用启动其他应用,您需要拥有它的包名称,然后您可以启动其他应用;

ResolveInfo info;
packageName = info.activityInfo.applicationInfo.packageName;

Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
        mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        if (null != mIntent) {
            try {
                startActivity(mIntent);
            } catch(Exception e) {      }
        }

您可以通过以下方式安装软件包:

ArrayList<PackageInfo> res = new ArrayList<PackageInfo>();
        PackageManager pm = context.getApplicationContext().getPackageManager();
        List<PackageInfo> packs = pm.getInstalledPackages(0);