2016-08-07 5 views
1

私は現在のアイテムのイメージとコンテンツを共有するために共有ボタンに取り組んでいますが、Intent Shareで動作するようにtexView idからテキストを取得することはできません。 誰かがもっと良い方法を知っているのだろうか?AndroidはTexviewのコンテンツを共有することができません

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")); 
+1

'STRING'として' TextView'のテキストを取得するには、あなたが呼び出す必要があり 'のgetText()のtoString()'。あなたが今持っているように、あなたは 'TextView'自体を別名として添付しようとしています。 –

答えて

1

変更コードのこの行は:。その上

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

ありがとう、トリックでした。 :-) – rijotech

+0

それを聞いてうれしい! – Marat

関連する問題