خرید بک لینک

سلام ، من یک imageView دارم که از پوشه Drawable به صورت تصادفی یک عکس میاره ، میخوام این عکس رو با یک دکمه ارسال کنم (ارسال عکس در تلگرام و ....)
خیلی سرچ کردم و این کد جواب میده ولی یک مشکل داره.
در این خط :
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.p1);
فقط یک عکس ثابت رو انتخاب میکنه .
چجور باید کد رو اصلاح کرد که از یک id مربوط به imageview عکس رو بگیره و ارسال کنه؟

Button btnShare = (Button) findViewById(R.id.btnShare);
btnShare.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
Bitmap bitmap;
OutputStream output;
Intent share;

// Decoding the image
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.p1);

// Find the SD Card path
File filepath = Environment.getExtealStorageDirectory();

// Create a new folder AndroidBegin in SD Card
File dir = new File(filepath.getAbsolutePath()
+ "/AndroidBegin/");
dir.mkdirs();

// Create a name for the saved image
File file = new File(dir, "sample_wallpaper.jpg");

try {

// Start Share Intent
share = new Intent(Intent.ACTION_SEND);

// Type of file to share
share.setType("image/jpeg");

// Saves the file into SD Card
output = new FileOutputStream(file);

// Compress into png format image from 0% - 100%, using 100%
// for this tutorial
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, output);
output.flush();
output.close();

// Locate the image to Share
Uri uri = Uri.fromFile(file);

// Captures the share image
share.putExtra(Intent.EXTRA_STREAM, uri);

// Start the share dialog
startActivity(Intent.createChooser(share, "Share Image"));
}

// Catch exceptions
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

}

- - , .

برچسب: نویسنده: محمد رضا جوادیان تاريخ: شنبه 3 بهمن 1394 ساعت: 11:55

صفحه بندی