rijotech rijotech - 3 months ago 7
Android Question

Android can't get Texview content to share intent

I'm working on a share button to share the current item image and content but i cant seen to get the text from the texView id to work on Intent Share.
I was wondering if anybody knows a better method?

btnShare.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
View content = findViewById(R.id.imgPreview);
content.setDrawingCacheEnabled(true);

Bitmap bitmap = content.getDrawingCache();
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/image.jpg");
try {
cachePath.createNewFile();
FileOutputStream ostream = new FileOutputStream(cachePath);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}


TextView tittle = (TextView) findViewById(R.id.txtText);
TextView txtSubText = (TextView) findViewById(R.id.txtSubText);
TextView txtDescription = (TextView) findViewById(R.id.txtDescription);


Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, tittle);
share.putExtra(Intent.EXTRA_TEXT, txtSubText);
share.putExtra(Intent.EXTRA_TEXT, txtDescription);
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
share.putExtra(Intent.EXTRA_TEXT,"This was share via Almas's Delicias");
startActivity(Intent.createChooser(share,"Share via"));

Answer

Change this lines of codes:

share.putExtra(Intent.EXTRA_SUBJECT, tittle.getText().toString());
share.putExtra(Intent.EXTRA_TEXT, txtSubText.getText().toString());
share.putExtra(Intent.EXTRA_TEXT, txtDescription.getText().toString());
Comments