简体   繁体   English

将图片分享到其他应用

[英]Share Pictures to other apps

I've been busting my head on this. 我一直在努力解决这个问题。 I had it. 我有 The app was sending the picture to any other app. 该应用程序正在将图片发送到其他任何应用程序。 I tried with WhatsApp, Gmail, etc. But, now it's not working. 我尝试使用WhatsApp,Gmail等。但是,现在不起作用。 What can it be? 会是什么 Packaging problem? 包装有问题吗? Keystore problem? 密钥库问题? Now, when I try to use Gmail, the attachment shows up, but it looks like an empty picture with its name. 现在,当我尝试使用Gmail时,附件会显示出来,但看起来像是空白的图片,其名称也是如此。 That means that is not finding the file on the Smartphone. 这意味着在智能手机上找不到文件。 Thanks guys. 多谢你们。

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);
}

Can you use the file explorer on DDMS to verify the file was actually created? 您可以在DDMS上使用文件资源管理器来验证文件是否实际创建吗? You should be able to see the file and then pull it off (from either emulator or device) and onto your development computer. 您应该能够看到文件,然后将其从仿真器或设备中拉出并拖到开发计算机上。 The fact that gmail gets a file that is only a name but looks empty means that getDefaultShareIntent() sees a file and correctly attaches it to the intent. gmail获取的文件只有一个名称,但看起来为空,这意味着getDefaultShareIntent()会看到一个文件并将其正确附加到意图上。 That means it's likely in dragonfile() where the problem resides, although I don't see what it is. 这意味着问题可能存在于dragonfile()中,尽管我不知道它是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM