V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Registering
V2EX  ›  微信

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

  •  
  •   Registering · 2015-02-09 10:41:36 +08:00 · 3070 次点击
    这是一个创建于 3357 天前的主题,其中的信息可能已经有所发展或是发生改变。

    昨晚刚为我的(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;
    }
    

    }

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5247 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:18 · PVG 17:18 · LAX 02:18 · JFK 05:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.