launching an android applications from our own view
HIE ALL i am trying to create a custom home screen in android . i,e in the carousel view . 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:04: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.java:936) 08-10 16:04:31.570: ERROR/AndroidRuntime(1028): at com.android.internal.polic开发者_运维百科y.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(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.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)
initially i am taking only six images .
please help
thanks in advance datta
You're getting a ClassCastException in line 75 of MainActivity:
java.lang.ClassCastException: java.lang.Integer
Be sure that the parameter you are using really is an Integer.
To launch other application from your app, you need to have it's package name and you can start other app thru;
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:
ArrayList<PackageInfo> res = new ArrayList<PackageInfo>();
PackageManager pm = context.getApplicationContext().getPackageManager();
List<PackageInfo> packs = pm.getInstalledPackages(0);
精彩评论