微信开放平台 SDK 没有打印出错日志,调试起来好晕啊!

2015-02-09 10:41:36 +08:00
 Registering

昨晚刚为我的(android)app申请了一个appid,于是兴冲冲的拿来用了一下,成功可用。

早上起来发现一个情况,每次分享都是跳转到微信之后,又闪退回我的APP,日志也没有输出出错原因,微信开放平台的SDK打印的日志只是一些生命周期的方法。,,调试无从下手啊。

我试着故意写错我的APPID,出现的错误也是一样,所以不知道是否会和APPID有关。。。

不知有没有前人遇到过这个坑,求解,,,调用SDK的分享功能代码如下:

public class WXFriendsHelper {
// APP_ID 替换为你的应用从官方网站申请到的合法appId
private static String APP_ID = "wx41xxxxxxxxxxxxxxxc";
private static final int MIN_SUPPORTED_VERSION = 0x21020001;// 最小支持的版本

/**
 * 分享到微信朋友圈
 * @param context
 * @param title
 * @param url
 */
public static void shareToWXFriends(Activity context,String title,String url){
    IWXAPI api = WXAPIFactory.createWXAPI(context,APP_ID,true);
    api.registerApp(APP_ID);
    // 检查是否安装微信
    if(!api.isWXAppInstalled()) {
        UIHelper.ToastMessage(context, "抱歉,您尚未安装微信客户端,无法进行微信分享!");
        return;
    }
    // 检查是否支持
    if(api.getWXAppSupportAPI() < MIN_SUPPORTED_VERSION) {
        UIHelper.ToastMessage(context, "抱歉,您的微信版本不支持分享到朋友圈!");
        return;
    }
    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = title;
    msg.description = "分享地址:" + url;
    // 缩略图的二进制数据
    Bitmap thumb = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
    msg.thumbData = bmpToByteArray(thumb, true);
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    // 分享的时间
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = msg;
    req.scene = SendMessageToWX.Req.WXSceneTimeline;
    api.sendReq(req);
}
// 处理缩略图
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.PNG, 100, output);
    if (needRecycle) {
        bmp.recycle();
    }
    byte[] result = output.toByteArray();
    try {
        output.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

}

3074 次点击
所在节点    微信
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/169454

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX