Android 各种功能代码收集

1.分享图片等文件到单个指定微信好友

 1 /**
 2      * 分享信息到朋友
 3      * 
 4      * @param file
 5      *    假如图片的路径为path,那么file = new File(path);
 6      */
 7     private void shareToFriend(File file) {
 8         Intent intent = new Intent();
 9         ComponentName componentName = new ComponentName("com.tencent.mm",
10                 "com.tencent.mm.ui.tools.ShareImgUI");
11         intent.setComponent(componentName);
12         intent.setAction(Intent.ACTION_SEND);
13         intent.setType("image/*");
14         intent.putExtra(Intent.EXTRA_TEXT, "测试微信");
15         intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
16         startActivity(intent);
17     }

2.分享图片等文件到微信朋友圈

 1     /**
 2      * 分享信息到朋友圈
 3      * 
 4      * @param file
 5      *            ,假如图片的路径为path,那么file = new File(path);
 6      */
 7     private void shareToTimeLine(File file) {
 8         Intent intent = new Intent();
 9         ComponentName componentName = new ComponentName("com.tencent.mm",
10                 "com.tencent.mm.ui.tools.ShareToTimeLineUI");
11         intent.setComponent(componentName);
12         intent.setAction(Intent.ACTION_SEND);
13         intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
14         intent.setType("image/*");
15         startActivity(intent);
16     }

 

原文地址:https://www.cnblogs.com/_ymw/p/4140229.html