Android共享意图图像共享不工作

Android共享意图图像共享不工作,android,android-intent,android-activity,uri,share-intent,Android,Android Intent,Android Activity,Uri,Share Intent,我是Android新手,在通过共享意图共享图像时遇到问题。我在谷歌上搜索了很多,尝试了各种方法,但仍然找不到解决方案 我的代码是: Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM,uri); this

我是Android新手,在通过共享意图共享图像时遇到问题。我在谷歌上搜索了很多,尝试了各种方法,但仍然找不到解决方案

我的代码是:

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("image/*");
            shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
            this.startActivityForResult(Intent.createChooser(shareIntent,"Share with"),12);
我已经检查了uri,保存的文件是位图及其返回文件。但共享期间显示的图像无效。Gmail表示无法附加附件,短信应用程序无法加载图片

文本共享工作正常

基本上,我正在为Unity编写一个插件。以下是我在Unity方面的代码:

string destination = Path.Combine(Application.persistentDataPath,"sharingImage" + ".png");
            if (!File.Exists(destination)) {
                print("creating new file");
                File.Create(destination);
            }
            File.WriteAllBytes(destination, bytes);

            print("destination= "+destination);

            AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
            AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://" + destination);

            using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.kashiftasneem.sharelib.ShareController")) {

                AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

                pluginClass.CallStatic("Share",message,uriObject,jo,gameObject.name,destination);
            }
string destination=Path.Combine(Application.persistentDataPath,“sharingImage”+“.png”);
如果(!File.Exists(destination)){
打印(“创建新文件”);
创建(目的地);
}
File.writealBytes(目标,字节);
打印(“目的地=”+目的地);
AndroidJavaClass uriClass=新的AndroidJavaClass(“android.net.Uri”);
AndroidJavaObject uriObject=uriClass.CallStatic(“解析”,“文件:/”+目的地”);
使用(AndroidJavaClass pluginClass=新的AndroidJavaClass(“com.kashiftasneem.sharelib.ShareController”)){
AndroidJavaClass jc=新的AndroidJavaClass(“com.unity3d.player.UnityPlayer”);
AndroidJavaObject jo=jc.GetStatic(“currentActivity”);
pluginClass.CallStatic(“共享”、消息、uriObject、jo、gameObject.name、目的地);
}
我正在记录目标和uri,它们是:

目的地= /data/data/com.kashiftasneem.sharedandridplugin2/files/sharingImage.png

uri= file:///data/data/com.kashiftasneem.shareandroidplugin2/files/sharingImage.png

这可能会有帮助

这可能会有所帮助。

请尝试以下代码:

        Bitmap bitmap = getBitmapFromView(idForSaveView);
        try {
            File file = new File(this.getExternalCacheDir(), "appdiam.png");
            FileOutputStream fOut = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            //fOut.close();
            file.setReadable(true, false);
            final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            intent.setType("image/png");
            startActivity(Intent.createChooser(intent, "Share image via"));
        } catch (Exception e) {
            e.printStackTrace();
        }
请尝试以下代码:

        Bitmap bitmap = getBitmapFromView(idForSaveView);
        try {
            File file = new File(this.getExternalCacheDir(), "appdiam.png");
            FileOutputStream fOut = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            //fOut.close();
            file.setReadable(true, false);
            final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            intent.setType("image/png");
            startActivity(Intent.createChooser(intent, "Share image via"));
        } catch (Exception e) {
            e.printStackTrace();
        }

我想这可能是uri的问题。我编辑了这个问题以包含更多与uri相关的信息。我认为这可能是uri的问题。我编辑了这个问题以包含更多与uri相关的信息。