如何不点击按钮直接上传图片到服务器?
How to directly upload images to server without click button?
Hye.I正在做应用程序比较身份证中的图像和实时捕获的人脸 image.User 在 UploadActivity.Then 捕获身份证图像,LivenessActivity 的前置摄像头将是提示抓脸 image.Then UploadActivity 将自动与 captured.User 需要点击按钮 "verify" 的两张图片一起出现,它会显示进度条并将图片上传到服务器进行比较 them.But,我必须输入什么代码才能在不单击 "verify" 按钮的情况下将两个图像上传到服务器?也许在图像出现在 UploadActivity 后,它会直接显示进度条并将图像上传到服务器。这是我提前给你的代码references.Thank你
上传活动:
btnCaptureId.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
captureImage();
}
});
// boolean flag to identify the media type, image or video
final boolean isImage = i.getBooleanExtra("isImage",true);
previewMedia(isImage);
if (fileUri != null )
{
//go to LivenessActivity to caoture image of face
Intent intent = new Intent(this, LivenessActivity.class);
startActivityForResult(intent, 2);
}
btnverify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// uploading the file to server
try {
new UploadFileToServer(Config.IMAGE_DOC, Config.IMAGE_FACE).execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
活跃度:
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent returnIntent = new Intent();
returnIntent.putExtra("image_best",face);
//result go to UploadActivity
setResult(UploadActivity.PAGE_INTO_LIVENESS, returnIntent);
finish();
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}
//do something with liveness face
return DetectionType.DONE;
}
button.performClick();
以编程方式单击
这是我添加的代码,无需点击按钮即可自动上传。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// successfully captured the image
// launching upload activity
launchUploadActivity(true);
} 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(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
if (requestCode == 2) {
if (resultCode == PAGE_INTO_LIVENESS) {
Bundle extras = getIntent().getExtras();
byte[] face = extras.getByteArray("image_best");
viewImage();
//automatically upload to server
try {
new UploadFileToServer(Config.IMAGE_DOC, Config.IMAGE_FACE).execute();
} catch (JSONException e) {
e.printStackTrace();
}
} else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),
"User cancelled video recording", Toast.LENGTH_SHORT)
.show();
}
}
}
按照步骤操作即可
- After set/show the image on imageview, start server call to upload it.
- show progress dialog until the uploading finished
Hye.I正在做应用程序比较身份证中的图像和实时捕获的人脸 image.User 在 UploadActivity.Then 捕获身份证图像,LivenessActivity 的前置摄像头将是提示抓脸 image.Then UploadActivity 将自动与 captured.User 需要点击按钮 "verify" 的两张图片一起出现,它会显示进度条并将图片上传到服务器进行比较 them.But,我必须输入什么代码才能在不单击 "verify" 按钮的情况下将两个图像上传到服务器?也许在图像出现在 UploadActivity 后,它会直接显示进度条并将图像上传到服务器。这是我提前给你的代码references.Thank你
上传活动:
btnCaptureId.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
captureImage();
}
});
// boolean flag to identify the media type, image or video
final boolean isImage = i.getBooleanExtra("isImage",true);
previewMedia(isImage);
if (fileUri != null )
{
//go to LivenessActivity to caoture image of face
Intent intent = new Intent(this, LivenessActivity.class);
startActivityForResult(intent, 2);
}
btnverify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// uploading the file to server
try {
new UploadFileToServer(Config.IMAGE_DOC, Config.IMAGE_FACE).execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
活跃度:
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {
FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
if (dataStruct != null) {
face = dataStruct.images.get("image_best");
Intent returnIntent = new Intent();
returnIntent.putExtra("image_best",face);
//result go to UploadActivity
setResult(UploadActivity.PAGE_INTO_LIVENESS, returnIntent);
finish();
}
if (face == null) {
face = validFrame.getCroppedFaceImageData();
}
//do something with liveness face
return DetectionType.DONE;
}
button.performClick();
以编程方式单击
这是我添加的代码,无需点击按钮即可自动上传。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// successfully captured the image
// launching upload activity
launchUploadActivity(true);
} 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(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
if (requestCode == 2) {
if (resultCode == PAGE_INTO_LIVENESS) {
Bundle extras = getIntent().getExtras();
byte[] face = extras.getByteArray("image_best");
viewImage();
//automatically upload to server
try {
new UploadFileToServer(Config.IMAGE_DOC, Config.IMAGE_FACE).execute();
} catch (JSONException e) {
e.printStackTrace();
}
} else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),
"User cancelled video recording", Toast.LENGTH_SHORT)
.show();
}
}
}
按照步骤操作即可
- After set/show the image on imageview, start server call to upload it.
- show progress dialog until the uploading finished