android 调用本地微信自定义多图分享朋友圈,可放在share sdk中一起使用
来源:互联网 发布:域名过期时间查询 编辑:程序博客网 时间:2024/05/06 01:17
最终的效果图,右下角微信多图为自定义调用系统分享,分享到微信。
在你能正常调用share sdk的时候想在原本的基础上加自定义的分享非常的简单。
它的官网已经给出了代码,但是给的不是很清楚。
lz毕竟是新手所以去问了客服(问第一个给我的是错误答案,坑了我。问了第二个才让我写了出来),下面直接上代码。
在源码里面有写好的添加方法,直接调用即可(在OnekeyShare类里)
在你调用分享的类里加上:
//自定义分享,微信多图分享Bitmap enableLogo = BitmapFactory.decodeResource(context.getResources(), R.mipmap.sharepic);Bitmap disableLogo = BitmapFactory.decodeResource(context.getResources(), R.mipmap.sharepic);String label = "微信多图";View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { }};上面的两个logo是显示的图片,label是下面的名字,再接着下面就是点击你加分享的点击事件了。
上面的写完调用添加自定义分享的方法:
oks.setCustomerLogo(enableLogo, disableLogo, label, listener);// 启动分享GUIoks.show(context);oks是 OnekeyShare oks = new OnekeyShare;
这样子就可以在share sdk的原基础上完成你自定义添加的分享了。
下面说调用系统的分享,多图分享到微信:
这个是最终分享的效果图,你还可以自行的添加或删除分享的图片。
微信官网给出的分享只能分享一张图片,想要发多张(微信朋友圈最多只能发九张图片)怎么办呢?每个手机的系统分享可调微信多图分享。 好了不扯了,下面上代码:
private static Runnable saveFileRunnable = new Runnable(){ @Override public void run() { try { for (int i = 0; i < 9; i++) { String[] ss = stringss[i].split("/"); boolean saveTrue = MyTools.downloadLyWithName(AppStatic.Url_Base+stringss[i],ss[5], fileName, mContext); } // 遍历 SD 卡下 .png 文件通过微信分享 File file = new File(Environment.getExternalStorageDirectory() + "/BangMai/images/" + fileName); File[] files = file.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.getName().endsWith(".jpg")) { return true; } return false; } }); Intent intent = new Intent(); ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI"); intent.setComponent(comp); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setType("image/*"); ArrayList<Uri> imageUris = new ArrayList<Uri>(); for (File f : files) { imageUris.add(Uri.fromFile(f)); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); intent.putExtra("Kdescription", "我分享成功啦!!!!!!"); // 这里可要可不要,这句话的意思是直接会显示在发表时候的文字 mContext.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }};
调用方法:
new Thread(saveFileRunnable).start();在你的OnClick事件里面加上这句就可以了。
因为是调用系统分享的方法,所以你要分享的图片必须要下载到本地分享的时候再从本地取出。try里面的第一个for是我自己写的下载图片的方法,你可以换成你自己写的。
这样子就可以在你的程序中调用系统的多图分享,分享到微信了。
最面是我的图片下载类:
// 保存带名称的图片 public static Boolean downloadLyWithName(String url, String imgName, String fileName, Context mContext) throws Exception { Bitmap bitmap1 = null; byte[] data1 = getImage(url); if (data1 != null) { bitmap1 = BitmapFactory.decodeByteArray(data1, 0, data1.length);// bitmap saveImgWithName(bitmap1, imgName, fileName, mContext); return true; } else return false; } public static byte[] getImage(String path) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); InputStream inStream = conn.getInputStream(); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { return readStream(inStream); } return null; } //保存图片带名称 public static void saveImgWithName(Bitmap bitmap, String imgName, String fileName, Context mContext) { if (bitmap != null) { File appDir = new File(Environment.getExternalStorageDirectory() + "/BangMai/"); if (!appDir.exists()) { appDir.mkdirs(); } if (fileName != null){ appDir = new File(Environment.getExternalStorageDirectory() + "/BangMai/images/" + fileName); if (!appDir.exists()) { appDir.mkdirs(); } } File file = null; file = new File(appDir, imgName); try { FileOutputStream fos = new FileOutputStream(file); if (null != fos) { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }// // 其次把文件插入到系统图库// try {// MediaStore.Images.Media.insertImage(mContext.getContentResolver(), file.getAbsolutePath(), imgName, null);// } catch (FileNotFoundException e) {// e.printStackTrace();// }// // 最后通知图库更新// mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/BangMai/"))); } }
end
0 0
- android 调用本地微信自定义多图分享朋友圈,可放在share sdk中一起使用
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- Android:QQ分享、微信分享、朋友圈分享(不使用第三方SDK)
- 【作废】share sdk 中一些分享问题、微信分享
- Android 微信朋友圈多图分享,不用申请key,不用第三方sdk
- 试用友盟SDK实现Android分享微信朋友圈
- android中关于图片分享到QQ或者微信,朋友圈及其他(免SDK)
- Android;Share SDK微信分享中遇到的问题以及解决方法
- 微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈
- 微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈,后台实现
- 微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈
- android微信朋友圈分享
- [Android分享] 不使用官方SDK,实现微信分享(发送到朋友,发送到朋友圈)
- Android 分享app到QQ好友、微信好友、朋友圈(无需提供SDK,只需调用相关的Activity)
- 分享内容到微信朋友圈和微信好友(使用微信分享SDK)
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
- github学习笔记
- spring spring-mvc mybatis jetty 的pom.xml依赖配置完整版
- iOS开发之富文本(oc与swift两种都有)
- Sicily 1005 Roll Playing Games
- JavaScript模板化:RequireJS学习
- android 调用本地微信自定义多图分享朋友圈,可放在share sdk中一起使用
- ubuntu下安装mysql及远程访问
- Redis入门很简单之七【使用Jedis实现客户端Sharding】
- 商业WIFI的虚幻与现实
- 简历 and tips
- UISwitch
- 650A.Watchmen
- 提升linux下tcp服务器并发连接数限制
- 1013. Battle Over Cities (25)