Android Third party application of the Information platform Research Sharing (ii) _android

Source: Internet
Author: User
Tags call back

The micro-trust platform is very hot after opening, many third-party applications want to try, after all, can use the micro-letter to build up the relationship chain to expand their application is very good, can save a lot of social expenses, I recently because of internship needs are also studying this thing, but found that the relevant information on the Internet is very small, Here my whole research situation is given out, hope can study together.

Third-party application platform (1)

Second, third-party applications and micro-letter communication sequence diagram

2, receive the micro-letter request Information


The previous four steps and the previous "1, send message to the micro-letter" is the same, do not need to repeat the execution, here is given only to

The integrity of the process. When we register, the application icon will appear in the micro-letter Chat list, click the plus sign to add,

When added, clicking on the application icon when chatting will callback the Third-party application, as shown in the timeline above. Here to add that

When we send a message to the micro-mail media type is the AppData type, that is, the Wxappextendobject object, the friend

When you receive a message, click the message, and a similar callback will occur, which needs to be modified when onreq is called, type

For constantsapi.command_showmessage_from_wx rather than constantsapi.command_getmessage_from_wx.

When we receive constantsapi.command_getmessage_from_wx in the Onreq method

Type of message, if you want to send the response back to the micro-letter, you can use the following code snippet to implement the


You can find that the message object for the response is the same as the send request, and look at the effect chart below

This is the Chat window, provided you have clicked the plus sign to add the application to the list below


At this point, if you click on a third party application, it will call back to our set of interfaces.


This interface is defined by itself, and you can customize the response interface after receiving a request from a micro-letter.

For a long time, I haven't talked about the origin of the Onreq method or the Onresp method mentioned earlier,

In other words, if we want to process feedback or respond to a request for a micro-letter.

What to do, we need the following 3 steps:

A. You can create a new WXAPI directory under the appropriate directory of your package name and add a new one in the Wxapi directory
Wxentryactivity class, which inherits from the activity (the path is, of course, custom, whatever you want)

and add the exported attribute to the manifest file, set to True, for example:

Copy Code code as follows:

<activity
Android:name= ". Wxapi. Wxentryactivity "
Android:exported= "true"
Android:label= "@string/app_name"
Android:launchmode= "Singletop" >

B. Implementation of the Iwxapieventhandler interface, micro-mail sent requests will be callback to the Onreq method, send
The response to the micro-letter request will be recalled to the Onresp method

Finally there are two magical ways to look at their approximate usage

Copy Code code as follows:

<span style= "FONT-SIZE:18PX; Font-family:microsoft Yahei "> @Override
public void Onreq (Basereq req) {
Switch (Req.gettype ()) {
Case CONSTANTSAPI.COMMAND_GETMESSAGE_FROM_WX:
Gotogetmsg ();
Break
Case CONSTANTSAPI.COMMAND_SHOWMESSAGE_FROM_WX:
Gotoshowmsg ((showmessagefromwx.req) Req);
Break
Default
Break
}
}</span>

Copy Code code as follows:

<span style= "FONT-SIZE:18PX; Font-family:microsoft Yahei "> @Override
public void Onresp (Baseresp resp) {
int result = 0;

Switch (resp.errcode) {
Case BaseResp.ErrCode.ERR_OK:
result = r.string.errcode_success;
Break
Case BaseResp.ErrCode.ERR_USER_CANCEL:
result = R.string.errcode_cancel;
Break
Case BaseResp.ErrCode.ERR_AUTH_DENIED:
result = R.string.errcode_deny;
Break
Default
result = R.string.errcode_unknown;
Break
}

Toast.maketext (this, result, Toast.length_long). Show ();
}</span>

C. The intent received in wxentryactivity and the pair that implements the Iwxapieventhandler interface
Like the Handleintent method passed to the Iwxapi interface:
Copy Code code as follows:

Api.handleintent (Intent, this);

OK, these three steps can be combined with the sequence diagram to understand, all can correspond.

Finally give some attention to point, is also easy to confuse, I have written demo verified, if you feel that there is wrong, welcome to point out, welcome to discuss

1, registration is a local registration, and only need to register once, but at the time of sending the micro-trust server will detect the legality of Third-party applications

2, the white is in the local Third-party applications will be sent to the content of the first micro-trust process, micro-trust process received and then send the message to their micro-trust friends

3, uninstall or reverse registration, the Third-party application will not appear in the local micro-letter can add application list

4, the use of micro-letter open platform to send Media objects, Web pages, audio and video can only be network URL, pictures can send local path, local byte data, network URL, file can send local byte data and local path, with a byte array in the media object, micro-letter by default will be clicked to give the download interface, After downloading the path is stored in the/sdcard/tecent/micromsg/native micro-letter account (usually a string of alphanumeric combinations)/attachment folder, this path does not need to record, the micro-letter will be in the Media Object filepath field record, It is important to note at this point that when you respond to a micro-letter show request, the Filedata field in the media object is empty, even if you are attached to the field when you send it, as previously mentioned, you can only use the FilePath field.

if you want to handle only AppData type data, here's why :

The only special point of the AppData type is to tell the micro-letter that the message needs to invoke a third party application when clicked, while other types of media objects are clicked to show the default page of the micro-letter

5, micro-letter based on the transaction field to determine the message in the Chat box performance and click on the response, only appdata when clicked can invoke the process of third-party applications, the triggering method is to implement the Iwxapieventhandler interface of the class Onreq method, Type is constantsapi.command_showmessage_from_wx while chatting with a friend in a micro-letter and clicking on a third party application icon triggers the method that implements the Iwxapieventhandler interface's class Onreq method, Type is CONSTANTSAPI.COMMAND_GETMESSAGE_FROM_WX

6, the micro-letter will be based on Third-party applications are registered to give the application installation information, for example, to a micro-trust friend an audio message, when the friend clicks on the message, the micro-letter will be a webview to load audio messages in the URL, but before the URL appended with some micro-letter definition of information, This will include a field that isinstalled the specific format of the URL after the micro-mail package, we can disconnect the network, and then click, then the natural appearance of the classic interface, you will be able to see the true nature of the URL because I wrote the demo in the internship after the end of the Lost, So give an official demo download, if there is not clear can communicate

Thank you for your cooperation and hope to learn together.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.