在果冻豆ActivityNotFoundException例外Gmail的作曲家 [英] ActivityNotFoundException exception on Jelly Bean for Gmail composer
问题描述
本类适用于ICS很好,但失败 ActivityNotFoundException
的果冻豆。难道你们知道为什么吗?谢谢你。
公共类EmailSender { 公共静态意图getSendEmailIntent(上下文的背景下,字符串电子邮件,
主题字符串,字符串的身体,文件的文件名,字符串chooserTitle){ 最终意图emailIntent =新意图(
android.content.Intent.ACTION_SEND); //明确只使用Gmail发送
emailIntent.setClassName(com.google.android.gm,com.google.android.gm.ComposeActivityGmail); emailIntent.setType(纯/文); //添加收件人
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
新的String [] {电子邮件}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,体); //通过指定我们的定制的ContentProvider参考添加附件
//和感兴趣的特定文件
emailIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(文件名)); 返回emailIntent;
}
}
在果冻豆我得到异常:
15 11-19:32:07.852:E / AndroidRuntime(19630):
android.content.ActivityNotFoundException:无法找到明确的
活动类
{} com.google.android.gm/com.google.android.gm.ComposeActivityGmail;
有你在你的AndroidManifest.xml宣布这项活动?
块引用>在需要的情况下完整跟踪:
15 11-19:32:07.852:E / AndroidRuntime(19630):
android.content.ActivityNotFoundException:无法找到明确的
活动类
{} com.google.android.gm/com.google.android.gm.ComposeActivityGmail;
有你宣布你的AndroidManifest.xml这个活动? 11-19
15: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-19
15:32:07.852:E / AndroidRuntime(19630):在
android.app.Activity.startActivityForResult(Activity.java:3331)11-19
15:32:07.852:E / AndroidRuntime(19630):在
android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:701)
11-19 15:32:07.852:E / AndroidRuntime(19630):在
android.support.v4.app.Fragment.startActivity(Fragment.java:787)11-19
15: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-19
15:32:07.852:E / AndroidRuntime(19630):在
android.os.Handler.handleCallback(Handler.java:725)11-19
15:32:07.852:E / AndroidRuntime(19630):在
android.os.Handler.dispatchMessage(Handler.java:92)11-19
15: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(ActivityThread.java:5039)11-19
15:32:07.852:E / AndroidRuntime(19630):在
java.lang.reflect.Method.invokeNative(本机方法)11-19
15:32:07.852:E / AndroidRuntime(19630):在
java.lang.reflect.Method.invoke(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(ZygoteInit.java:560)11-19
15:32:07.852:E / AndroidRuntime(19630):在
dalvik.system.NativeStart.main(本机方法)
块引用>解决方案我会建议不要使用意图直接打开Gmail撰写活动。使用这样的严格的意图意味着用户需要拥有Gmail的安装使用您的应用程序。不是每个人都使用的Gmail电子邮件客户端程序..此外,通过硬编码类名,你会把自己暴露给实例,其中可能会导致您的活动破坏(这是您当前的问题的原因)类名更改
我反编译的Gmail 4.2应用,发现ComposeActivity类名和路径已经改变了..现在是
com.android.mail.compose.ComposeActivity
您应该使用一般的电子邮件的意图,允许用户使用他们选择的电子邮件应用程序
This class works fine on ICS, but fails with
ActivityNotFoundException
on Jelly Bean. Do you guys know why? Thank you.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; } }
On Jelly Bean I'm getting an exception:
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?
Full trace in case of need:
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)
解决方案I'd advise against using an intent to directly open the gmail compose activity. Using such a strict intent means that the user needs to have gmail installed to use your app. Not everybody uses gmail for their mail client.. Additionally, by hardcoding class names you leave yourself open to instances where the class name changes can result in your activity breaking (which is the cause of your current problem)
I decompiled the gmail 4.2 application and found that the ComposeActivity class name and path has changed.. it is now
com.android.mail.compose.ComposeActivity
You should use a general email intent that allows the user to use the email application of their choosing
这篇关于在果冻豆ActivityNotFoundException例外Gmail的作曲家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!