【问题标题】:Share Pictures to other apps将图片分享到其他应用
【发布时间】:2013-04-13 07:22:25
【问题描述】:

我一直在努力解决这个问题。我有它。该应用程序正在将图片发送到任何其他应用程序。我尝试使用 WhatsApp、Gmail 等。但是,现在它无法正常工作。会是什么?包装问题?密钥库问题?现在,当我尝试使用 Gmail 时,附件会显示出来,但它看起来像一张带有名称的空白图片。这意味着在智能手机上找不到文件。谢谢大家。

private ShareActionProvider mShareActionProvider;

private void dragonFile(){
    Bitmap dragonFront = BitmapFactory.decodeResource(getResources(),R.drawable.phoenix_art);
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    OutputStream outputStream = null;
    File file = new File(extStorageDirectory, "phoenix_art.jpeg");
    try{  
        outputStream = new FileOutputStream(file);
        dragonFront.compress(Bitmap.CompressFormat.JPEG, 90, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (Exception e){
        e.printStackTrace();
    }

private Intent getDefaultShareIntent(){

    Intent shareIntent = new Intent();
    shareIntent.setType("image/jpeg");
    shareIntent.setAction(Intent.ACTION_SEND);
    dragonFile();
    File downloadedPic = new File(Environment.getExternalStorageDirectory().toString(), "phoenix_art.jpeg");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
    return shareIntent;
}
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.share_menu, menu);

    MenuItem item = menu.findItem(R.id.menu_item_share);

    mShareActionProvider = (ShareActionProvider) item.getActionProvider();

    mShareActionProvider.setShareIntent(getDefaultShareIntent());

    return super.onCreateOptionsMenu(menu);
}

【问题讨论】:

    标签: android image share send android-image


    【解决方案1】:

    您能否使用 DDMS 上的文件资源管理器来验证文件是否已实际创建?您应该能够看到该文件,然后将其拉出(从模拟器或设备)并放到您的开发计算机上。 gmail 获取的文件只是一个名称但看起来为空的事实意味着 getDefaultShareIntent() 看到一个文件并将其正确附加到意图。这意味着它很可能在问题所在的 dragonfile() 中,尽管我不明白它是什么。

    【讨论】:

    • 似乎没有创建它。但是,这就是奇怪的事情。它正在这样做。 ://
    • 但它实际上除了创建文件之外还有其他作用吗?该文件显然在那里,否则你会得到一个错误,把它作为额外的。文件真的是图像吗?
    猜你喜欢
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 2016-09-09
    相关资源
    最近更新 更多