このコードを使用して、リンク可能なテキストとテキストで画像を共有できます。あなたのコンテンツを共有するためにあなたのlayout.xml
にボタンを一つ取る - :
が、これは
ステップ1、ステップに従ってください。
手順2:Activity.java
のこのボタンにはonClickListner
を設定します。
ステップ3: -あなたActivity.java
ファイルボタンsetOnClickListner
にこのコードを入れてください。
String myText = "share text though this string";
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.icon_256);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
String extraText = myText + "\n\nhttps://www.google.co.in";
share.putExtra(Intent.EXTRA_TEXT,extraText);
share.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(f));
startActivity(Intent.createChooser(share, "Share Image"));
ありがとうございます!私はおそらく私はアプリのフォルダから電話のストレージ上のフォルダに画像を作成し、その後、それを取得して共有しているのだろうかと思う。どうやってやるの? –