我已经通过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设备中不起作用。请给我这些解决方案..
在这里,我使用了警报列表对话框。
我没有在任何地方使用表面视图。如果我删除了这些线
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 登录正在打开。但单击电子邮件意味着我没有收到电子邮件撰写消息并且没有收到任何错误???为什么 ???我的代码有什么问题...