package com.esandinfo; import android.app.AlertDialog; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.text.TextUtils; import android.widget.Toast; import com.esandinfo.utils.MyLog; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 描述手機信息的檢測對象 */ public class PhoneInfoCheck { private final String SONY = "sony"; private final String OPPO = "oppo"; private final String HUAWEI = "huawei"; private final String HONOR = "honor"; private final String KNT = "knt"; private static PhoneInfoCheck instance = null; public static synchronized PhoneInfoCheck getInstance(Context context, String brand){ if (null == instance) instance = new PhoneInfoCheck(context, brand); return instance; } private Context context; private String brand; private PhoneInfoCheck(Context context, String brand) { this.context = context; this.brand = brand; } /** * 跳轉到指紋頁面 或 通知用戶去指紋錄入 */ public void startFingerprint() { String pcgName = null; String clsName = null; if (compareTextSame(SONY)){ pcgName = "com.android.settings"; clsName = "com.android.settings.Settings$FingerprintEnrollSuggestionActivity"; } else if (compareTextSame(OPPO)) { pcgName = "com.coloros.fingerprint"; clsName = "com.coloros.fingerprint.FingerLockActivity"; } else if (compareTextSame(HUAWEI)) { pcgName = "com.android.settings"; clsName = "com.android.settings.fingerprint.FingerprintSettingsActivity"; } else if (compareTextSame(HONOR)) { pcgName = "com.android.settings"; clsName = "com.android.settings.fingerprint.FingerprintSettingsActivity"; } // TODO 後續機型會繼續加入的 (Deliliu) // .... else { // 若是以上判斷沒有符合該機型,那就跳轉到設置界面,讓用戶本身設置吧 // Toast.makeText(context, "請到設置中,找到指紋錄入,進行指紋錄入操做", Toast.LENGTH_LONG).show(); new AlertDialog.Builder(context) .setTitle("指紋錄入") .setMessage("請到設置中,找到指紋錄入,進行指紋錄入操做") .setPositiveButton("好的,我去錄入指紋", null) .show(); // 跳轉到Settings頁面的Intent /*pcgName = "com.android.settings"; clsName = "com.android.settings.Settings";*/ } if (!TextUtils.isEmpty(pcgName) && !TextUtils.isEmpty(clsName)) { Intent intent = new Intent(); ComponentName componentName = new ComponentName(pcgName, clsName); intent.setAction(Intent.ACTION_VIEW); intent.setComponent(componentName); context.startActivity(intent); } } /** * 得到當前手機品牌 * @return 例如:HONOR */ private String getBrand() { MyLog.debug("PhoneInfoCheck Board:" + android.os.Build.BRAND + " brand:" + brand); return this.brand; } /** * 對比兩個字符串,而且比較字符串是否包含在其中的,而且忽略大小寫 * @param value * @return */ private boolean compareTextSame(String value) { return value.toUpperCase().indexOf(getBrand().toUpperCase()) >= 0 ; } @Deprecated public static void main(String[] args) { String str = "java JavA ABC"; Pattern test_ = Pattern.compile("java",Pattern.CASE_INSENSITIVE); Matcher result_ = test_.matcher(str); // str = result_.replaceAll("Perl6"); System.out.println(str); System.out.println(result_); // ----------------------------------- String str1 = "abcdefghijklmnabc"; String str2 = "HiJK"; // 查找是否存在指定的字符 System.out.println(str2.indexOf(str1)); // 忽略大小寫查找 System.out.println("HONOR".toUpperCase().indexOf("HONOR".toUpperCase()) >= 0); } }
/** * 引導指紋錄入 * @param view */ public void startFingerprint(View view) { final String BRAND = android.os.Build.BRAND; MyLog.debug("BRAND:" + BRAND); PhoneInfoCheck.getInstance(this, BRAND).startFingerprint(); }
佈局的Buttonjava
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="引導指紋錄入" android:onClick="startFingerprint" />
日誌打印:android
PhoneInfoCheck Board:HONOR brand:HONORapp
Honor V8 手機:佈局
點擊按鈕:測試
就跳轉到了 honor 手機的指紋驗證界面了:ui
而後輸入密碼,點擊下一步:this
而後就進入 honor 手機的 指紋管理 界面了,能夠錄入指紋了:spa