Multi-Modal-Biometric-System-App:该存储库包含执行多模式生物特征识别的android应用程序的源

  • m2_887596
    了解作者
  • 13.5MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 10:16
    上传日期
Multi-Modal-Biometric-System-App:该存储库包含执行多模式生物特征识别的android应用程序的源代码。 主要功能包括指纹扫描。 要测试指纹模块,您的设备必须包含适当的指纹检测硬件
Multi-Modal-Biometric-System-App-master.zip
内容介绍
package com.multimodalbiometricapp; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Hashtable; import java.util.Locale; import java.util.Map; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Base64; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; import android.widget.VideoView; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; public class ImageCapture extends Activity { // Activity request codes private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; private static final int CAMERA_CAPTURE_VIDEO_REQUEST_CODE = 200; private String UPLOAD_URL ="http://simplifiedcoding.16mb.com/VolleyUpload/upload.php"; public static final int MEDIA_TYPE_IMAGE = 1; public static final int MEDIA_TYPE_VIDEO = 2; // directory name to store captured images and videos private static final String IMAGE_DIRECTORY_NAME = "Hello Camera"; private Uri fileUri; // file url to store image/video private ImageView imgPreview; private VideoView videoPreview; private Button btnCapturePicture, btnSendToserver; private String KEY_IMAGE = "image"; private String KEY_NAME = "name"; private Bitmap bitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.imagecapture); imgPreview = (ImageView) findViewById(R.id.imgPreview); videoPreview = (VideoView) findViewById(R.id.videoPreview); btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture); btnSendToserver = (Button) findViewById(R.id.btnSendToServer); /** * Capture image button click event */ btnCapturePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // capture picture captureImage(); } }); btnSendToserver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { uploadImage(); } }); // Checking camera availability if (!isDeviceSupportCamera()) { Toast.makeText(getApplicationContext(), "Sorry! Your device doesn't support camera", Toast.LENGTH_LONG).show(); // will close the app if the device does't have camera finish(); } } /** * Checking device has camera hardware or not * */ private boolean isDeviceSupportCamera() { if (getApplicationContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA)) { // this device has a camera return true; } else { // no camera on this device return false; } } public void uploadImage(){ //Showing the progress dialog final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false); StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, new Response.Listener<String>() { @Override public void onResponse(String s) { //Disimissing the progress dialog loading.dismiss(); //Showing toast message of the response Toast.makeText(ImageCapture.this, s , Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { //Dismissing the progress dialog loading.dismiss(); //Showing toast Toast.makeText(ImageCapture.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show(); } }){ @Override protected Map<String, String> getParams() throws AuthFailureError { //Converting Bitmap to String String image = getStringImage(bitmap); //Creating parameters Map<String,String> params = new Hashtable<String, String>(); //Adding parameters params.put(KEY_IMAGE, image); params.put(KEY_NAME, "sample_name"); //returning parameters return params; } }; //Creating a Request Queue RequestQueue requestQueue = Volley.newRequestQueue(this); //Adding request to the queue requestQueue.add(stringRequest); } public String getStringImage(Bitmap bmp){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } /** * Capturing Camera Image will lauch camera app requrest image capture */ private void captureImage() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // start the image capture Intent startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE); } /** * Here we store the file url as it will be null after returning from camera * app */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // save file url in bundle as it will be null on scren orientation // changes outState.putParcelable("file_uri", fileUri); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); // get the file url fileUri = savedInstanceState.getParcelable("file_uri"); } /** * Receiving activity result method will be called after closing the camera * */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if the result is capturing Image Uri filePath = data.getData(); if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) { if (resultCode == RESULT_OK) { // successfully captured the image // display it in image view try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath); } catch (IOException e) { e.printStackTrace(); } previewCapturedImage(); } else if (resultCode == RESULT_CANCELED) { // user cancelled Image capture Toast.makeText(getApplicationContext(), "User cancelled image capture", Toast.LENGTH_SHORT) .show(); } else { // failed to capture image Toast.makeText(
评论
    相关推荐