转:android 调用系统分享的类型和步骤

来源:互联网 发布:js 字段默认值 编辑:程序博客网 时间:2024/06/07 02:29

类型======

      

case "doc": ContentType = "application/msword"; bre
case "doc":                    ContentType = "application/msword";                    break;                case "pdf":                    ContentType = "application/pdf";                    break;                case "jpg":                case "jpeg":                    ContentType = "image/jpeg";                    break;                case "gif":                    ContentType = "image/gif";                    break;                          case "zip":                    ContentType = "application/zip";                    break;                case "txt":                    ContentType = "text/plain";                    break;                case "htm":                case "html":                    ContentType = "text/html";                    break;                             case "xls":                    ContentType = "application/vnd.ms-excel";                    break;                case "ppt":                    ContentType = "application/vnd.ms-powerpoint";                    break;                default:                    ContentType = "application/octet-stream";                    break;
类型===========================================
标准模式=====
Intent intent = new Intent(Intent.ACTION_SEND); //启动分享发送的属性
intent.setType("text/plain"); // 分享发送的数据类型
String msg = "推荐给大家";
intent.putExtra(Intent.EXTRA_TEXT, msg); // 分享的内容
activity.startActivity(Intent.createChooser(intent,"选择分享"));// 目标应用选择对话框的标题 
标准模式========================================

举例说明======
1.发送文本
                  Intent sendIntent = new Intent();  sendIntent.setAction(Intent.ACTION_SEND);
                  sendIntent.putExtra(Intent.EXTRA_TEXT,"Mirror is a good application, let's share it");          sendIntent.setType("text/*");
                  startActivity(sendIntent);
2.发送图片
                  Intent sendIntent = new Intent();  sendIntent.setAction(Intent.ACTION_SEND);  File f = new File(Environment.getExternalStorageDirectory() + "/q.png");          Uri u = Uri.fromFile(f);
                  sendIntent.putExtra(Intent.EXTRA_STREAM, u);
                  sendIntent.setType("image/png");
                  startActivity(sendIntent);
举例说明========================================
特例===========
/** * 从Assets中读取图片 */private Bitmap getImageFromAssetsFile(String fileName) {Bitmap image = null;AssetManager am = getResources().getAssets();try {InputStream is = am.open(fileName);image = BitmapFactory.decodeStream(is);is.close();} catch (IOException e) {e.printStackTrace();}return image;}
从android eclipse工程中获取图片资源
注意: 调用系统默认分享,不能传工程中的图片资源,只能是再手机上存储的图片
特例===============================================


0 0
原创粉丝点击