此处将为大家介绍关于平凡:确认在android中发送的电子邮件的详细内容,并且为您解答有关平凡:确认在android中发送的电子邮件是什么的相关问题,此外,我们还将为您介绍关于android–从内部存
此处将为大家介绍关于平凡:确认在android中发送的电子邮件的详细内容,并且为您解答有关平凡:确认在android中发送的电子邮件是什么的相关问题,此外,我们还将为您介绍关于android – 从内部存储发送包含附件的电子邮件、android – 发送带附件的电子邮件时出错、android – 如何使用设备注册的电子邮件ID自动填充电子邮件edittext、android – 无密码发送电子邮件的有用信息。
本文目录一览:- 平凡:确认在android中发送的电子邮件(平凡:确认在android中发送的电子邮件是什么)
- android – 从内部存储发送包含附件的电子邮件
- android – 发送带附件的电子邮件时出错
- android – 如何使用设备注册的电子邮件ID自动填充电子邮件edittext
- android – 无密码发送电子邮件
平凡:确认在android中发送的电子邮件(平凡:确认在android中发送的电子邮件是什么)
启动电子邮件意图后,如何获得确认已发送电子邮件或发生错误的回叫活动?
Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("png/image"); String subject = "Email Subject"; String body = "Message Body"; emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, body); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/" + IMAGE_FILENAME)); startActivity(Intent.createChooser(emailIntent, "Send email...")); //Here I need to do something on a successfully sent email
也许开始activityForResult?但是我应该期待什么结果呢?
答案1
小编典典这确实取决于您的所启动的应用程序Intent
。它可以是Gmail应用程序,可以是电子邮件应用程序,也可以是任何第三方应用程序。因此,没有100%可靠的方法来确定用户是否实际按下了Send
。
您唯一可以做的就是检查Gmail和电子邮件应用程序在通过调用时是否返回了任何相关内容,startActivityForResult
并依靠它们。但是要当心这是不可靠的,因为再次可能会有第三方应用程序。另外,由于这些应用并未公开指定返回的内容,因此它们可能会在不作任何通知的情况下在某些时候进行更改。
android – 从内部存储发送包含附件的电子邮件
任何人都知道如何解决它或一个工作的例子?将外部存储上的所有东西都转换成是很糟糕的.
谢谢
Ps:我检查了其他线程,他们似乎没有解决方案(旧线程)
解决方法
I’m assuming you are trying to send the file as an email attachment
using intents.The reason why the file is empty is that the email app does not have
access to the file in /data/data/package_name/myfile_name,due to
Androids security model (the /data/data/package_name directory is
private to your app).In order to add the file as an attachment,you need to write it to public storage (such as the SD card) so the email app can access it.
android – 发送带附件的电子邮件时出错
码:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Halosys Greetings"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,""); emailIntent.putExtra(Intent.EXTRA_STREAM,bm); emailIntent.setType("image/png"); startActivity(Intent.createChooser(emailIntent,"Send mail..."));
错误堆栈:
12-28 11:42:37.456: ERROR/AndroidRuntime(21930): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gm/com.google.android.gm.ComposeActivity}: java.lang.NullPointerException 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2663) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.os.Handler.dispatchMessage(Handler.java:99) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.os.Looper.loop(Looper.java:123) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread.main(ActivityThread.java:4627) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at java.lang.reflect.Method.invokeNative(Native Method) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at java.lang.reflect.Method.invoke(Method.java:521) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at dalvik.system.NativeStart.main(Native Method) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): Caused by: java.lang.NullPointerException 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.provider.Gmail$AttachmentOrigin.localFileExtras(Gmail.java:2194) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.ComposeArea.addAttachment(ComposeArea.java:732) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.ComposeArea.initFromExtras(ComposeArea.java:685) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.ComposeActivity.initFromExtras(ComposeActivity.java:1482) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.ComposeActivity.finishOnCreateAfteraccountSelected(ComposeActivity.java:1021) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at com.google.android.gm.ComposeActivity.onCreate(ComposeActivity.java:259) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2627) 12-28 11:42:37.456: ERROR/AndroidRuntime(21930): ... 11 more
提前致谢.
解决方法
public void doSendFile() { String fileName = "myFileName.txt"; String externalStorageDirectory = Environment .getExternalStorageDirectory().toString(); String myDir = externalStorageDirectory + "/myDir/"; // the file will be in myDir Uri uri = Uri.parse("file://" + myDir + fileName); Intent i = new Intent(Intent.ACTION_SEND); try { myFileHandle.close(); // you may want to be sure that the file is closed correctly } catch (IOException e) { // Todo Auto-generated catch block e.printstacktrace(); } i.setType("text/plain"); // as you can see I am sending a simple txt file here i.putExtra(Intent.EXTRA_EMAIL,new String[] { "sendTo@gmail.com" }); i.putExtra(Intent.EXTRA_SUBJECT,"the subject text"); i.putExtra(Intent.EXTRA_TEXT,"extra text body"); Log.i(getClass().getSimpleName(),"logFile=" + uri); i.putExtra(Intent.EXTRA_STREAM,uri); try { startActivity(Intent.createChooser(i,"Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getBaseContext(),"There are no email clients installed.",Toast.LENGTH_SHORT) .show(); } }
也确定你有
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在您的清单中,您可以在外部存储中实际创建该文件.
附:我从未设法直接从内部存储发送文件.
android – 如何使用设备注册的电子邮件ID自动填充电子邮件edittext
例如,如果我的手机注册了gmail id sd@gmail.com,那么当我开始输入“s”时它应该是自动完成的.有任何想法吗???谢谢…
解决方法
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE); Account[] list = manager.getAccounts();
并且还需要向AndroidManifest文件添加所需的权限:
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
从那里你可以自动填充信息.
android – 无密码发送电子邮件
我不希望该用户应该添加他/她的密码.
我已经通过Intent检查了默认方法,并在下面的链接中检查了第二种方法.
Second Method
解决方法
因此,您可以发送电子邮件应用程序的意图(如您所述),也可以自己完成(如您提到的第二种方法).
但是第二种方法显然需要密码,因为您代表用户(从他们的帐户)发送电子邮件.如果没有密码,Gmail(或任何邮件服务提供商实际上)将不允许这样做.
所以简单地回答你的问题,不.没有密码就无法做到.
相反,你可以使用一种解决方法.您可以通过单个邮件ID(由您创建,因此您知道密码)发送通过您的应用程序发送的所有电子邮件.现在,在电子邮件的内容中,您可以存储要求您提供反馈的用户的电子邮件ID.
这样,你只需要询问邮件ID(无密码),如果你想联系他们,你也可以获得他们的联系信息.
希望这可以帮助.祝好运.
关于平凡:确认在android中发送的电子邮件和平凡:确认在android中发送的电子邮件是什么的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android – 从内部存储发送包含附件的电子邮件、android – 发送带附件的电子邮件时出错、android – 如何使用设备注册的电子邮件ID自动填充电子邮件edittext、android – 无密码发送电子邮件等相关内容,可以在本站寻找。
本文标签: