Android development realizes opening Taobao on mobile phones, and automatically identifying Taobao passwords to pop up product information. Everyone has encountered that they were inexplicably pulled into a WeChat group, and then the group owner began to send some product links. When we click on this link, we will copy a password (just like this ¥AzZK0hPyou5¥). When we copy this password to open Taobao, the product information will automatically pop up. Today, let’s share with you how this requirement is achieved.
1. First of all, we need the backend to help us connect to Taobao's product interface, because this thing (¥AzZK0hPyou5¥) is provided by Taobao. All we have to do is request our backend through the network and get this password. As for how the backend calls Taobao's interface, we don't need to worry about this at all.
2. After getting this password, the first step is to open Taobao. Friends here, please note that we only need to open the Taobao program on mobile phones, and there is no need to enter the product details page (most of the online talks about how to enter the product details page, but for our needs, entering the product details page is not applicable). We can use the following code to start mobile phone Taobao.
Intent intent = getPackageManager().getLaunchIntentForPackage(""); startActivity(intent);
The above code is easy to understand. An intent is created through the Taobao package name (Note: "" is the package name of Taobao mobile phone), and finally open the activity corresponding to this intent.
3. Although we have been able to successfully open Taobao at this time, how do we make Taobao automatically recognize the product information corresponding to the password we copied? I was stuck here for a long time. We might as well look back at the operation steps in the WeChat group. Open the link, copy the product password, and then open Taobao. The product information will automatically pop up (PS: Thanks to my IOS partner here). We just did a copy operation and the product information will automatically pop up. The key to the problem should be here.
4. Since it is copying, it must be copied to the system's clipboard. We can use the following code to copy the password to the system's clipboard.
//Get the clipboard manager:ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); // Create a normal character type ClipDataClipData mClipData = ("Label", "¥AzZK0hPyou5¥"); // Put ClipData content into the system clipboard.(mClipData);
Note: ClipboardManager and ClipData are under the following two packages respectively
import ; import ;
5. The order of the steps I have here is wrong. It should be to copy the information to the clipboard first, then open Taobao, and change the order of steps 2 and 4. I am here to record my wrong thoughts at that time, so the layout has not been changed. I hope everyone will forgive me!
Finally: This requirement is completed here. It is actually quite simple. I hope it can help friends in need!
PS: Let's take a look at the implementation code of android imitation Taobao Taobao password
Copy *wangbin1* password to open the APP
Execute code blocks in main activity onResume
public void GangUpInvite(final Context context) { ClipboardManager clipboard = (ClipboardManager) (CLIPBOARD_SERVICE); //Return directly when there is no data if (!()) { return; } //If it is text information if (().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { ClipData cdText = (); item = (0); //This is the TEXT text information if (() != null) { String str = ().toString(); String key = "*"; final int first = (key); if (first >= 0) { String new1 = (first + 1); int tow = (key); if (tow >= 0) { String new2 = (0, tow); (new2); if (() == 8) { //new2 is the password string } } } } } }
Get the key to cooperate with the backend to get the password-related information
Summarize
The above is the Android function that the editor introduced to you to enable the Android phone to open Taobao and automatically recognize Taobao password to pop up product information. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!