error in program Install Application programmatically on Android
I use this code to install voice_search programmatically from my application.
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("file:///android_asset/voicesearch.x.apk")) .setType("application/vnd.android.package-archive");
I have this errors
04-06 08:48:01.112: ERROR/AndroidRuntime(293): Uncaught handler: thread main exiting due to uncaught exception
04-06 08:48:01.151: ERROR/AndroidRuntime(293): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=application/vnd.android.package-archive }
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.app.Activity.startActivityForResult(Activity.java:2749)
04-06 08:48:01.1开发者_开发技巧51: ERROR/AndroidRuntime(293): at android.app.Activity.startActivity(Activity.java:2855)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.dreamstep.wPS.Main.onClick(Main.java:110)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.View.performClick(View.java:2364)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.View.onTouchEvent(View.java:4179)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.widget.TextView.onTouchEvent(TextView.java:6541)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.View.dispatchTouchEvent(View.java:3709)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.os.Looper.loop(Looper.java:123)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at java.lang.reflect.Method.invoke(Method.java:521)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-06 08:48:01.151: ERROR/AndroidRuntime(293): at dalvik.system.NativeStart.main(Native Method)
I have this
Intent installIntent = new Intent(Intent.ACTION_VIEW);
Uri apkFile = Uri.fromFile(myFile);
installIntent.setDataAndType(apkFile,
"application/vnd.android.package-archive");
and it works with an apk file. may be settings the data and the type at the same time ?
You cannot install applications out of assets.
精彩评论