如何使用什么应用程序(android)中的共享按钮与图像共享表数据?

时间:2018-04-11 10:27:31

标签: android

我的应用程序代码如:

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBodyText = "**I want my table data with images and text** ";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject/Title");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(intent, "Choose sharing method"));

3 个答案:

答案 0 :(得分:0)

您可能尝试的最简单的代码可能是,

File imageFile = ...;
Uri uriToImage = ...; // Convert the File to a Uri
Intent shareIntent = ShareCompat.IntentBuilder.from(activityContext)
    .setType("image/*")
    .setStream(uriToImage)
    .getIntent();

if (shareIntent.resolveActivity(getPackageManager()) != null) {
   startActivity(shareIntent);
}

答案 1 :(得分:0)

String imagePath="[local image path]"
Uri imageUri; 

File file = new File(imagePath);
FileOutputStream out = null;
try {
    out = new FileOutputStream(imagePath);
    boolean compressed = imageBitmap[i].compress(Bitmap.CompressFormat.JPEG, 100, out);
    if (compressed) {
        imageUri = Uri.fromFile(file));
    }
    out.flush();
    out.close();
} catch (Exception e) {
    e.printStackTrace();
}

//This piece of code will help to share both image and text together

Intent intent= new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.putExtra(Intent.EXTRA_TEXT, content);
intent.setType("image/*");
startActivity(intent);

答案 2 :(得分:0)

    Intent shareIntent;
    Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/Share.png";
    OutputStream out = null;
    File file=new File(path);
    try {
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    path=file.getPath();
    Uri bmpUri = Uri.parse("file://"+path);
    shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
    shareIntent.putExtra(Intent.EXTRA_TEXT,"Your TABLE DATA");
    startActivity(Intent.createChooser(shareIntent,"Share with"));