简体   繁体   English

从我们自己的角度启动 android 应用程序

[英]launching an android applications from our own view

HIE ALL i am trying to create a custom home screen in android.大家好,我正在尝试在 android 中创建自定义主屏幕。 i,e in the carousel view. i,e 在轮播视图中。 i am able to show the application icons in the carousel view but unable to launch the application.我能够在轮播视图中显示应用程序图标,但无法启动应用程序。 i,e on click of a particular application icon i need to launch the application but i am getting the error(force close).我,即单击特定应用程序图标时,我需要启动该应用程序,但出现错误(强制关闭)。 this is error log what i am getting这是我得到的错误日志

08-10 16:04:31.570: ERROR/AndroidRuntime(1028): FATAL EXCEPTION: main 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): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:557) 08-10 16:0 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): FATAL EXCEPTION: main 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:错误/AndroidRuntime(1028):在 android.view.GestureDetector.onTouchEvent(GestureDetector.java:557)08-10 16:0 4:31.570: ERROR/AndroidRuntime(1028): at com.carouseldemo.controls.Carousel.onTouchEvent(Carousel.java:327) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.View.dispatchTouchEvent(View.java:3766) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.Z93F725A07423FE1C889F448B33D21 4:31.570: ERROR/AndroidRuntime(1028): at com.carouseldemo.controls.Carousel.onTouchEvent(Carousel.java:327) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.View .dispatchTouchEvent(View.java:3766) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897) 08-10 16:04:31.570: ERROR /AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java: 936)08-10 16:04:31.570:错误/AndroidRuntime(1028):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.Z93F725A07423FE1C889F448B33D21 F46Z: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): at 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): at android.view.ViewRoot.handleMessage( F46Z: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): at 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: 错误/AndroidRuntime(1028): 在 android.view.ViewRoot.handleMessage( ViewRoot.java:1785) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.os.Handler.dispatchMessage(Handler.java:99) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.os.Looper.loop(Looper.java:123) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at 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.Z93 ViewRoot.java:1785) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.os.Handler.dispatchMessage(Handler.java:99) 08-10 16:04:31.570: ERROR/AndroidRuntime( 1028): at android.os.Looper.loop(Looper.java:123) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at android.app.ActivityThread.main(ActivityThread.java:4627) 08 -10 16:04:31.570:错误/androidruntime(1028):在java.LANG.RANG.RANG.RANG.METHOD.MENOD.INVOENATIVE.INVOENATIDE(INVOOKENATION(MEDATING)08-10 16:04:04:04:31.570:31.570:31.570:31.570:31.570:31.570 f. reflect.Method.invoke(Method.java:521) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Z93 F725A07423FE1C889F448B33D21F46Z: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) F725A07423FE1C889F448B33D21F46Z: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):在 dalvik.system.NativeStart.main(Native Method)

在此处输入图像描述

initially i am taking only six images.最初我只拍了六张照片。

please help请帮忙

thanks in advance datta在此先感谢

You're getting a ClassCastException in line 75 of MainActivity:您在 MainActivity 的第 75 行收到 ClassCastException:

 java.lang.ClassCastException: java.lang.Integer

Be sure that the parameter you are using really is an Integer.确保您使用的参数确实是 Integer。

To launch other application from your app, you need to have it's package name and you can start other app thru;要从您的应用程序启动其他应用程序,您需要拥有它的 package 名称,您可以通过它启动其他应用程序;

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) {      }
        }

you can get installed package thru:您可以通过以下方式安装 package:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM