gpt4 book ai didi

android - Gmail Composer Jelly Bean 的 ActivityNotFoundException 异常

转载 作者:行者123 更新时间:2023-11-29 16:10:55 25 4
gpt4 key购买 nike

此类在 ICS 上运行良好,但在 Jelly Bean 上因 ActivityNotFoundException 而失败。你们知道为什么吗?谢谢。

public class EmailSender {

public static Intent getSendEmailIntent(Context context, String email,
String subject, String body, File fileName, String chooserTitle) {

final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);

//Explicitly only use Gmail to send
emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");

emailIntent.setType("plain/text");

//Add the recipients
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{email});

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);

//Add the attachment by specifying a reference to our custom ContentProvider
//and the specific file of interest
emailIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(fileName));

return emailIntent;
}
}

在 Jelly Bean 上出现异常:

11-19 15:32:07.852: E/AndroidRuntime(19630): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.gm/com.google.android.gm.ComposeActivityGmail}; have you declared this activity in your AndroidManifest.xml?

在需要时进行完整跟踪:

11-19 15:32:07.852: E/AndroidRuntime(19630): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.gm/com.google.android.gm.ComposeActivityGmail}; have you declared this activity in your AndroidManifest.xml? 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.app.Activity.startActivityForResult(Activity.java:3370) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.app.Activity.startActivityForResult(Activity.java:3331) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:701) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.support.v4.app.Fragment.startActivity(Fragment.java:787) 11-19 15:32:07.852: E/AndroidRuntime(19630): at ebeletskiy.gmail.com.passwords.ui.Export.sendByEmail(Export.java:91) 11-19 15:32:07.852: E/AndroidRuntime(19630): at ebeletskiy.gmail.com.passwords.ui.Export.access$400(Export.java:22) 11-19 15:32:07.852: E/AndroidRuntime(19630): at ebeletskiy.gmail.com.passwords.ui.Export$1.onClick(Export.java:57) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.view.View.performClick(View.java:4202) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.view.View$PerformClick.run(View.java:17340) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.os.Handler.handleCallback(Handler.java:725) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.os.Handler.dispatchMessage(Handler.java:92) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.os.Looper.loop(Looper.java:137) 11-19 15:32:07.852: E/AndroidRuntime(19630): at android.app.ActivityThread.main(ActivityThread.java:5039) 11-19 15:32:07.852: E/AndroidRuntime(19630): at java.lang.reflect.Method.invokeNative(Native Method) 11-19 15:32:07.852: E/AndroidRuntime(19630): at java.lang.reflect.Method.invoke(Method.java:511) 11-19 15:32:07.852: E/AndroidRuntime(19630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 11-19 15:32:07.852: E/AndroidRuntime(19630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 11-19 15:32:07.852: E/AndroidRuntime(19630): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我建议不要使用 intent 直接打开 gmail 撰写 Activity 。使用如此严格的 Intent 意味着用户需要安装 gmail 才能使用您的应用程序。不是每个人都使用 gmail 作为他们的邮件客户端。此外,通过硬编码类名,您可以让自己面对类名更改可能导致您的 Activity 中断的情况(这是您当前问题的原因)

我反编译了gmail 4.2应用,发现ComposeActivity类名和路径都变了..现在是com.android.mail.compose.ComposeActivity

您应该使用允许用户使用他们选择的电子邮件应用程序的通用电子邮件 Intent

关于android - Gmail Composer Jelly Bean 的 ActivityNotFoundException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455118/

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