Android ShareSDK不同平台分享

不使用ShareSDK集成好的UI分享样式,单独调用指定平台
  • OnekeyShare的平台设置
    http://wiki.mob.com/%E5%88%86%E4%BA%AB%E5%88%B0%E6%8C%87%E5%AE%9A%E5%B9%B3%E5%8F%B0/
  • 各平台所需的内容字段。参考:
    http://wiki.mob.com/%E4%B8%8D%E5%90%8C%E5%B9%B3%E5%8F%B0%E5%88%86%E4%BA%AB%E5%86%85%E5%AE%B9%E7%9A%84%E8%AF%A6%E7%BB%86%E8%AF%B4%E6%98%8E/
注意:一定要明确分享形式是(图片、链接、文本...)
  • 如:QQ分享只需分享图片,那么只需设置imagePath或者ImageUrl即可,如果设置了title或text则会变成链接的分享形式。总会一句参数和形式对应
拓展:
  • 分享的图片是当前屏幕截屏加APP的二维码logo


    Android ShareSDK不同平台分享_第1张图片

    实现:

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

你可能感兴趣的:(Android ShareSDK不同平台分享)