The pit encountered by android integration sharesdk cannot return to app, etc

Posted by Thikho on Tue, 10 Dec 2019 18:14:37 +0100

After sharesdk integration, I encountered a problem sharing to wechat and friends circle. When I clicked back, I found that I couldn't go back to the app

    private void sharedToThirdPlatform() {
        OnekeyShare oks = new OnekeyShare();
        //Close sso authorization
        oks.disableSSOWhenAuthorize();
        // Title title, wechat, QQ, QQ space and other platforms
        oks.setTitle("My title");
        // titleUrl QQ and QQ space jump links
        oks.setTitleUrl("http://sharesdk.cn");
        // Text is shared text, which is required by all platforms
        oks.setText("shock,sharesdk It turns out...");
        // imagePath is the network path of the picture. No thumbnail is set
        oks.setImageUrl("http://img.mp.sohu.com/upload/20170614/1b236c0dfb2d4d098e08b9b94db043aa.png");
        // imagePath is the local path of the picture, which is supported by platforms other than linked in
//            oks.setImagePath("https://pic3.zhimg.com/80/7d6e12985dfdb526e902443a7dc9abfe_hd.jpg");
        // url use jump address in wechat, Weibo, Facebook and other platforms
        oks.setUrl("http://img.mp.sohu.com/upload/20170614/1b236c0dfb2d4d098e08b9b94db043aa.png");
        // Comment is my comment on this sharing, which is only used on renren.com
        oks.setComment("I'm the test comment text");

        oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
            @Override
            public void onShare(Platform platform, Platform.ShareParams shareParams) {
                if (Wechat.NAME.equals(platform.getName())) {
                    
                }
            }
        });
        // Launch sharing GUI
        oks.show(this);
    }

Later, set the startup mode of WXEntryActivity to Android: launchmode = "single task" according to the online method

        <!--Wechat share callback -->
        <activity
            android:name=".wxapi.WXEntryActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" />

But although it can return to the app, there is another problem. The app can't be operated. It covers a layer of interface and needs to click the physical return key once to operate

None of the callback methods with sharesdk executed. I guess this layer of interface is WXEntryActivity, because it is executed in the wechat development document, and I think I will finally follow this type of method. Then I tried to print it in the callback method of WXEntryActivity. Finally, I found that this was true. After sharing successfully, click to return to app baseResp.getType=2

And then there's the problem

    @Override
    public void onResp(BaseResp baseResp) {
       switch (baseResp.getType()){
           case 2:          //Wechat share successfully returns the callback of app
               finish();

               break;
       }
    }

Judge type. If = = 2, the sharing is successful. At this time, finish the transparent WXEntryActivity interface. Then the app can operate

 

In addition, attach the configuration in the build.gradle file under the app

apply plugin: 'com.mob.sdk'

MobSDK {
    appKey "xxxxxxx"          //Self registration generated
    appSecret "xxxxxxxxxx"    //Self registration generated

    ShareSDK {
        devInfo {     
            WechatMoments {                  //Wechat Moments
                appKey "Apply to wechat open platform"
                appSecret "Apply to wechat open platform"
                callbackUri "http://www.sharesdk.cn"
                shareByAppClient true
                bypassApproval="false"
            }

            Wechat {                        //WeChat
                appId "Apply to wechat open platform"
                appSecret "Apply to wechat open platform"
                userName "gh_afb25ac019c9"
                path "pages/index/index.html?id=1"
                withShareTicket true
                shareByAppClient true    
                miniprogramType 2
                bypassApproval false   
            }

        }
    }
}

 

Topics: Mobile Android network Gradle SDK