recently received an item: Place your phone on a cradle with an NFC card and the phone will automatically unlock, then open the appropriate app
I use: Hangzhou Bus General card as an NFC card +coolpad mobile phone test
The effect is as follows:
1, the phone itself with a pattern lock, lost to the pattern to unlock
2. Coolpad with NFC function
3. Empty all running apps in the phone
4. Turn off the phone (currently in locked state)
5. Close the NFC card
6. Automatic Unlock + start Application
Note: I use Huawei's mobile phone can not achieve the breakthrough lock screen, open the application effect
Engineering Core Code
The whole code is simple: (Create a new project) join Uses-feature and permission in Androidmanifest.xml
At the same time also in the corresponding activity to add intent-filter, here Note must add: <category android:name= "Android.intent.category.DEFAULT"/>
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3 Package= "Com.beautifulzzzz.nfc_test"4 Android:versioncode= "1"5 Android:versionname= "1.0" >6 7 <USES-SDK8 android:minsdkversion= "+"9 android:targetsdkversion= "+" />Ten One <!-- A See http://www.developer.com/ws/android/nfc-programming-in-android.html for reference (note - that the minimum API version must is set as ten in Build.gradle (Module:app) for the - and that classes being used from the NFC package require a minimum API version): the - - <uses-feature - Android:name= "ANDROID.HARDWARE.NFC" - android:required= "true" /> + <uses-permissionAndroid:name= "Android.permission.NFC" /> about <uses-permissionAndroid:name= "Android.permission.WAKE_LOCK"/> A <uses-permissionAndroid:name= "Android.permission.DISABLE_KEYGUARD"/> at - <Application - Android:allowbackup= "true" - Android:icon= "@drawable/ic_launcher" - Android:label= "@string/app_name" - Android:theme= "@style/apptheme" > in <Activity - Android:name=". Activity_main " to Android:label= "@string/app_name" > + <Intent-filter> - <ActionAndroid:name= "Android.intent.action.MAIN" /> the <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> * </Intent-filter> $ Panax Notoginseng <Intent-filter> - <ActionAndroid:name= "Android.nfc.action.TAG_DISCOVERED" /> the <categoryAndroid:name= "Android.intent.category.DEFAULT" /> + </Intent-filter> A </Activity> the </Application> + - </Manifest>
The activity is also relatively simple--
OnCreate detect if the hardware supports and whether NFC is turned on
Onresume by Getintent (). Getaction () Gets the current action and then displays it in the text display area of the UI
第34-48 line is to break through the pattern lock, power screen with
1 Public classActivity_mainextendsActivity {2 3 Nfcadapter Nfcadapter; 4 TextView promt; 5 @Override6 Public voidonCreate (Bundle savedinstancestate) {7 Super. OnCreate (savedinstancestate); 8 Setcontentview (r.layout.ui_main);9PROMT =(TextView) Findviewbyid (R.ID.PROMT); Ten //Get the default NFC controller OneNfcadapter = Nfcadapter.getdefaultadapter ( This); A if(Nfcadapter = =NULL) { -Promt.settext ("Device does not support nfc! "); -SYSTEM.OUT.PRINTLN ("Device does not support nfc! "); the finish (); - return; - } - if(!nfcadapter.isenabled ()) { +Promt.settext ("Enable the NFC feature in System Setup first!") "); -System.out.println ("Enable the NFC feature in System Setup first!") "); + finish (); A return; at } -Promt.settext ("normal enable app! "); -System.out.println ("normal enable app! "); - } - - @Override in protected voidOnresume () { - Super. Onresume (); to Promt.settext (Getintent (). Getaction ()); +System.out.println ("normal enable app! "); - thePowerManager pm=(PowerManager) Getsystemservice (Context.power_service); * //get the Power Manager object $Powermanager.wakelock wl = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.screen_dim_wake_lock, "Bright"); Panax Notoginseng //gets the Powermanager.wakelock object, followed by the argument | To pass in two values at the same time, and finally the tag used in Logcat . - Wl.acquire (); the //light the screen. + wl.release (); A //Release the +Keyguardmanager km=(Keyguardmanager) Getsystemservice (Context.keyguard_service); - //get the keyboard lock manager Object $Keyguardlock KL = Km.newkeyguardlock ("UnLock"); $ //parameter is the tag used in Logcat . - Kl.disablekeyguard (); - //Unlock </pre><br><br> the } -}
Resource Links
Android unlock screen lock with light on (incoming call effect)
Uses and uses of Android Android.intent.category.DEFAULT
Android NFC Development Overview (the author has found a lot of NFC data on the Internet, can refer to, there are omissions)
Android NFC Development Example (a simple demo, I tried a few little questions, can refer to)
This project: http://pan.baidu.com/s/1c04ries
@beautifulzzzz
2015-11-02 Continuous Update in ~
[Android] 15, unlock your phone with NFC and open the app automatically