系统相机拍照后不重启,而是通知app直接发送

MQTTtest
Matthew 9 months ago
parent ccd5a6a04f
commit 721ed1e0e5

@ -754,6 +754,28 @@ Java_com_xypower_mpapp_MicroPhotoService_reloadConfigs(
} }
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto(
JNIEnv* env, jclass cls, jlong handler, jstring path) {
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
if (pTerminal == NULL)
{
return JNI_FALSE;
}
if (env->GetStringUTFLength(path) <=0)
{
return JNI_FALSE;
}
const char *pathStr = env->GetStringUTFChars(path, 0);
bool res = pTerminal->SendExternalPhoto(pathStr);
env->ReleaseStringUTFChars(path, pathStr);
return res ? JNI_TRUE : JNI_FALSE;
}
extern "C" JNIEXPORT void JNICALL extern "C" JNIEXPORT void JNICALL
Java_com_xypower_mpapp_MicroPhotoService_infoLog( Java_com_xypower_mpapp_MicroPhotoService_infoLog(
JNIEnv* env, jclass cls, jstring msg) { JNIEnv* env, jclass cls, jstring msg) {

@ -342,7 +342,16 @@ public class MicroPhotoService extends Service {
mService.mHander.postDelayed(new Runnable() { mService.mHander.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
CameraAdb cameraAdb = new CameraAdb(context, appPath); final CameraAdb cameraAdb = new CameraAdb(context, appPath);
cameraAdb.setCallback(new Runnable() {
@Override
public void run() {
String targetPath = cameraAdb.getTargetPath();
if (!TextUtils.isEmpty(targetPath)) {
mService.sendExternalPhoto(mService.mNativeHandle, targetPath);
}
}
});
cameraAdb.takePhoto(); cameraAdb.takePhoto();
} }
}, 10000 * cnt); }, 10000 * cnt);
@ -1189,7 +1198,9 @@ cellSignalStrengthGsm.getDbm();
protected native void recordingFinished(long handler, boolean result, String path, long videoId); protected native void recordingFinished(long handler, boolean result, String path, long videoId);
public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path); public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path);
public static native void releaseDeviceHandle(long deviceHandle); public static native void releaseDeviceHandle(long deviceHandle);
public static native boolean sendExternalPhoto(long deviceHandle, String path);
public static native void infoLog(String log); public static native void infoLog(String log);
public static native void setOtgState(boolean enabled); public static native void setOtgState(boolean enabled);
public static native void setCam3V3Enable(boolean enabled); public static native void setCam3V3Enable(boolean enabled);
public static native String getSerialNumber(); public static native String getSerialNumber();

@ -2,6 +2,7 @@ package com.xypower.mpapp.adb;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.dev.devapi.api.SysApi; import com.dev.devapi.api.SysApi;
@ -26,6 +27,16 @@ public class CameraAdb {
private String mAppPath; private String mAppPath;
private AdbKeyPair mAdbKeyPair; private AdbKeyPair mAdbKeyPair;
private String mDeviceIp = "127.0.0.1"; private String mDeviceIp = "127.0.0.1";
private String mTargetPath;
private Runnable mRunnable;
public String getTargetPath() {
return mTargetPath;
}
public void setCallback(Runnable runnable) {
mRunnable = runnable;
}
public CameraAdb(Context context, String appPath) { public CameraAdb(Context context, String appPath) {
@ -90,17 +101,20 @@ public class CameraAdb {
takePhoto(true); takePhoto(true);
takingTime = System.currentTimeMillis() / 1000; takingTime = System.currentTimeMillis() / 1000;
sleep(250); sleep(250);
movePhoto(true, requestTime, takingTime); String path = movePhoto(true, requestTime, takingTime);
sleep(200); sleep(200);
SysApi.forceStopApp(mContext, "com.mediatek.camera"); SysApi.forceStopApp(mContext, "com.mediatek.camera");
MicroPhotoService.restartApp(mContext, MicroPhotoContext.PACKAGE_NAME_MPAPP); if (mRunnable != null) {
mRunnable.run();
}
} }
private void movePhoto(boolean frontCamera, long requestTime, long takingTime) { private String movePhoto(boolean frontCamera, long requestTime, long takingTime) {
String targetPath = null;
String photoPath = mAppPath + "photos/"; String photoPath = mAppPath + "photos/";
String photoFile = "IMG_" + Long.toHexString(requestTime).toUpperCase() + "_" String photoFile = "IMG_" + Long.toHexString(requestTime).toUpperCase() + "_"
+ (frontCamera ? "2" : "1") + "_FF_0_" + Long.toHexString(requestTime).toUpperCase() + (frontCamera ? "2" : "1") + "_FF_0_" + Long.toHexString(requestTime).toUpperCase()
@ -119,6 +133,7 @@ public class CameraAdb {
for (int idx = 0; idx < 10; idx++) { for (int idx = 0; idx < 10; idx++) {
res = srcFile.renameTo(targetFile); res = srcFile.renameTo(targetFile);
if (res) { if (res) {
targetPath = targetFile.getAbsolutePath();
break; break;
} }
sleep(200); sleep(200);
@ -130,6 +145,8 @@ public class CameraAdb {
Log.e(TAG, "Failed to copy photo from Camera"); Log.e(TAG, "Failed to copy photo from Camera");
} }
} }
return targetPath;
} }
private void sleep(long timeout) { private void sleep(long timeout) {

Loading…
Cancel
Save