The previous article, the initial development of this application, features are available (see http://www.jb51.net/article/96992.htm Click to open the link).
But left two problems: 1, or unable to uninstall, 2, must manually click on the application to enter the program, and then click the button, which seems very troublesome.
This one will solve the above two problems and make the best effect.
First troubleshoot problems that cannot be uninstalled:
In the manifest file, configure one key uninstall main activity (two main activities do not matter, only two icons on the desktop, but still an application)
<activity
android:name= "Com.itydl.lockscreen.Remove"
android:label= "one-click Uninstall" >
<intent-filter >
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= " Android.intent.category.LAUNCHER "/>
</intent-filter>
</activity>
In the new activity, write the code to cancel activation and uninstall:
Package com.itydl.lockscreen;
Import android.app.Activity;
Import Android.app.admin.DevicePolicyManager;
Import Android.content.ComponentName;
Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.view.View; public class Remove extends activity {@Override protected void onCreate (Bundle savedinstancestate) {//SUPER.O
Ncreate (savedinstancestate);
Setcontentview (R.layout.activity_remove); public void Remove (View v) {//Invoke the uninstalled interface, go to the upper source to see what the Uninstall interface is intended for. By looking at the source code, as follows:/** * <intent-filter> <action android:name= "Android.intent.action.VIEW"/> <act Ion Android:name= "Android.intent.action.DELETE"/> <category android:name= "Android.intent.category.DEFAULT"/ > <data android:scheme= "package"/> </intent-filter>///To cancel the Activation Device Manager//Get device tube before uninstalling
Manager Devicepolicymanager DPM = (devicepolicymanager) getsystemservice (Device_policy_service); ComponenTname who = new ComponentName (this,deviceadminsample.class); Dpm.removeactiveadmin (WHO),//remove a current administration component. This can is called by the application that owns the administration component//uninstall, start uninstall interface Intent remove = NE
W Intent ("Android.intent.action.DELETE");
Remove.addcategory ("Android.intent.category.DEFAULT");
Remove.setdata (Uri.parse ("Package:" +getpackagename ());//means uninstall this program, return the name of this application ' s package.
StartActivity (remove),//uninstall User apk Interface}}
Note, however, that the new one-click Uninstall layout must make the following modifications:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http:// Schemas.android.com/tools "
android:layout_width=" match_parent "
android:layout_height=" Match_parent " >--------------------must be modified here.
<button
android:onclick= "Remove"
android:layout_width= "wrap_content"
android:layout_height = "Wrap_content"
android:text= "one-click Uninstall"/>
</RelativeLayout>
Run the program, when the user wants to uninstall, click a key uninstall into the uninstall interface, you can complete the uninstall of this application.
Finally, do some article on the user experience:
This time, a key lock screen is achieved by clicking on the button, in order to save trouble, do not open the interface of the lock screen.
Remove the screen button and set the background to a transparent color
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http:// Schemas.android.com/tools "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
android:background= "#00000000" >
---------------------set to Transparent color
Add a code to the Oncreat method of the lock screen activity: Lockscreen (NULL), which means that no view is required to initiate the Click event.
This opens the application to call the Lockscreen (View v) inside the lock screen or to open the Device Manager function, the code is as follows:
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
DMP = (Devicepolicymanager) getsystemservice (device_policy_service);
Lockscreen (null);
}
Also, one-click Uninstall application does the same thing:
Rerun the program and go into the Activation Device Manager interface as soon as it runs. Now put a key lock screen icon to the main interface, a click on the lock screen, particularly convenient. and want to uninstall this program, a click on the direct uninstall off.
So far, this application, the perfect development of the second kill market 99% of a key lock screen application.
Here is a screenshot of the application:
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.