एंड्रॉइड में फिंगरप्रिंट नामांकन स्थिति जांचने का पूरा गाइड
यह ट्यूटोरियल दर्शाता है कि कैसे प्रोग्रामेटिक रूप से जांचा जाए कि एंड्रॉइड डिवाइस पर कोई फिंगरप्रिंट नामांकित (रजिस्टर्ड) है या नहीं। हम FingerprintManager क्लास और इसकी hasEnrolledFingerprints() विधि का उपयोग करेंगे।
आवश्यक शर्तें
- एंड्रॉइड स्टूडियो इंस्टॉल होना चाहिए
- फिंगरप्रिंट सेंसर वाला वास्तविक एंड्रॉइड डिवाइस (एमुलेटर पर काम नहीं करेगा)
- न्यूनतम API लेवल 23 (Android 6.0 Marshmallow) या उससे ऊपर
चरण 1: नया प्रोजेक्ट बनाएं
एंड्रॉइड स्टूडियो खोलें → File → New Project चुनें → "Empty Activity" चुनें → प्रोजेक्ट का नाम, पैकेज नाम, सेव लोकेशन दर्ज करें → Finish पर क्लिक करें।
चरण 2: लेआउट फ़ाइल संशोधित करें (res/layout/activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/actionEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_marginTop="30dp"
android:padding="16dp"/>
</LinearLayout>
हमने एक TextView जोड़ा है जो फिंगरप्रिंट मैनेजर की जानकारी प्रदर्शित करेगा।
चरण 3: मेन एक्टिविटी कोड जोड़ें (src/MainActivity.java)
package com.example.fingerprintcheck;
import android.Manifest;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
public class MainActivity extends AppCompatActivity {
private TextView resultTextView;
private FingerprintManager fingerprintManager;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultTextView = findViewById(R.id.actionEvent);
fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
// रनटाइम परमिशन जांचें (Android 6.0+ के लिए आवश्यक)
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.USE_FINGERPRINT}, 101);
return;
}
checkFingerprintEnrollment();
}
@RequiresApi(api = Build.VERSION_CODES.M)
private void checkFingerprintEnrollment() {
boolean hasEnrolled = fingerprintManager.hasEnrolledFingerprints();
String message = hasEnrolled ? "फिंगरप्रिंट नामांकित है ✓" : "कोई फिंगरप्रिंट नामांकित नहीं ✗";
resultTextView.setText(message);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 101 && grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
checkFingerprintEnrollment();
} else {
resultTextView.setText("फिंगरप्रिंट परमिशन अस्वीकृत");
}
}
}
चरण 4: मैनिफेस्ट में परमिशन जोड़ें (AndroidManifest.xml)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.example.fingerprintcheck">
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-feature android:name="android.hardware.fingerprint" android:required="false" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FingerprintCheck">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
चरण 5: ऐप चलाएं और टेस्ट करें
- USB डिबगिंग सक्षम करके अपना एंड्रॉइड डिवाइस कनेक्ट करें
- एंड्रॉइड स्टूडियो में Run आइकन (▶) पर क्लिक करें
- डिप्लॉयमेंट टारगेट के रूप में अपना डिवाइस चुनें
- ऐप लॉन्च होगा और फिंगरप्रिंट नामांकन स्थिति दिखाएगा
महत्वपूर्ण नोट्स
- USE_FINGERPRINT परमिशन Android 10 (API 29) में
USE_BIOMETRICद्वारा प्रतिस्थापित की गई है - आधुनिक ऐप्स के लिए
BiometricPromptAPI का उपयोग करने पर विचार करें - यह कोड केवल नामांकन स्थिति जांचता है, वास्तविक फिंगरप्रिंट प्रमाणीकरण नहीं करता
- डिवाइस में फिंगरप्रिंट हार्डवेयर होना चाहिए और लॉक स्क्रीन सेटअप होना चाहिए
सामान्य समस्याएं और समाधान
| समस्या | समाधान |
|---|---|
| हमेशा "कोई फिंगरप्रिंट नहीं" दिखाता है | सेटिंग्स → सुरक्षा → फिंगरप्रिंट में जाकर फिंगरप्रिंट जोड़ें |
| SecurityException क्रैश | रनटाइम परमिशन अनुरोध जोड़ें (ऊपर कोड में दिखाया गया है) |
| एमुलेटर पर काम नहीं करता | केवल वास्तविक हार्डवेयर डिवाइस पर टेस्ट करें |
