乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      [安卓] 15、用NFC解鎖手機并自動打開應(yīng)用

       看見就非常 2015-11-20

       

       

      最近接到一個項目:將手機放到一個帶有NFC卡的底座上手機會自動解鎖,然后打開相應(yīng)的應(yīng)用

      本人用:杭州公交通用卡做為NFC卡+Coolpad手機進(jìn)行試驗

      效果如下:

       1、手機本身帶有圖案鎖,輸對圖案才能解鎖

       2、Coolpad帶有NFC功能

       3、把手機內(nèi)的所有正在運行的應(yīng)用清空

       4、關(guān)閉手機(目前處于鎖住狀態(tài))

       5、將NFC卡靠近

       6、自動解鎖+啟動應(yīng)用

       

       

       

      注:我用華為的手機無法實現(xiàn)突破鎖屏、打開應(yīng)用的效果

       

      工程核心代碼

      整個代碼比較簡單:(新建一個工程)在AndroidManifest.xml加入uses-feature和permission

      同時還要在相應(yīng)的activity中加入intent-filter,這里注意一定要加:<category android:name="android.intent.category.DEFAULT" />

      復(fù)制代碼
       1 <?xml version="1.0" encoding="utf-8"?>
       2 <manifest xmlns:android="http://schemas./apk/res/android"
       3     package="com.beautifulzzzz.nfc_test"
       4     android:versionCode="1"
       5     android:versionName="1.0" >
       6 
       7     <uses-sdk
       8         android:minSdkVersion="14"
       9         android:targetSdkVersion="19" />
      10 
      11   <!--
      12         see http://www./ws/android/nfc-programming-in-android.html for reference (note
      13         that the minimum API version must be set as 10 in build.gradle (Module: app) for this to work,
      14         and that classes being used from the nfc package require a minimum API version 14):
      15     -->
      16     <uses-feature
      17         android:name="android.hardware.nfc"
      18         android:required="true" />
      19     <uses-permission android:name="android.permission.NFC" />
      20     
      21     <uses-permission android:name="android.permission.WAKE_LOCK"/>    
      22     <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>  
      23 
      24     <application
      25         android:allowBackup="true"
      26         android:icon="@drawable/ic_launcher"
      27         android:label="@string/app_name"
      28         android:theme="@style/AppTheme" >
      29         <activity
      30             android:name=".Activity_Main"
      31             android:label="@string/app_name" >
      32             <intent-filter>
      33                 <action android:name="android.intent.action.MAIN" />
      34                 <category android:name="android.intent.category.LAUNCHER" />
      35             </intent-filter>                
      36             
      37             <intent-filter>
      38                 <action android:name="android.nfc.action.TAG_DISCOVERED" />
      39                 <category android:name="android.intent.category.DEFAULT" />
      40             </intent-filter>  
      41         </activity>
      42     </application>
      43 
      44 </manifest>
      復(fù)制代碼

      Activity中也比較簡單——

      onCreate中檢測硬件是否支持和是否打開NFC

      onResume中通過getIntent().getAction()獲取當(dāng)前的action然后顯示在UI的文本顯示區(qū)中

        第34-48行是沖破圖案鎖,電量屏幕用的

      復(fù)制代碼
       1 public class Activity_Main extends Activity {
       2 
       3     NfcAdapter nfcAdapter;  
       4     TextView promt;  
       5     @Override  
       6     public void onCreate(Bundle savedInstanceState) {  
       7         super.onCreate(savedInstanceState);  
       8         setContentView(R.layout.ui_main); 
       9         promt = (TextView) findViewById(R.id.promt);  
      10         // 獲取默認(rèn)的NFC控制器  
      11         nfcAdapter = NfcAdapter.getDefaultAdapter(this);  
      12         if (nfcAdapter == null) {  
      13             promt.setText("設(shè)備不支持NFC!");  
      14             System.out.println("設(shè)備不支持NFC!");  
      15             finish();  
      16             return;  
      17         }  
      18         if (!nfcAdapter.isEnabled()) {  
      19             promt.setText("請在系統(tǒng)設(shè)置中先啟用NFC功能!");  
      20             System.out.println("請在系統(tǒng)設(shè)置中先啟用NFC功能!");  
      21             finish();  
      22             return;  
      23         }
      24         promt.setText("正常啟用APP!");  
      25         System.out.println("正常啟用APP!"); 
      26     }  
      27   
      28     @Override  
      29     protected void onResume() {  
      30         super.onResume(); 
      31         promt.setText(getIntent().getAction());  
      32         System.out.println("正常啟用APP!"); 
      33         
      34         PowerManager pm=(PowerManager) getSystemService(Context.POWER_SERVICE);  
      35         //獲取電源管理器對象  
      36         PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");  
      37         //獲取PowerManager.WakeLock對象,后面的參數(shù)|表示同時傳入兩個值,最后的是LogCat里用的Tag  
      38         wl.acquire();  
      39         //點亮屏幕  
      40         wl.release();  
      41         //釋放  
      42    
      43         KeyguardManager  km= (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);  
      44         //得到鍵盤鎖管理器對象  
      45         KeyguardLock kl = km.newKeyguardLock("unLock");    
      46         //參數(shù)是LogCat里用的Tag  
      47         kl.disableKeyguard();   
      48         //解鎖</pre><br><br>  
      49     } 
      50 }
      復(fù)制代碼

       

      資源鏈接

      Android 解屏幕鎖與點亮屏幕(來電時效果)

      android之a(chǎn)ndroid.intent.category.DEFAULT的用途和使用

      Android NFC開發(fā)概述(作者找了很多網(wǎng)上的NFC資料,可參考,有疏漏)

      Android NFC 開發(fā)實例(一個簡單的demo,我試了幾下有點小問題,可參考)

      本工程下載地址:http://pan.baidu.com/s/1c04ries 

       

       

      @beautifulzzzz

        2015-11-02 持續(xù)更新中~

       

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多