Android Intent 跳转 发送朋友圈
来源:互联网 发布:mac如何设置桌面图标 编辑:程序博客网 时间:2024/04/28 22:51
写在前面
2016年7 月份 微信封了几乎所有的deeplink URL Scheme ,现在基本上不可以直接通过deeplink 跳转到微信去执行相应的操作,但是很多时候我们还是不希望集成 SDK去获取接口,毕竟既有65535 方法数限制,又有引包麻烦,更新迭代麻烦等相应问题,我尝试着 使用传统的直接Intent 调相应的action 执行相关操作。
问题原因:
网上很多相关的教程,但是在我这边测试使用时出现了问题,比如说 可以发送 文字·图片等到微信好友,这一点没有问题,但是想要去发送照片到朋友圈,我们发现,很难直接做到这一步操作,通过查看反编译微信得到的manifest 文件,我们看出 发送到朋友圈这个Activity只接受 image/* 类型的文件,当我们尝试发布本地图片或者网络图片时,又出现了问题,它只识别 content// 类型的URI,而且,我们将URI转换成 相应的URI时 还是获取不到相应的图片资源,没办法只有使用笨方法:
具体方法:
1.先将生成的图文 存成图片 存入图库
2.再通知系统更新图片信息
3.获取图库中相应图片的URI,调起 微信相应activity
4.发布朋友圈
具体的方法 见 代码:
Resources res=getResources(); Bitmap bmp= BitmapFactory.decodeResource(res, R.drawable.main_activity_list_1); String filePrefix= null; try { filePrefix = saveImageToGallery(this,bmp); } catch (IOException e) { e.printStackTrace(); } ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI"); intent.setComponent(comp); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "你好 "); intent.putExtra(Intent.EXTRA_TITLE, "我是标题"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri=Uri.parse(filePrefix); Log.i("uri", "" + uri.getScheme()); intent.setAction(Intent.ACTION_SEND); intent.setType("image"); Log.i("image", " " + uri);//这里做一下修改可以发多图//// ArrayList<Uri> imageUris = new ArrayList<>();//// imageUris.add(uri);// intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(intent);
相关工具类:
public static String saveImageToGallery(Context context, Bitmap bmp) throws IOException { // 首先保存图片 File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis()+".jpg"; String fileNameTemp; File file = new File(appDir, fileName); file.createNewFile(); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // 其次把文件插入到系统图库 try { fileNameTemp=MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null); } catch (FileNotFoundException e) { e.printStackTrace(); fileNameTemp=""; } // 最后通知图库更新 context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(Environment.getExternalStorageDirectory().toString()+"/Boohee"))); return fileNameTemp;//返回的就是 content://开头的具体地址 }
同时分享一些成功使用没有大费周章的方法:
- 调用支付宝扫码 支付 (可用于向开发者捐款项目)
Uri uriPay = Uri.parse("alipayqr://platformapi/startapp?saId=10000007&qrcode=你的二维码对应的网址");intent = new Intent(Intent.ACTION_VIEW, uriPay);
qq的deepLink
//String url = "mqqwpa://im/chat?chat_type=group&uin=463028**3&version=1";//这是调到指定的qq群String url="mqqwpa://im/chat?chat_type=wpa&uin=XXXXXXXX";startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));//这是调起跟个人的聊天儿
希望 能对你有帮助
github【https://github.com/panyunyi97】
阅读全文
1 0
- Android Intent 跳转 发送朋友圈
- Android - Intent - 界面跳转
- Android - Intent - 界面跳转
- android intent 跳转
- android intent 跳转
- android intent跳转时传参
- Android Intent跳转活动
- Android系统Intent跳转
- 【Android】 Intent跳转功能
- Android Intent 跳转方式
- Android intent页面跳转
- android 页面跳转(intent)
- Android页面跳转Intent使用
- Android FragmentActivity Intent 跳转封装
- Android intent跳转工具类
- android界面跳转,Intent介绍
- Android Intent跳转回传
- Intent发送短信(跳转到发送界面)
- Windows MySQL 升级步骤和常见问题
- [JSON]2017年最新县及县以上行政区划代码
- Shortest Prefixes 【字典树 求给定字符串的 最短确定前缀】
- Spring Boot
- python写算法题:leetcode: 17. Letter Combinations of a Phone Number
- Android Intent 跳转 发送朋友圈
- 212.m1-详情页面信息和5张图的显示
- 2017年6月版NDK开发入门
- 关于PHP5.6连接SQL Server 2008 R2数据库驱动及一些问题
- Java学习笔记系列02
- python写算法题:leetcode: 18. 4Sum
- C语言的文件随机访问fseek()和ftell()函数
- Android 调整 TextView,CheckBox,RadioButton中图片大小
- 在 lisp 中使用 FSO 对象