栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何通过Messenger发送来自应用的图片?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何通过Messenger发送来自应用的图片?

在此花费大量时间后:

检查是否已授予权限。 然后:

步骤1:在活动中创建想要的图像的ImageView,然后将其转换为无位图

ImageView imageView = findViewById(R.id.image);Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();//save the image now:saveImage(bitmap);//share itsend();

步骤2:将图片存储在内部文件夹中:

private static void saveImage(Bitmap finalBitmap) {    String root = Environment.getExternalStorageDirectory().getAbsolutePath();    File myDir = new File(root + "/saved_images");    Log.i("Directory", "==" + myDir);    myDir.mkdirs();    String fname = "Image-test" + ".jpg";    File file = new File(myDir, fname);    if (file.exists()) file.delete();    try {        FileOutputStream out = new FileOutputStream(file);        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);        out.flush();        out.close();    } catch (Exception e) {        e.printStackTrace();    }}

步骤3:传送储存的图片:

public void send() {    try {        File myFile = new File("/storage/emulated/0/saved_images/Image-test.jpg");        MimeTypeMap mime = MimeTypeMap.getSingleton();        String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1);        String type = mime.getMimeTypeFromExtension(ext);        Intent sharingIntent = new Intent("android.intent.action.SEND");        sharingIntent.setType(type);        sharingIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(myFile));        startActivity(Intent.createChooser(sharingIntent, "Share using"));    } catch (Exception e) {        Toast.makeText(getbaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();    }}

现在,发送后,如果您不想在存储中保存图像,可以将其删除。检查其他链接可以做到这一点。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/469918.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号