我已经通过Android中的 ACTION_SEND 发送了电子邮件。
这里它成功发送自 android 2.2 ,但它没有从 android 4.1 发送。
我使用了以下代码:
ImageView share = (ImageView) findViewById(R.id.imageView5);
share.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final CharSequence[] items = {"Facebook", "Twitter", "Email"};
AlertDialog.Builder builder = new AlertDialog.Builder(SubCate.this);
builder.setTitle("Share Via:");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(items[item] == "Facebook"){
Intent in = new Intent(SubCate.this, TestConnect.class);
in.putExtra("Title", _Substring);
startActivity(in);
}
if(items[item] == "Twitter"){
Intent in = new Intent(SubCate.this, TestConnect.class);
in.putExtra("Title", _Substring);
startActivity(in);
}
if(items[item] == "Email"){
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ ""});
email.putExtra(Intent.EXTRA_SUBJECT, _Substring);
email.putExtra(Intent.EXTRA_TEXT, _Description);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
为什么这些代码在 android 4.0中不起作用 device.pls给我这些解决方案..
这里我使用了alertlist对话框。
我没有在任何地方使用表面视图。如果我删除了这些行
email.putExtra(Intent.EXTRA_STREAM,Uri.parse(“android.resource://”+ getPackageName()+“/”+ R.drawable.ic_launcher));
意味着它的工作...主题和文本从android4.0发送到邮件...但我面对问题只添加附加图像...请给我解决方案。
我收到以下错误:
04-12 10:36:04.722: E/ViewRootImpl(1461): IllegalArgumentException locking surface
04-12 10:36:04.722: E/ViewRootImpl(1461): java.lang.IllegalArgumentException
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.view.Surface.lockCanvasNative(Native Method)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.view.Surface.lockCanvas(Surface.java:76)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.view.ViewRootImpl.draw(ViewRootImpl.java:1924)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.os.Looper.loop(Looper.java:137)
04-12 10:36:04.722: E/ViewRootImpl(1461): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-12 10:36:04.722: E/ViewRootImpl(1461): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 10:36:04.722: E/ViewRootImpl(1461): at java.lang.reflect.Method.invoke(Method.java:511)
04-12 10:36:04.722: E/ViewRootImpl(1461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-12 10:36:04.722: E/ViewRootImpl(1461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-12 10:36:04.722: E/ViewRootImpl(1461): at dalvik.system.NativeStart.main(Native Method)
修改
ImageView share = (ImageView) getActivity().findViewById(R.id.imageView5);
share.setOnClickListener(new OnClickListener()
{
public void onClick ( View v )
{
final CharSequence[] items =
{
"Facebook", "Twitter", "Email"
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Share Via:");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick ( DialogInterface dialog , int item )
{
if (items[item] == "Facebook")
{
onFacebookClick();
}
if (items[item] == "Twitter")
{
onClickTwitt();
}
if (items[item] == "Email")
{
class LongOperation extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]
{
""
});
email.putExtra(Intent.EXTRA_SUBJECT, _Title);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse(_Image));
startActivity(Intent.createChooser(email, "Choose an Email client :"));
return "Executed";
}
protected void onPostExecute(String result) {
}
protected void onPreExecute() {
}
protected void onProgressUpdate(Void... values) {
}
}
}
}
});
AlertDialog alert = builder.create();
alert.setCanceledOnTouchOutside(true);
alert.show();
}
});
}
我必须运行应用程序并单击电子邮件意味着我没有得到任何东西...如果我点击Facebook意味着Facebook登录正在打开。但是点击电子邮件意味着我没有收到电子邮件撰写邮件而没有得到任何错误???为什么???我的代码有什么问题...
答案 0 :(得分:0)
这可能是由于您无法从较新版本的android中的任何UI活动进行网络操作。请点击此链接以使其正常工作。
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ ""});
email.putExtra(Intent.EXTRA_SUBJECT, _Substring);
email.putExtra(Intent.EXTRA_TEXT, _Description);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
return "Executed";
}
@Override
protected void onPostExecute(String result) {
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
答案 1 :(得分:0)
您使用 droid共享来发送电子邮件。在droid共享主要部分是 .setType (对于您使用的电子邮件电子邮件/纯强>)。 试试这个,我确信它有效。
// TODO Auto-generated method stub
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("email/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT_TEXT");
emailIntent.putExtra(Intent.EXTRA_TEXT, "EXTRA_TEXT");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(emailIntent, "Send email using"));
答案 2 :(得分:0)
答案 3 :(得分:0)
尝试在您的电子邮件项目上使用以下代码点击。它可以帮助您。它将同时发送图像和文本。您可以根据需要发送数据..
Bitmap bmp_cmpressed = Bitmap.createScaledBitmap(edited_image, 60,
60, false);
File file_image = saveBitmap(bmp_cmpressed);
Uri uri = Uri.fromFile(file_image);
Intent mail_image = new Intent(android.content.Intent.ACTION_SEND);
mail_image.setType("plain/text");
mail_image.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] {});
mail_image.putExtra(android.content.Intent.EXTRA_SUBJECT, "Image");
mail_image.putExtra(android.content.Intent.EXTRA_STREAM, uri);
mail_image.putExtra(android.content.Intent.EXTRA_TEXT, "Hello...");
Intent intent_mail = Intent.createChooser(mail_image, "Send Mail");
startActivity(intent_mail);