Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 意图共享无法附加映像_Android_Share Intent - Fatal编程技术网

Android 意图共享无法附加映像

Android 意图共享无法附加映像,android,share-intent,Android,Share Intent,当与Gmail共享意图时,此代码无法附加图像,并且当与仅共享多个图像或视频的Facebook共享时,此代码也会出错。当我用sendIntent.setType(“image/*”)更改类型时,它会打开Facebook的共享窗口,但会显示空白文本和图像。这一个对我有用 Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "

当与
Gmail
共享意图时,此代码无法附加图像,并且当与仅共享多个图像或视频的
Facebook
共享时,此代码也会出错。当我用
sendIntent.setType(“image/*”)更改类型时,它会打开
Facebook的共享窗口,但会显示空白文本和图像。

这一个对我有用

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "My text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(http://onman.ir/colorfinder/sample.jpg));
sendIntent.setType("*/*");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sendIntent, "Share using"));

对于共享,您可以使用此代码

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("image/jpeg");

            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));

            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(yourimagepath);

            startActivity(Intent.createChooser(shareIntent, "Share Image"));
但如果你想在facebook上这样做,它将无法通过intent工作,你应该使用facebook sdk来共享图像和文本

     Intent shareIntent = new Intent();

                   shareIntent.setAction(Intent.ACTION_SEND);
                   shareIntent.setType("image/*");
                   shareIntent.putExtra(Intent.EXTRA_TEXT,"abc");
                   shareIntent.putExtra(Intent.EXTRA_STREAM, imagebitmap);
                  startActivity(Intent.createChooser(shareIntent, "Share using"));
在代码中,您直接共享图像url,首先需要获取位图,然后共享位图,而不是url{ 意向共享=新意向(意向.行动\发送)

试试这个代码

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("image/jpeg");

            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));

            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(yourimagepath);

            startActivity(Intent.createChooser(shareIntent, "Share Image"));
请注意,当您使用setType()方法时,您正在启用Android来过滤哪些应用程序可以共享您的内容。例如,您正在共享文本或URL,要显示的适当应用程序可以是Facebook、消息或电子邮件。如果您共享图像,合适的应用程序可以是Instagram、Snapshod或Picasa

// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");

// Make sure you put example png image named myImage.png in your
// directory
String imagePath = Environment.getExternalStorageDirectory()
        + "/myImage.png";

File imageFileToShare = new File(imagePath);

Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(Intent.createChooser(share, "Share Image!"));
OnClickListner

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == UPLOADIMAGE && resultCode == RESULT_OK)
    {
        uploadImage.setVisibility(View.GONE);
        imageView.setVisibility(View.VISIBLE);

        if (data !=null)
        {
            imageUri=data.getData();
            imageView.setImageURI(imageUri);
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
            cursor.moveToFirst();
            columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            attachmentFile = cursor.getString(columnIndex);
            Log.e("Attachment Path:", attachmentFile);
            URI = Uri.parse("file://" + attachmentFile);
            cursor.close();

        }
        else {Toast.makeText(TutorForm.this,"Uploading image failed",Toast.LENGTH_LONG).show();}




    }
    super.onActivityResult(requestCode, resultCode, data);

您是否在清单中设置权限?是的,此权限已添加。您在facebook上共享时遇到了什么错误?请告诉我此错误:
请只附加一张照片或一段视频
有什么区别?如果不想添加任何主题,那么?但是facebook是共享意图中的一个选项。但是根据facebook,您可以er及时使用intent共享图像或文本,因此当您想要进行共享时,您应该创建一个自定义共享对话框,并为Facebook共享编写不同的代码。只有在Facebook上,您才编写不同的代码,并对所有共享应用程序intent进行扩孔。请提供更多信息(解释)关于您的答案。感谢您提供这段代码片段,它可能会提供一些有限的、即时的帮助。通过说明这是一个很好的问题解决方案的原因,正确地解释它的长期价值,并将使它对未来有其他类似问题的读者更有用。请您的答案添加一些解释,包括假设这是你做的。
 Intent emailIntent=new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+ clientEmail));
        emailIntent.putExtra(Intent.EXTRA_TEXT,body);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Tutor Registration from App");
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri uri = Uri.parse(imageUri.toString());
        emailIntent.putExtra(Intent.EXTRA_STREAM,URI);
        startActivity(Intent.createChooser(emailIntent,"Send Via..."));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");

//set your message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msgText); 
String imagePath = Environment.getExternalStorageDirectory() + 
File.separator + "image_name.jpg";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Uri uri = Uri.fromFile(imageFileToShare);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);