Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓可以';无法获取Texview内容以共享意图_Java_Android_Android Intent - Fatal编程技术网

Java 安卓可以';无法获取Texview内容以共享意图

Java 安卓可以';无法获取Texview内容以共享意图,java,android,android-intent,Java,Android,Android Intent,我正在使用共享按钮来共享当前项目图像和内容,但我无法从texView id获取文本来进行意图共享。 我想知道是否有人知道更好的方法 btnShare.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { View content = findViewById(R.id.imgPreview); content.setDrawingCacheEnabled(true);

我正在使用共享按钮来共享当前项目图像和内容,但我无法从texView id获取文本来进行意图共享。 我想知道是否有人知道更好的方法

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

更改以下代码行:

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

要将
文本视图
的文本作为
字符串
,需要对其调用
getText().toString()
。现在,您正试图将
TextView
s本身附加为附加项。很高兴听到这个消息!