【问题标题】:Android Application with Intents带有意图的 Android 应用程序
【发布时间】:2014-03-10 13:06:05
【问题描述】:

我正在尝试共享 SD 卡中的图像。但我的分享按钮有问题:它说:

没有应用程序可以执行此操作

那么,我必须使用哪种类型的代码来共享图像?我希望,也许,有可能将我的图像作为电子邮件或消息发送。希望有人可以帮助我。

【问题讨论】:

标签: android


【解决方案1】:

首先你需要将 img 存储在 storege 中 像这样

 Bitmap icon = mBitmap;
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/jpeg");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
    try {
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
    } catch (IOException e) {                       
            e.printStackTrace();
    }

然后你就可以这样分享了

 share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
    startActivity(Intent.createChooser(share, "Share Image"));

【讨论】:

    【解决方案2】:

    “没有应用程序可以执行此操作”,因为您的设备中没有安装共享应用程序。在您的真实设备中安装一些第三方应用程序,如 facebook、whats app、gmail... 并运行您的应用程序以共享图像。

    并开始如下活动:

    share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
    startActivity(Intent.createChooser(share, "Share Image"));
    

    【讨论】:

    • 你知道我必须把这段代码或其他部分放在哪里吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    相关资源
    最近更新 更多