Home > WeChat Applet > WeChat Development > I have discovered some pitfalls after logging in and sharing on Android WeChat for a while.

I have discovered some pitfalls after logging in and sharing on Android WeChat for a while.

php是最好的语言
Release: 2018-08-02 11:08:18
Original
5347 people have browsed it

Some pitfalls I have discovered after doing WeChat login and sharing for a while:
1. First of all, in addition to obtaining the AppID, the Android application must pass the review. Otherwise, WeChat cannot be called up for sharing, and it needs to be on the website. Fill in the package name and signature fields. The signature can be obtained using the signature generation tool. If you have special needs, please refer to "Signature Generation Method" to generate it yourself.
See WeChat Open Platform-->Mobile Application-->FAQ-->Android FAQ and WeChat Open Platform-->Resource Download-->android Resource Download-->Signature Generation Tool Download
2. The signature and package name in the first step must be written correctly. The second question is how to receive the callback from WeChat

a. Create a new wxapi directory in the directory corresponding to your package name. , and add a WXEntryActivity class in the wxapi directory, which inherits from Activity()
And add the exported attribute to the manifest file, set it to true, and set the startup mode to singleTop to ensure that it will not be created repeatedly.
Because WeChat will call up a new activity: WXEntryActivity when calling back, so the transparent style must be set (otherwise the user will perceive that a new activity is started), and finish WXEntryActivity in the onResp method
For example:

<!--非要设置成透明的才不会对用户造成困扰-->
        <activity
            android:name=".wxapi.WXEntryActivity"
            android:theme="@android:style/Theme.Translucent"
            android:label="@string/app_name"
            android:exported="true"
            android:launchMode="singleTop">

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="sdksample"/>
            </intent-filter>
        </activity>
Copy after login

b. Implement the IWXAPIEventHandler interface, the request sent by WeChat will be called back to the onReq method, and the response result sent to the WeChat request will be called back to the onResp method

c. In WXEntryActivity, the received The intent and the object that implements the IWXAPIEventHandler interface are passed to the handleIntent method of the IWXAPI interface, and the onResp method will be corresponding.

Related articles:

Detailed graphic explanation of Android development WeChat authorized login and WeChat sharing analysis

Detailed explanation of the method of Android programming to implement WeChat sharing information

Related videos:

Android Development Manual

The above is the detailed content of I have discovered some pitfalls after logging in and sharing on Android WeChat for a while.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template