gpt4 book ai didi

android - 在 Android 中使用带有图像附件的 Gmail 通过隐式 Intent 发送邮件?

转载 作者:太空宇宙 更新时间:2023-11-03 12:19:07 25 4
gpt4 key购买 nike

它很简单但在我的应用程序中产生了问题。我正在使用隐式 Intent 发送电子邮件,并附有图像作为附件。但是下面的代码会产生问题。

File file = new File(path);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Wedding App");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Sharing image via email.");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.toString()));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

创建崩溃:

02-22 12:20:47.561: E/ActivityThread(6317): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@417c1fc8 that was originally registered here. Are you missing a call to unregisterReceiver()?
02-22 12:20:47.561: E/ActivityThread(6317): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@417c1fc8 that was originally registered here. Are you missing a call to unregisterReceiver()?
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1066)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1053)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1047)
02-22 12:20:47.561: E/ActivityThread(6317): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
02-22 12:20:47.561: E/ActivityThread(6317): at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
02-22 12:20:47.561: E/ActivityThread(6317): at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
02-22 12:20:47.561: E/ActivityThread(6317): at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.Activity.performCreate(Activity.java:4470)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-22 12:20:47.561: E/ActivityThread(6317): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 12:20:47.561: E/ActivityThread(6317): at android.os.Looper.loop(Looper.java:137)
02-22 12:20:47.561: E/ActivityThread(6317): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-22 12:20:47.561: E/ActivityThread(6317): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 12:20:47.561: E/ActivityThread(6317): at java.lang.reflect.Method.invoke(Method.java:511)
02-22 12:20:47.561: E/ActivityThread(6317): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
02-22 12:20:47.561: E/ActivityThread(6317): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
02-22 12:20:47.561: E/ActivityThread(6317): at dalvik.system.NativeStart.main(Native Method)

最佳答案

试试下面的代码。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("png/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {
"mail--id" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
Uri uri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "/saved_images/MyImage.png"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
emailIntent.setType("text/plain");
startActivity(emailIntent);

并且不要忘记在 list 文件中添加以下权限。

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

关于android - 在 Android 中使用带有图像附件的 Gmail 通过隐式 Intent 发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21951161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com