public class WeixinUtil {
public static final String APP_ID = "wx0b4qcb0f974c5a4b";
private static final int THUMB_SIZE = 150;
private static IWXAPI mApi;
private Context mContext;
private static WeixinUtil mInstance;
private WeixinUtil(Context context){
mContext =context;
mApi = WXAPIFactory.createWXAPI(context, APP_ID,false);
mApi.registerApp(APP_ID);
}
public static WeixinUtil getInstance(Context context){
if(mInstance!=null){
mInstance = new WeixinUtil(context);
}
return mInstance;
}
/**
* 发送文本信息到微信
*/
public static void sendRequest(String text){
WXTextObject textObj = new WXTextObject();
textObj.text=text;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject=textObj;
msg.description = text;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction="txt"+String.valueOf(System.currentTimeMillis());
req.message =msg;
//SendMessageToWX.Req.WXSceneSession 发送至微信的会话内
//SendMessageToWX.Req.WXSceneTimeline 发送至朋友圈
req.scene = SendMessageToWX.Req.WXSceneTimeline;
mApi.sendReq(req);
}
/**
* 发送图片到微信
*/
public void sentBitmap(Bitmap bitmap){
WXImageObject imgObj = new WXImageObject(bitmap);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, THUMB_SIZE, THUMB_SIZE, true);
bitmap.recycle();
// msg.thumbData = Util.bmpToByteArray(thumbBmp,true);
SendMessageToWX.Req req =new SendMessageToWX.Req();
req.transaction = "img" + String.valueOf(System.currentTimeMillis());
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneTimeline;
mApi.sendReq(req);
}
}
WeixinUtil.java这个类是定义过的,里面的方法可以直接用的把? 我想在点击分享的那个按钮直接调用这里的方法?这样是可以的?