Android 应用间 的分享

Android 应用间 的分享

一 ,第三方应用点击分享能找到本应用,把内容分享到本应用内

在需要 让第三方应用打开本应用的 activity 中加入一下内容

        

            

            

            

            

            

            

            

            

            

            

            

            
        
    

data里面的内容 是本应用能接收的 被分享的 数据类型

在 接收的 activity 内 做如下处理: 处理接收到的 数据,比如 文本内容,链接,图片等

 Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
        L.e("   action   " + action);
        L.e("   type   " + type);

        if (action.equals(Intent.ACTION_SEND) && type.equals("image/*")) {
            Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            L.e("   parcelableExtra   " + uri);
            if (uri != null) {

            Bitmap bitmap = BitmapUtils.imageUrlToBitmap(BitmapUtils.getImagePath(uri));// 这里需要  通过uri找到文件路径  生成图片 下面这个 是我自己封装的方法
            }
        }
        if (action.equals(Intent.ACTION_SEND) && (type.equals("text/plain") || type.equals("text/html"))) {

            stringExtra = intent.getStringExtra(Intent.EXTRA_TEXT);//  接收不同类型  进行不同判断 
            L.e("   stringExtra   " + stringExtra);
        }
//  其他也是同样 接收到 语音 视频等 做其他处理  

二 , 将 本应用的 内容分享到其他可以接收分享的应用

Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("image/*");//   同上 选择不同的 类型  
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("/storage/emulated/0/Pictures/145.jpg"));// 设置不同的  数据  
startActivity(Intent.createChooser(intent,"分享到..."));    // 里面两个字段 后面那个是分享页 显示的题头

你可能感兴趣的:(android)