2

我已经通过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 登录正在打开。但单击电子邮件意味着我没有收到电子邮件撰写消息并且没有收到任何错误???为什么 ???我的代码有什么问题...

4

4 回答 4

0

您使用droid share发送电子邮件.in droid share 主要部分是.setType(对于您使用email/plain的电子邮件)。试试这个,我相信它的作品。

// 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"));
于 2013-04-12T05:25:45.440 回答
0

您必须将资源文件复制到 sdcard 中,然后在电子邮件中附加它才能工作

检查这个这个链接以获取更多详细信息。

将资源复制到 sdcard android

于 2013-04-12T05:35:36.157 回答
0

尝试在您的电子邮件项目 click 上使用以下代码。它可以帮助您。Tt 将发送图像和文本。您可以根据需要发送数据..

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);
于 2013-04-12T06:19:30.763 回答
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) {
  }
}   
于 2013-04-12T05:23:01.413 回答