0
백그라운드에서 작동해야하는 지문 인식 응용 프로그램을 개발 중이며 계속해서 원하는 작업을 수행하기 위해 사용자의 지문 입력을 계속 수신합니다. 지금까지 IntentService를 사용하여 백그라운드에서 지문 스캐너를 작동 시키려고했지만 액티비티를 닫거나 최소화하면 지문 스캐너가 작동을 멈 춥니 다. 내 활동이 종료 된 후에도 백그라운드에서 지문 스캐너를 사용할 수있는 방법이 있습니까? 다음은 코드 아래에이 시도 할 수백그라운드에서 안드로이드 장치의 지문을 계속 수신합니다.
public class AsyncService extends IntentService {
private int ONGOING_NOTIFICATION_ID=2346712;
public AsyncService() {
super(AsyncService.class.getName());
}
@Override
protected void onHandleIntent(Intent intent) {
showNotification();
new FingerprintHandler().startAuth(Provider.fpManager,Provider.cryptoObj);
}
public void showNotification() {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification =
new Notification.Builder(this)
.setContentTitle(getText(R.string.notification_title))
.setContentText(getText(R.string.notification_message))
.setSmallIcon(R.drawable.launcher)
.setContentIntent(pendingIntent)
.build();
startForeground(ONGOING_NOTIFICATION_ID, notification);
}
public class FingerprintHandler extends FingerprintManager.AuthenticationCallback {
private CancellationSignal cancellationSignal;
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject)
{
cancellationSignal = new CancellationSignal();
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED)
{
return;
}
manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
@Override
public void onAuthenticationError(int errMsgId, CharSequence errString)
{
}
@Override
public void onAuthenticationFailed()
{
//some action to perform
}
@Override
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString)
{
}
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result)
{
//some action to perform
}
}
}
Provider.java
public class Provider {
public static FingerprintManager fpManager;
public static FingerprintManager.CryptoObject cryptoObj;
public static Context mContext;
public Provider(FingerprintManager fingerprintManager, FingerprintManager.CryptoObject cryptoObject, Context context) {
fpManager=fingerprintManager;
cryptoObj=cryptoObject;
mContext=context;
}
}