The previous article introduced it to youAndroid realizes the function of opening Taobao on your mobile phone and automatically identifying Taobao password to pop up product informationNext, through this article, I will share with you the function of copying pop-up box of the Android simple version of Taobao password. I hope it will be helpful to everyone!
Use the Android system's pasteboard management service and ClipboardManager to add Listener through addPrimaryClipChangedListener to monitor the status of the pasteboard. It is a very simple small function~
1. First create a service to run in the background:
Intent intent = new Intent(this,); startService(intent);
In addition, the content copied by the paste board is obtained in OnResume(), which is used to restart the APP to pop up the exit window when the APP is not started or the Service is closed.
@Override protected void onResume() { // TODO Auto-generated method stub (); ClipboardManager mClipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); ("Copylistenerdemo", ().getItemAt(0).getText().toString()); }
2. Management Pasteboard service in Service:
mClipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); (mPrimaryClipChangedListener);
3. Do what you want in onPrimaryClipChanged(), such as pop-up box:
Use WindowManager to display popup boxes
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View floatView = (, null); final WindowManager mWindowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); LayoutParams params = new (); = .TYPE_SYSTEM_ERROR;//The system internal error prompt is displayed on all content = PixelFormat.RGBA_8888; = .FLAG_NOT_TOUCH_MODAL | .FLAG_NOT_FOCUSABLE; //When the window can get focus (the FLAG_NOT_FOCUSALBE option is not set), the point device events outside the window range (mouse, touch screen) are still sent to the subsequent window for processing = .MATCH_PARENT; = .WRAP_CONTENT; = | ; = 0; = 0; (floatView, params); ObjectAnimator animatorShow = (floatView, "alpha", 0.0f,1.0f); (500); (); ObjectAnimator animatorHide = (floatView, "alpha", 1.0f,0.0f); (500); (3000); ();
Click the pop-up box to jump to activity
(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub (, "Click Taobao password", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); (Intent.FLAG_ACTIVITY_NEW_TASK); (, ); startActivity(intent); } });
Very simple small functions, but there should be some small problems to be solved in the actual application process.
OK, let’s take a look at the principle of Taobao password: ClipBoard notes
Clipboard is a system service provided by Android. It provides a global clipboard that enables sharing of text, pictures, and data among multiple apps.
The basic use of Clipboard is divided into three steps:
Obtain ClipboardManager:
ClipboardManager mClipboardManager = mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
Copy:
ClipData mClipData; String text = "hello world"; mClipData = ("test", text); (mClipData);
Paste:
ClipData clipData = (); item = (0); String text = ().toString();
Get it done!
Summarize
The above is the Android imitation Taobao password copy pop-up function (short answer version) introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!