Как поделиться данными таблицы с изображением с помощью кнопки общего доступа в приложении WhatsApp (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"));

Эй, ты получил свой ответ?

Shubham Raitka 12.04.2018 21:39

Нет, пожалуйста, помогите мне ...

user9629921 13.04.2018 08:08
0
2
112
3

Ответы 3

Самый простой код, который вы можете попробовать, может выглядеть так:

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

сэр, мне нужно без URL-адреса, я хочу попробовать получить данные в таблице локальной базы данных

user9629921 11.04.2018 12:43
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);
    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"));

Другие вопросы по теме