how to store fingerprint data in database android - android

I am using mantra fingerprint scanner to get finger print data, I want to store the fingerprint data in mysql.Later i want to compare with other. I am facing issue in Storing the data in mysql.
here is the code where after scanner gives the fingerprint data.
private void StartSyncCapture() {
runOnUiThread(new Thread(new Runnable() {
#Override
public void run() {
try {
FingerData fingerData = new FingerData();
int ret = mfs100.AutoCapture(fingerData, timeout, false,
true);
if (ret != 0) {
Toast.makeText(getApplicationContext(), "StartSyncCapture " + mfs100.GetErrorMsg(ret), Toast.LENGTH_SHORT).show();
} else {
if (fingerData.Quality() >= minQuality) {
final Bitmap bitmap = BitmapFactory.decodeByteArray(
fingerData.FingerImage(), 0,
fingerData.FingerImage().length);
imgFinger.post(new Runnable() {
#Override
public void run() {
imgFinger.setImageBitmap(bitmap);
imgFinger.refreshDrawableState();
}
});
Toast.makeText(getApplicationContext(), "Capture Success", Toast.LENGTH_SHORT).show();
String log = "\nQuality: " + fingerData.Quality()
+ "\nNFIQ: " + fingerData.Nfiq()
+ "\nWSQ Compress Ratio: "
+ fingerData.WSQCompressRatio()
+ "\nImage Dimensions (inch): "
+ fingerData.InWidth() + "\" X "
+ fingerData.InHeight() + "\""
+ "\nImage Area (inch): " + fingerData.InArea()
+ "\"" + "\nResolution (dpi/ppi): "
+ fingerData.Resolution() + "\nGray Scale: "
+ fingerData.GrayScale() + "\nBits Per Pixal: "
+ fingerData.Bpp() + "\nWSQ Info: "
+ fingerData.WSQInfo();
Toast.makeText(getApplicationContext(), "fingerData.Quality()" + fingerData.Quality() + "StartSyncCapture is " + fingerData.ISOTemplate().length, Toast.LENGTH_SHORT).show();
mFingerData = fingerData;
//////////////////// Extract ISO Image
int dataLen = 0;
byte[] tempData = new byte[(mfs100.GetDeviceInfo().Width() * mfs100.GetDeviceInfo().Height()) + 1078];
byte[] isoImage = null;
dataLen = mfs100.ExtractISOImage(fingerData.RawData(), tempData);
if (dataLen <= 0) {
if (dataLen == 0) {
Toast.makeText(getApplicationContext(), "Failed to extract ISO Image", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), mfs100.GetErrorMsg(dataLen), Toast.LENGTH_SHORT).show();
}
return;
} else {
isoImage = new byte[dataLen];
System.arraycopy(tempData, 0, isoImage, 0, dataLen);
mISOImage = new byte[dataLen];
System.arraycopy(tempData, 0, mISOImage, 0, dataLen);
}
} else {
Toast.makeText(getApplicationContext(), "Please try again", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
}
}));
}

fingerprint scanners only return image, either you can store bitmap into database or you can save image into local storage and path of image into database.
you can use external library to convert image to minutiae and enroll and verify as:
http://www.nist.gov/itl/iad/ig/nbis.cfm
http://www.neurotechnology.com/verifinger.html

Images having of different types such as bitmap, iso, wsq etc..
normally, from photo viewer only bitmap image can be previewed. But if you want to preview iso image (19794-4) then you need iso viewer and if you want to preview wsq image then you need to use wsq viewer.
About storing images in to database, you need to use blob datatype and you need to convert bitmap image into byte array and then you have to store into database.
but remember, if you want to use stored image for verification purpose then you need to store ISO Template (19794-2) into your database.
to get ISO template (19794-2), you have to use mfs100.ExtractISOTemplate function of SDK.

also best solution for store and reuse your fingerprint data in Mantra device so save your ISO temple to base64 string and store base64 string in database and get fingerprint data from database so create file from base64 to ISO temple
check this url
Base 64 encode and decode example code

Related

data not passing when running doInBackground method within for loop

I have some pics to upload to the ftp server and I am using Asynctask for it.The images need to be sent to multiple host so I am using a for loop.The data to be passed is very well being fetched by the constructor but the doInBackground method is not running which was earlier running very well without the for loop and the additional data apart from the String filePathName that I am trying to pass in now in doInBackground.please help me
class uploadTask extends AsyncTask<String, Void, String> {
public uploadTask(String filePathName,String host_2,String user_2,String pass_2)
{
filePath=filePathName;
host_1=host_2;
user_1=user_2;
pass_1=pass_2;
Toast.makeText(getBaseContext(),"FTP DATA RECEIVING:"+"HOST:"+host_2+" USERNAME:"+user_2+" PASS:"+pass_2,Toast.LENGTH_LONG).show();
//hostName=host;
}
#Override
protected String doInBackground(String... params) {
try {
Toast.makeText(getBaseContext(),"Entered Do in Background Method to upload",Toast.LENGTH_SHORT).show();
ftp_host = "ftp.photoshelter.com";//This is not the correct way. Supposed to get from Backendless table
ftp_username = "brytest";//This is not the correct way. Supposed to get from Backendless table
ftp_password = "passtest";//This is not the correct way. Supposed to get from Backendless table
Toast.makeText(getBaseContext(),"HOST:"+ftp_host+" USERNAME:"+ftp_username+" PASS:"+ftp_password,Toast.LENGTH_LONG).show();
news_agency = "news agency";
easyFTP ftp = new easyFTP();
ftp.connect(ftp_host, ftp_username, ftp_password);
status = ftp.setWorkingDirectory("mem/images"); // if User say provided any Destination then Set it , otherwise
// Upload will be stored on Default /root level on server
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageTimeStamped = ftp_username + "_" + timeStamp + ".png";
FileInputStream is = new FileInputStream(imageFileLocation);
//addPhotoGrapherInfo();
ftp.uploadFile(is, imageTimeStamped);
System.out.println("Successfull ftp upload to " + ftp_host);
Toast.makeText(getBaseContext(), "Photo uploading by ftp to " + ftp_host, Toast.LENGTH_LONG).show();
//}
//reset booleans
//cameraPicTaken = false;
//galleryImageSelected = false;
//System.out.println("reset cameraPicTaken and galleryImageSelected");
// }
return new String("Upload Successful");
}catch (Exception e){
String t="Failure : " + e.getLocalizedMessage();
return t;
}
}
}
my onClickListener with for loop
if(cameraPicTaken || galleryImageSelected) {
Toast.makeText(SubmitActivity.this,"Image Location is:"+ imageFileLocation,Toast.LENGTH_LONG).show();
//addPhotoGrapherInfo();
for(int i=0;i<Common.selectedHostArray.size();i++) {
uploadFile(imageFileLocation,Common.selectedHostArray.get(i),Common.selectedUsernameArray.get(i),Common.selectedPasswordArray.get(i));
}
cameraPicTaken = false;
galleryImageSelected = false;
}
funnction called in onClick
public void uploadFile(String filePath,String host_1,String user_1,String pass_1)
{
if(cameraPicTaken == true) {
System.out.println("camera photo start upload");
//for(int i=0;i<Common.selectedHostArray.size();i++) {
//host_1=Common.selectedHostArray.get(i);
//user_1=Common.selectedUsernameArray.get(i);
//pass_1=Common.selectedPasswordArray.get(i);
//host_1="ftp.photoshelter.com";
//user_1="brytest";
//pass_1="passtest";
Toast.makeText(getBaseContext(),"FTP DATA PASSING:"+"HOST:"+host_1+" USERNAME:"+user_1+" PASS:"+pass_1,Toast.LENGTH_LONG).show();
new uploadTask(filePath,host_1,user_1,pass_1).execute();
// }
//cameraPicTaken = false;
//galleryImageSelected = false;
System.out.println("reset cameraPicTaken and galleryImageSelected");
//cameraPicTaken = false;
}
if(galleryImageSelected == true){
System.out.println("gallery image start upload");
Toast.makeText(getBaseContext(),"FTP DATA PASSING:"+"HOST:"+host_1+" USERNAME:"+user_1+" PASS:"+pass_1,Toast.LENGTH_LONG).show();
new uploadTask(filePath,host_1,user_1,pass_1).execute();
//new uploadTask(filePat)h.execute();
//galleryImageSelected = false;
}
Toast.makeText(getBaseContext(), "Photo uploading by ftp to photoshelter.com" /*+ news_agency*/, Toast.LENGTH_LONG).show();
}
You're trying to perform a UI command on a background thread (Toast). This is causing your background tasks to fail early. Since your background tasks catch their own errors, they fail silently.
#Override
protected String doInBackground(String... params) {
try {
// you can't Toast on a background thread, this should throw an exception
Toast.makeText(getBaseContext(),"Entered Do in Background Method to upload",Toast.LENGTH_SHORT).show();
...
}catch (Exception e){
// your Toast exception is getting caught silently here
String t="Failure : " + e.getLocalizedMessage();
return t;
}
}
By the way, the try/catch on everything is not a good practice. You end up with a ton of silent failures leaving you scratching your head and asking why things aren't working.

Google Fit Session title not "sticking"

My Referee watch creates a Google Fit Session using the following code:
private void insertFitSession(final Game currentGame, final Period period,
final long periodStartTime, final long periodEndTime) {
//add the detailed Sensor data (using History API) if available
boolean activityWasInserted = false;
if (!RefWatchUtil.isRefWatchFree()) {
//If there are speeds then we will insert an activity
//4.5.09: Unfortunately mFitnessDataSets[] can have leftover data from a period where you did track fitness
//So we had to replace with period-by-period dataSets
activityWasInserted = (period.getFitnessDataSet(SPEED_LISTENER_IDX) != null)
&& !period.getFitnessDataSet(SPEED_LISTENER_IDX).isEmpty();
}
//create a Session in Google Fit for the period that just completed
//(this happens even for Free)
try {
String sessionBaseName = currentGame.getTitle();
if (sessionBaseName.isEmpty()) sessionBaseName = currentGame.getLocation();
if (sessionBaseName.isEmpty()) sessionBaseName = RefWatchUtil.timeMillisToDefaultShortDateTime(currentGame.getStartTimeMillis());
final String sessionName = sessionBaseName + ": " + String.format(getResources().getString(R.string.fitness_period_label), period.getPeriodNum());
final Session.Builder fitnessSessionBuilder = new Session.Builder();
fitnessSessionBuilder
.setName(sessionName)
.setIdentifier(sessionName)
.setDescription(mCurrentGame.getDescription())
.setStartTime(periodStartTime, TimeUnit.MILLISECONDS)
.setEndTime(periodEndTime, TimeUnit.MILLISECONDS);
//If we're Free, then we don't have real fitness session data and just guess at Jogging
// (also if we have no Activity data in Pro)
if (RefWatchUtil.isRefWatchFree() || !activityWasInserted) {
fitnessSessionBuilder.setActivity(FitnessActivities.RUNNING_JOGGING);
}
final Session fitSession = fitnessSessionBuilder.build();
SessionInsertRequest insertRequest = new SessionInsertRequest.Builder()
.setSession(fitSession)
.build();
Fitness.SessionsApi.insertSession(mFitnessApiClient, insertRequest)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(#NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "Successfully inserted Session " + sessionName);
} else {
Log.d(TAG, "There was a problem inserting the session " + sessionName
+ ": " + status.getStatusCode() + " " + status.getStatusMessage());
}
}
});
} catch (RuntimeException e){
Log.e(TAG, "There was a runtime exception inserting the session: " + e.getLocalizedMessage());
}
}
Note the sessionName defaults to either Title, Location, or Time appended with the current Period. This has been working great.
Recently (last month or so?) the Fit session is correctly inserted (I can track it in the log) but the Name doesn't stick. Instead I get "25 min running" for some, but not all, of them.
Has anybody else experienced this type of override by Fit?

