在android中发送带有附加图片的电子邮件(解决方案)

发布于 2024-09-18 13:38:46 字数 1317 浏览 3 评论 0原文

图像存储在android SD卡中

我得到了我们需要

 <uses-permission android:name="android.permission.SEND_SMS"/>

在清单中指定的解决方案,工作代码是:

String _path = Environment.getExternalStorageDirectory() + "/mapp/test.jpeg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );

if(file.exists())
{

//final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
//final int result = connMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE,Phone.FEATURE_ENABLE_MMS);

    Toast.makeText(context,"exists",Toast.LENGTH_LONG).show();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("image/jpeg");
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
    sendIntent.putExtra(Intent.EXTRA_SUBJECT,"World Toyata(via Android App");
    sendIntent.putExtra(Intent.EXTRA_STREAM,outputFileUri);
    sendIntent.putExtra(Intent.EXTRA_TEXT,"Problem Area Image");
    startActivity(Intent.createChooser(sendIntent, ""));
}
else
{
    Toast.makeText(context,"SD CARD Required ",Toast.LENGTH_LONG).show();
}

            }                   

the image is stored in android sd card

I got the solution we need to specify

 <uses-permission android:name="android.permission.SEND_SMS"/>

in manifest and the working code is:

String _path = Environment.getExternalStorageDirectory() + "/mapp/test.jpeg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );

if(file.exists())
{

//final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
//final int result = connMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE,Phone.FEATURE_ENABLE_MMS);

    Toast.makeText(context,"exists",Toast.LENGTH_LONG).show();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("image/jpeg");
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
    sendIntent.putExtra(Intent.EXTRA_SUBJECT,"World Toyata(via Android App");
    sendIntent.putExtra(Intent.EXTRA_STREAM,outputFileUri);
    sendIntent.putExtra(Intent.EXTRA_TEXT,"Problem Area Image");
    startActivity(Intent.createChooser(sendIntent, ""));
}
else
{
    Toast.makeText(context,"SD CARD Required ",Toast.LENGTH_LONG).show();
}

            }                   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-09-25 13:38:46

Ramesh - 我在您的示例中发现了价值,但也发现我没有必要拥有 android.permission.SEND_SMS 权限。

我想知道是否有必要
startActivity(Intent.createChooser(sendIntent, "电子邮件:"));

您在其中指定“电子邮件:”。

Ramesh - I found value in your example but also found that it is was not necessary for me to have the permission android.permission.SEND_SMS.

I am wondering if it is necessary to have
startActivity(Intent.createChooser(sendIntent, "Email:"));

where you specify "Email:".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文