Android applications can easily complete these functions, many applications have "sharing" function? How to share it? Let's talk about it.
Recently, someone asked the Android sharing feature to use that better, using the Android intent to share it or with a third party, directly code:
Use intent to communicate directly with a third party application:
/** * Sharing function * * @param context * @param activitytitle * Activ
Ity's name * @param msgtitle * Message title * @param msgtext * message content * @param imgpath * Image path, do not share the picture will pass NULL/ public void Shareutil (string activitytitle, String msgtitle, String msgtext, String imgpath) {Intent Intent = new
Intent (Intent.action_send); if (Imgpath = = NULL | | imgpath.equals ("")) {Intent.settype ("Text/plain");
Plain text} else {file F = new file (Imgpath);
if (f!= null && f.exists () && f.isfile ()) {Intent.settype ("image/jpg");
Uri u = uri.fromfile (f);
Intent.putextra (Intent.extra_stream, u);
} Intent.putextra (Intent.extra_subject, msgtitle);
Intent.putextra (Intent.extra_text, Msgtext);
Intent.setflags (Intent.flag_activity_new_task);
StartActivity (Intent.createchooser (Intent, activitytitle)); }
Looking at the code is not very simple, but to use the above code to share success, you must let the current device must install micro-letter to achieve sharing. Although the use of micro-letter is very high, it is common, but have to prevent accidental appearance, and its share has limitations, the most is to share a text plus pictures, if the application upgrade is difficult.
second, the use of third-party sharing tools , such as friends, SHARESDK (support a variety of social platforms).
And does not require equipment to install micro-letters. This detailed use, if the use of a third party should know how to use, detailed access to the corresponding documents to view, looks very tall third party, and easy to use, but third party after all, you know.
Third, the use of micro-letter of the Official SDK package, this way does not require device installation micro-letter.
It is implemented in the same way as the second, after all, is to access the third generation side, although it is also a third party, but I think Tencent's more reliable, and then we share the ultimate goal, the most common platform is not, here is not a detailed description of how to access, just talk about access skills, and often encountered problems (if you are novice, haha, The following access steps are best not to mess up.
1. Establish your own application (Sharetestdemo)
After the application is established, run the program first, and note that when you run it, the Android default Debug.keystore signature is used.
2. To the micro-credit development platform website Http://open.weixin.qq.com/download/?lang=zh_CN Download Development Kit, unzip, copy Libammsdk.jar to Libs, and add it to build path.
3. To the micro-credit development platform website Http://open.weixin.qq.com/agreement to create your application, the use of the third party know what meaning, so this eliminates the front of those basic operations (do not understand can go to the platform https:// OPEN.WEIXIN.QQ.COM/CGI-BIN/FRAME?T=HOME/APP_TMPL&LANG=ZH_CN take a look at the access process), the following steps are the main focus here.
One step is to sign our program with a APK tool to sign the letter, because our program has been installed, so the direct download installation, and then in the phone inside the box to enter the package name (package name can not be filled in the wrong), click the Generate button, this time will generate a MD5 encryption value, Enter it into the box where the application page was created (at this point, we note that if our application is not yet installed on the phone, the signing tool prompts you not to find the related package).
Then enter the package name (the package name must not be filled in error), and then submit the review. The next step is to wait for the micro-credit official to review. During the audit, we got to create the application by the micro-letter provided by the AppID access to our own applications (according to access documents or reference micro-letter provided by the demo), is basically completed the half work, and then the audit passed the normal use of the.
4. After the completion of the above process, in fact, our application has realized the sharing function, the minimum test passed, but once we use the formal signature file for packaging, installation, release, the results found that the sharing function is not available, the micro-credit sharing API can not be adjusted, this time don't panic, back to the first step, we said need to pay attention to " Note that you are running at this time using the Android default Debug.keystore signature. "This sentence, is the signature file caused by the problem, in the use of third parties, especially to pay attention to this issue, including micro-credit Alipay, etc. are the same, found the problem, the next is not simple (we apply for AppID when filling in the application signature is generated with Debug.keystore.) Instead of our official signature file Xxx.keystore The program for formal packaging, and then installed to the phone, and then run the micro-letter that signed APK tool, the name of our package into the inside (the package name can not be filled in the wrong), regenerate a MD5 encryption value, and then to the official website http:// Open.weixin.qq.com/agreement, find the application you created, click Modify, enter the signature that you just generated, and then save the resubmit review. After the approval, we want to use the sharing function, we must formally packaged installation.
5. After the success of the micro-letter sharing, feedback on the results of the micro-letter sharing information, this should be noted below two points, if it is not not received to share feedback. (Payment and other operations should be noted)
(1) The name of this activity must be wxentryactivity
(2) Wxentryactivity This class must be based on the application package name +WXAPI Package
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.