Android组件学习笔记(分享文字以及图片功能)

来源:互联网 发布:重庆时时计划软件 编辑:程序博客网 时间:2024/04/30 06:38

跟着一位前辈教程敲得代码,记录一下

下面代码设置为按钮点击事件即可,另外对应好信息内容即可(在对应位置添加文本框图片之类)

 public void goShare( View view)    {        String content = ((EditText)findViewById(R.id.editText2)).getText().toString();//获取文本        content = content.trim(); // 对于文本去除空格        if(content.length() ==0) return;        Intent intent = new Intent(Intent.ACTION_SEND);        intent.setType("text/plain"); // MIME TYPE        intent.putExtra(Intent.EXTRA_TEXT, content);        startActivity(intent);    }    public void shareImage(View view)    {        File file = new File("/your_image_file_path/xxx.jpg");//图片对应的路径        Uri imageUri = Uri.fromFile(file);        Intent intent = new Intent(Intent.ACTION_SEND);        intent.putExtra(Intent.EXTRA_STREAM, imageUri);        intent.setType("image/jpeg");        startActivity(Intent.createChooser(intent, "分享我的图片到..."));    }

阅读全文
1 0