Java InputSream hascode is different each time even when the request is same

I have a query not particular to UniversalImageLoader but because i am trying to use the content stream to load the image i am facing following issue.
I am using input stream "stream://" to be able to use ImageLoader. Everything is working fine except that the hashcode of the input stream for the same request is generated differently and hence forces the imageloader to download the image again from the network instead of the disk.
What should i do to fix it.
PS: I tried to follow the answer from here
The code to get InputStream is (The UtilityMethod is noting just an async task):
public void displayContentImage(final String fileId, final ImageView imageView) {
UtilityMethods.startMyTask(new AsyncTask<Object, Void, InputStream>() {
#Override
protected InputStream doInBackground(Object... params) {
CMServiceGateway cmServiceGateway = new CMServiceGateway();
final InputStream inputStream = cmServiceGateway.GetContentAsStream(fileId);
if (inputStream != null) {
//String imageId = "stream://" + inputStream.hashCode();
//Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId);
//String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode();
//Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2);
return inputStream;
}
return null;
}
#Override
protected void onPostExecute(InputStream inputStream) {
if (inputStream != null) {
displayImage(inputStream, imageView);
}
}
});
}
The basic problem of hash code equal like the sample above where you will find that the second log hash code is different than first log hash code even if the inputStream object used is same.
//String imageId = "stream://" + inputStream.hashCode();
//Log.d("ImageId :: 1 ::", "file id : " + fileId + "hashcode: " + imageId);
//String imageId2 = "stream://" + cmServiceGateway.GetContentAsStream(fileId).hashCode();
//Log.d("ImageId :: 2 ::", "file id : " + fileId + "hashcode: " + imageId2);
Although not answering the above question exactly but I am able to resolve this problem by not passing the hashcode to the universal image loader as id. Instead i passed the unique file Id's and it worked well now to display image from memory cache.

