发送apk文件从Android的code意向错误 [英] Send .apk from android code Intent Error
问题描述
我要发送的.apk文件。但我不能够给它通过蓝牙或WiFi直接或任何其他方式发送。
I want to send .apk file. but i am not able to send it via bluetooth or wifi-direct or any other way.
我已经尝试了一切。我可以轻松地发送过电子邮件,但同样不是通过意图,而是通过邮件API。
i have tried everything. i can easily send through e-mail but that too not via Intents but through Mail API.
请在下面找到我的code。
please find below my Code.
public void sendIntent(int x) throws Exception{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, appnametosend);
sendIntent.putExtra(Intent.EXTRA_STREAM, getApplicationPath(x));
sendIntent.setType("application/vnd.android.package-archive");
startActivity(sendIntent);
}
下面是我的logcat:
Below is my logCat:
09-01 02:08:33.090: W/Bundle(17609): Key android.intent.extra.STREAM expected Parcelable but value was a java.lang.String. The default value <null> was returned.
09-01 02:08:33.110: W/Bundle(17609): Attempt to cast generated internal exception:
09-01 02:08:33.110: W/Bundle(17609): java.lang.ClassCastException: java.lang.String cannot be cast to android.os.Parcelable
09-01 02:08:33.110: W/Bundle(17609): at android.os.Bundle.getParcelable(Bundle.java:1171)
09-01 02:08:33.110: W/Bundle(17609): at android.content.Intent.getParcelableExtra(Intent.java:4454)
09-01 02:08:33.110: W/Bundle(17609): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:7016)
09-01 02:08:33.110: W/Bundle(17609): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1414)
09-01 02:08:33.110: W/Bundle(17609): at android.app.Activity.startActivityForResult(Activity.java:3446)
09-01 02:08:33.110: W/Bundle(17609): at android.app.Activity.startActivityForResult(Activity.java:3407)
09-01 02:08:33.110: W/Bundle(17609): at android.app.Activity.startActivity(Activity.java:3617)
09-01 02:08:33.110: W/Bundle(17609): at android.app.Activity.startActivity(Activity.java:3585)
09-01 02:08:33.110: W/Bundle(17609): at com.example.mysiminfo.MainActivity.sendIntent(MainActivity.java:137)
09-01 02:08:33.110: W/Bundle(17609): at com.example.mysiminfo.MainActivity$1.onItemClick(MainActivity.java:59)
09-01 02:08:33.110: W/Bundle(17609): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
09-01 02:08:33.110: W/Bundle(17609): at android.widget.AbsListView.performItemClick(AbsListView.java:1276)
09-01 02:08:33.110: W/Bundle(17609): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
09-01 02:08:33.110: W/Bundle(17609): at android.widget.AbsListView$1.run(AbsListView.java:3963)
09-01 02:08:33.110: W/Bundle(17609): at android.os.Handler.handleCallback(Handler.java:615)
09-01 02:08:33.110: W/Bundle(17609): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 02:08:33.110: W/Bundle(17609): at android.os.Looper.loop(Looper.java:137)
09-01 02:08:33.110: W/Bundle(17609): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-01 02:08:33.110: W/Bundle(17609): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 02:08:33.110: W/Bundle(17609): at java.lang.reflect.Method.invoke(Method.java:511)
09-01 02:08:33.110: W/Bundle(17609): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
09-01 02:08:33.110: W/Bundle(17609): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
09-01 02:08:33.110: W/Bundle(17609): at dalvik.system.NativeStart.main(Native Method)
请帮助。
推荐答案
首先,的setType()
需要一个MIME类型。路径是不是一个MIME类型。
First, setType()
takes a MIME type. A path is not a MIME type.
其次,您需要使用 EXTRA_STREAM
发送二进制附件。
Second, you would need to use EXTRA_STREAM
to send a binary attachment.
三,我不认为其他的应用程序是一定能够从 getApplicationPath阅读APK(X)
。
Third, I would not assume that other apps are necessarily capable of reading the APK from getApplicationPath(x)
.
这篇关于发送apk文件从Android的code意向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!