Android ShareSDK不同平台分享

不使用ShareSDK集成好的UI分享样式,单独调用指定平台
注意:一定要明确分享形式是(图片、链接、文本...)
  • 如:QQ分享只需分享图片,那么只需设置imagePath或者ImageUrl即可,如果设置了title或text则会变成链接的分享形式。总会一句参数和形式对应
拓展:
  • 分享的图片是当前屏幕截屏加APP的二维码logo



    实现:

    private String getShareImg(String imagePath) {

        File filePic = null;
        try {
            filePic = new File(UrlConfig.IMGEPATH + "sharePic.jpg");
            if (!filePic.exists()) {
                filePic.getParentFile().mkdirs();
                filePic.createNewFile();
            }


            DisplayMetrics displayMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            int width = displayMetrics.widthPixels;
            int height = displayMetrics.heightPixels;

            View view = View.inflate(this, R.layout.layout_share_feed, null);



            ImageView img = view.findViewById(R.id.img_feed_back);
//            Glide.with(this).load(R.drawable.challenge_bg).into(img);
            img.setImageURI(Uri.fromFile(new File(imagePath)));

            view.setDrawingCacheEnabled(true);//启用绘图缓存。
            view.measure(View.MeasureSpec.makeMeasureSpec(width,View.MeasureSpec.EXACTLY),
                    View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

            Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); //获得Bitmap;

            FileOutputStream fos = new FileOutputStream(filePic);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return filePic.getAbsolutePath();
    }
        oks.setImagePath(getShareImg(imagePath));
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • @synthesize和@dynamic分别有什么作用?@property有两个对应的词,一个是 @synthes...
    笔笔请求阅读 541评论 0 1
  • 【Aipm引导页】 https://58976235.wodemo.net/down/20170514/44034...
    Mr_洛寒阅读 2,702评论 3 5
  • NOTE:资源全部来自互联网收集! 第六季全资源已出! 【第六季】【高清】The.Walking.Dead.S06...
    kingfans阅读 7,889评论 0 0
  • 从小我就发现自己运气很差,真的,喝口水都可能被呛到的那种。 就像刚刚我准备去坐公交车,然后眼睁睁的看着一辆公交车从...
    元小芒阅读 316评论 1 4
  • 1、首先,我们要养成良好的生活习惯,做到早睡早起,不暴饮暴食,养成良好的卫生习惯,坚决把病菌扼杀在摇篮之中。 2、...
    黑是黑阅读 294评论 0 0