Skip to content

Commit

Permalink
working on usb camera access
Browse files Browse the repository at this point in the history
  • Loading branch information
kaysiz committed Feb 15, 2019
1 parent 94369da commit 82c1858
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cricket">


<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/example/cricket/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Camera;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
Expand All @@ -11,6 +12,8 @@
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Environment;
Expand All @@ -20,6 +23,7 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.util.SparseArray;
import android.util.SparseIntArray;
Expand All @@ -39,6 +43,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -135,7 +140,13 @@ public int compare(Size lhs, Size rhs) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

UsbManager m = (UsbManager)getApplicationContext().getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> devices = m.getDeviceList();
Collection<UsbDevice> ite = devices.values();
UsbDevice[] usbs = ite.toArray(new UsbDevice[]{});
for (UsbDevice usb : usbs){
Toast.makeText(getApplicationContext(), usb.getDeviceName(), Toast.LENGTH_SHORT).show();
}
createVideoFolder();

mMediaRecorder = new MediaRecorder();
Expand Down Expand Up @@ -223,9 +234,12 @@ private void setupCamera(int width, int height) {
try {
for (String cameraId : cameraManager.getCameraIdList()) {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
// Toast.makeText(getApplicationContext(),cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) , Toast.LENGTH_SHORT).show();

if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
Toast.makeText(this, String.valueOf(cameraManager.getCameraIdList().length), Toast.LENGTH_SHORT).show();
StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
int deviceOrientation = getWindowManager().getDefaultDisplay().getRotation();
mTotalRotation = sensorToDeviceRotation(cameraCharacteristics, deviceOrientation);
Expand Down

0 comments on commit 82c1858

Please sign in to comment.