SVM model fails to load in Android Application

I have a problem with load() method in SVM module. For example if I run code:
try {
Uri uri = Uri.fromFile(new File("file:///android_asset/SVM_Bills.xml"));
mySvm.load(uri.getPath());
int in = mySvm.get_support_vector_count();
if (in != 0) {
Toast.makeText(context,"done loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
value = (int)mySvm.predict(matOfDescriptor);
}
else {
Toast.makeText(context,"error while loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
}
It give me the error toast message (i.e it goes to else part and show the toast message).
Of course SVM was previously trained.
Any help please?

Titanium Android : Facebook dialog image URL not properly formatted

I developing an Android application using Titanium Appcelerator. I had tried to Post text and Image via facebook feed dialog
.. But error while load my local image URL..
var fileimg = Titanium.Filesystem.getFile(backupDir.nativePath, "myimg.jpg");
var fb_data1 = {
description : "Some good text",
picture : fileimg.nativePath,
link : "www.googlee.com",
};
facebook_qfav.dialog("feed", fb_data1, showRequestResult);
function showRequestResult(e) {
var s = '';
if (e.success) {
s = "SUCCESS";
if (e.result) {
s += "; " + e.result;
}
if (e.data) {
s += "; " + e.data;
}
if (!e.result && !e.data) {
s = '"success",but no data from FB.I am guessing you cancelled the dialog.';
}
} else if (e.cancelled) {
s = "CANCELLED";
} else {
s = "FAILED ";
if (e.error) {
s += "; " + e.error;
alert("facebook Share " + s);
}
}
}
ERROR: "Image URL not properly formatted"
File path will be like this: file:///storage/sdcard0/myimg.jpg
But if i pass the remote URL to the picture property , the image is shown in the dialog...
what happens to the local URL..?
I think the only issue is that nativepath has capital P in it. so, its : nativePath
so instead of picture : fileimg.nativepath, It Should be picture : fileimg.nativePath,
Documentation.
Hope it helps.

Categories

Resources