popuwindow下的微信好友和朋友圈分享

private PopupWindow popupWindow;
// 微信分享
private IWXAPI api;
public static final int DLG_SHARE = 3004;
private void showWindow(View parent) {


api = WXAPIFactory.createWXAPI(this, WEIXIN_APPID, false);
api.registerApp(WEIXIN_APPID);

View shareView = LayoutInflater.from(this).inflate(
R.layout.personinfo_gengduo_click, null);
ImageView report = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_reportimg);
report.setImageResource(R.drawable.icon_share_pyq);
TextView reporttxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_report);
reporttxt.setText("朋友圈");
ImageView lahei = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_laheiimg);
lahei.setImageResource(R.drawable.activity_contacts_wx);
TextView laheitxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_lahei);
laheitxt.setText("微信好友");
View weixin_haoyou_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemreport_layout);
View weixin_pengyouquan_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemlahei_layout);
popupWindow = new PopupWindow(shareView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);
// 使其聚集
popupWindow.setFocusable(true);
// 设置允许在外点击消失
popupWindow.setOutsideTouchable(true);
//刷新状态 
popupWindow.update(); 
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popupWindow.setBackgroundDrawable(new BitmapDrawable());
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
// 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
int xPos = windowManager.getDefaultDisplay().getWidth() / 2
- popupWindow.getWidth() / 2;

popupWindow.showAsDropDown(parent, xPos,0);
weixin_haoyou_send.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss(); 
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;

if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}


SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneTimeline;


dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});
weixin_pengyouquan_send
.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss(); 
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;


if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}


SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;


dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});

}

private String buildTransaction(final String type) {
return (type == null) ? String.valueOf(System.currentTimeMillis())
: type + System.currentTimeMillis();
}

// 获取指定路径的图片
public void getImage(String urlpath) throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);


if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.e("ADActivity", "bitmap =========================== bitmap");
}

}
class MygetImage implements Runnable {
@Override
public void run() {
// while (true) {
try {
getImage(img);
//break;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();


}
//}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值