android分享的两种方法_android分享

2020-02-28 其他范文 下载本文

android分享的两种方法由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“android分享”。

不采用官方sdk分享到微信

private void shareToFriend(File file){

Intent intent = new Intent();

ComponentName comp = new ComponentName(“com.tencent.mm”,“com.tencent.mm.ui.tools.ShareImgUI”);

intent.setComponent(comp);

intent.setAction(“android.intent.action.SEND”);

intent.setType(“image/*”);

intent.putExtra(Intent.EXTRA_TEXT,“我是文字”);

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

startActivity(intent);

}

private void shareToTimeLine(File file){

Intent intent = new Intent();

ComponentName comp = new ComponentName(“com.tencent.mm”,“com.tencent.mm.ui.tools.ShareToTimeLineUI”);

intent.setComponent(comp);

intent.setAction(“android.intent.action.SEND”);

intent.setType(“image/*”);

intent.putExtra(Intent.EXTRA_TEXT,“我是文字”);

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

startActivity(intent);

} 使用官网的sdk分享到微信

//注册

api = WXAPIFactory.createWXAPI(this, appId,true);

regToWx();//发送请求

参数为0表示发送到朋友,为1发送到朋友圈 private void wechatShare(int flag){ WXWebpageObject webpage = new WXWebpageObject();webpage.webpageUrl = “www.daodoc.com”;WXMediaMeage msg = new WXMediaMeage(webpage);msg.title = “这是一个测试”;msg.description = “测试微信分享”;

//这里替换一张自己工程里的图片资源

Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);msg.setThumbImage(thumb);

SendMeageToWX.Req req = new SendMeageToWX.Req();req.transaction = String.valueOf(System.currentTimeMillis());req.meage = msg;req.scene = flag==0?SendMeageToWX.Req.WXSceneSeion:SendMeageToWX.Req.WXSceneTimeline;

api.sendReq(req);}

《android分享的两种方法.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
android分享的两种方法
点击下载文档
相关专题 android分享 两种 方法 Android android分享 两种 方法 Android
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文