增加系统camera的调用
parent
817b3af2cd
commit
e48aedd172
@ -0,0 +1,103 @@
|
|||||||
|
package com.xypower.mpapp.adb;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.xypower.common.FilesUtils;
|
||||||
|
import com.xypower.mpapp.v2.Camera2VideoActivity;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import dadb.AdbKeyPair;
|
||||||
|
import dadb.AdbShellResponse;
|
||||||
|
import dadb.Dadb;
|
||||||
|
|
||||||
|
public class CameraAdb {
|
||||||
|
private final String TAG = "CameraAdb";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private String mAppPath;
|
||||||
|
private AdbKeyPair mAdbKeyPair;
|
||||||
|
private String mDeviceIp = "127.0.0.1";
|
||||||
|
|
||||||
|
public CameraAdb(Context context, String appPath) {
|
||||||
|
|
||||||
|
mContext = context;
|
||||||
|
mAppPath = appPath;
|
||||||
|
|
||||||
|
File file = new File( new File(appPath), "data/.keypair");
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
final File pubKeyFile = new File(file, "pub.key");
|
||||||
|
final File priKeyFile = new File(file, "pri.key");
|
||||||
|
if (!priKeyFile.exists() || !pubKeyFile.exists()) {
|
||||||
|
AdbKeyPair.generate(priKeyFile, pubKeyFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
mAdbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void takePhoto() {
|
||||||
|
(new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
runImpl();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runImpl() {
|
||||||
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
||||||
|
|
||||||
|
if (adb == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, mDeviceIp + " Connected");
|
||||||
|
boolean res = false;
|
||||||
|
|
||||||
|
String[] cmds = {
|
||||||
|
"am force-stop com.mediatek.camera",
|
||||||
|
"setprop mtk.camera.app.keycode.enable 1",
|
||||||
|
"setprop mtk.camera.switch.camera.debug 1",
|
||||||
|
"setprop mtk.camera.switch.id.debug back-1",
|
||||||
|
"am start -a android.media.action.STILL_IMAGE_CAMERA --ez com.google.assistant.extra.USE_FRONT_CAMERA true -f " + Integer.toString(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),
|
||||||
|
"wait",
|
||||||
|
"input keyevent 27"};
|
||||||
|
|
||||||
|
AdbShellResponse adbShellResponse = null;
|
||||||
|
for (String cmd : cmds) {
|
||||||
|
if (cmd.equals("wait")) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
adbShellResponse = adb.shell(cmd);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "CMD: " + cmd);
|
||||||
|
if (adbShellResponse.getExitCode() == 0) {
|
||||||
|
String[] lines = FilesUtils.splitLines(adbShellResponse.getAllOutput());
|
||||||
|
for (String line : lines) {
|
||||||
|
Log.i(TAG, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})).start();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue