Android Simple Combat Tutorial--the sixth session of the development of a key lock screen application 2 • Complete

Source: Internet
Author: User
Tags transparent color

Reprint please indicate the source: http://blog.csdn.net/qq_32059827/article/details/51885687 Click to open the link

Previous, the initial development of the application, the function has been (see http://blog.csdn.net/qq_32059827/article/details/51860900 Click to open the link

)。 But two questions were left. 1, still cannot uninstall, 2, must manually click the application to enter the program, and then click the button, which seems very troublesome.

This article solves the above two problems and makes the best results.

Resolve the problem that cannot be uninstalled first:

In the manifest file, and then configure the main activity of one-click Uninstall (two main activities does not matter, just display two icons on the desktop, in fact, is 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 deactivation and uninstallation code:

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 {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {//Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_remove);} public void Remove (View v) {//Call Uninstall interface, to go to the upper source to see what the intention of uninstalling the interface.                By viewing the source code, as follows:/** * <intent-filter> <action android:name= "Android.intent.action.VIEW"/> <action android:name= "Android.intent.action.DELETE"/> <category android:name= "android.intent . category. DEFAULT "/> <data android:scheme=" package "/> </intent-filter> *///first to deactivate the activation setting before uninstalling Standby Manager//Get Device Manager Devicepolicymanager DPM = (devicepolicymanager) getsystemservice (Device_policy_service); ComponentName who = new ComponentName (this,dEviceadminsample.class);DP M.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 = new Intent ("an Droid.intent.action.DELETE "), Remove.addcategory (" Android.intent.category.DEFAULT "); Remove.setdata (Uri.parse (" Package: "+getpackagename ())"//means uninstall the program, Return the name of this application ' s packages. StartActivity (remove);//uninstall User apk Interface}}
But note that the new one-click Unload Layout, be sure to 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 button unload"/></relativelayout>


Run the program, when the user wants to uninstall, click on a button to uninstall into the uninstall interface, you can complete the uninstall of the application.

Finally, do some articles on the user experience:

This time, a key lock screen is achieved by clicking the button, in order to save trouble, do not open the lock screen interface.

Delete the lock screen button, Beijing is set to 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   </RelativeLayout>

Add a code to the Oncreat method of the lock screen activity: Lockscreen (NULL), indicating that no view is required to start the Click event.

To open the app, call the lock screen inside Lockscreen (View v) or turn on the Device Manager function, the code is as follows:

@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);d MP = ( Devicepolicymanager) Getsystemservice (Device_policy_service); lockscreen (null);}


At the same time, the one-click Uninstall app also does the same thing:

Rerun the program and enter the activation Device Manager interface as soon as it runs. Now put a button lock screen icon to the main interface, a click on the lock screen, especially convenient. and want to uninstall this program, a click on the direct uninstall off.

So far, this application has been perfectly developed. Seconds to kill 99% on the market one-click Lock Screen Application.

Here are the applications:




Android Simple Combat Tutorial--the sixth session of the development of a key lock screen application 2 • Complete

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.