Gmail composer的Jelly Bean上出现ActivityNotFoundException异常



此类在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;
}
}

在果冻豆上,我得到了一个例外:

11-19 15:32:07.852:E/AndroidRuntime(19630):android.content.ActivityNotFoundException:找不到显式活动类别{com.google.android.gm/com.google.aandroid.gm.ComposeActivityGmail};您是否在AndroidManifest.xml中声明了此活动?

需要时的完整跟踪:

11-19 15:32:07.852:E/AndroidRuntime(19630):android.content.ActivityNotFoundException:找不到显式活动类别{com.google.android.gm/com.google.aandroid.gm.ComposeActivityGmail};您是否在AndroidManifest.xml中声明了此活动?11-1915:32:07.852:E/AndroidRuntime(19630):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.app.Activity.startActivityForResult(Activity.java:3370)11-1915:32:07.852:E/AndroidRuntime(19630):在android.app.Activity.startActivityForResult(Activity.java:3331)11-1915:32:07.852:E/AndroidRuntime(19630):在android.support.v4.app.FragageActivity.startActivityFromFragment(FragmentActivity.java:701)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.support.v4.app.FFragment.startActivity(Fragment.java:787)11-1915:32:07.852:E/AndroidRuntime(19630):在ebeletskiy.gmail.com.passwords.ui.Export.sendByEmail(Export.java:91)11-19 15:32:07.852:E/AndroidRuntime(19630):在ebeletskiy.gmail.com.passwords.ui.Export.access$400(Export.java:22)11-19 15:32:07.852:E/AndroidRuntime(19630):在ebeletskiy.gmail.com.passwords.ui.Export$1.onClick(Export.java:57)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.view.view.performClick(view.java:4202)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.view.view$PerformClick.run(view.java:17340)11-1915:32:07.852:E/AndroidRuntime(19630):在android.os.Handler.handleCallback(Handler.java:725)11-1915:32:07.852:E/AndroidRuntime(19630):在android.os.Handler.dispatchMessage(Handler.java:92)11-1915:32:07.852:E/AndroidRuntime(19630):在android.os.Looper.loop(Looper.java:137)11-19 15:32:07.852:E/AndroidRuntime(19630):在android.app.ActivityThread.main(ActivityThreads.java:5039)11-1915:32:07.852:E/AndroidRuntime(19630):在java.lang.reflect.Method.invokeNative(Native Method)11-1915:32:07.852:E/AndroidRuntime(19630):在java.lang.reflect.Method.ioke(Method.java:511)11-19 15:32:07.852:E/AndroidRuntime(19630):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)11-19 15:32:07.852:E/AndroidRuntime(19630):在com.android.internal.os.ZygoteInit.main(ZygoteNit.java:560)11-1915:32:07.852:E/AndroidRuntime(19630):在dalvik.system.NativeStart.main(本地方法)

我建议不要使用直接打开gmail compose活动的意图。使用这样严格的意图意味着用户需要安装gmail才能使用你的应用程序。并不是每个人都使用gmail作为邮件客户端。。此外,通过对类名进行硬编码,您可以在类名更改可能导致活动中断(这是当前问题的原因)的情况下打开

我反编译了gmail4.2应用程序,发现ComposeActivity类名和路径已经更改。。现在是com.android.mail.compose.ComposeActivity

你应该使用一个通用的电子邮件意图,允许用户使用他们选择的的电子邮件应用程序

仔细观察这条线

您是否在AndroidManifest.xml 中声明了此活动

抱歉,你只是没有申报活动。

最新更新