diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1ff0f4..0c032c2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,8 +4,7 @@ - - + - + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/jiangdg/usbcamera/application/MyApplication.java b/app/src/main/java/com/jiangdg/usbcamera/application/MyApplication.java index 768242c..e79041a 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/application/MyApplication.java +++ b/app/src/main/java/com/jiangdg/usbcamera/application/MyApplication.java @@ -2,15 +2,18 @@ package com.jiangdg.usbcamera.application; import android.app.Application; +import com.jiangdg.usbcamera.UVCCameraHelper; import com.jiangdg.usbcamera.utils.CrashHandler; -/**全局类 +/**application class * * Created by jianddongguo on 2017/7/20. */ public class MyApplication extends Application { private CrashHandler mCrashHandler; + // File Directory in sd card + public static final String DIRECTORY_NAME = "UVCCamera"; @Override public void onCreate() { diff --git a/app/src/main/java/com/jiangdg/usbcamera/utils/CrashHandler.java b/app/src/main/java/com/jiangdg/usbcamera/utils/CrashHandler.java index 1165523..5bef590 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/utils/CrashHandler.java +++ b/app/src/main/java/com/jiangdg/usbcamera/utils/CrashHandler.java @@ -9,6 +9,9 @@ import android.os.Environment; import android.os.Looper; import android.widget.Toast; +import com.jiangdg.usbcamera.UVCCameraHelper; +import com.jiangdg.usbcamera.application.MyApplication; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -98,8 +101,11 @@ public class CrashHandler implements UncaughtExceptionHandler { public void run() { Looper.prepare(); Toast.makeText(mContext.getApplicationContext(), - "程序异常退出,即将重启...", Toast.LENGTH_LONG).show(); + "unknown exception!Please checking logs in sd card.", Toast.LENGTH_LONG).show(); Looper.loop(); + + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(0); } }).start(); // 收集设备参数信息 @@ -160,8 +166,7 @@ public class CrashHandler implements UncaughtExceptionHandler { sb.append("\n"); } - File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() - +File.separator+System.currentTimeMillis()+".txt"); + File file = new File(UVCCameraHelper.ROOT_PATH + MyApplication.DIRECTORY_NAME +"/log.txt"); FileOutputStream fos = null; try { fos = new FileOutputStream(file); diff --git a/app/src/main/java/com/jiangdg/usbcamera/view/SplashActivity.java b/app/src/main/java/com/jiangdg/usbcamera/view/SplashActivity.java new file mode 100644 index 0000000..1887139 --- /dev/null +++ b/app/src/main/java/com/jiangdg/usbcamera/view/SplashActivity.java @@ -0,0 +1,99 @@ +package com.jiangdg.usbcamera.view; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.view.WindowManager; +import android.widget.Toast; + +import com.jiangdg.usbcamera.R; + +import java.util.ArrayList; +import java.util.List; + + +/** + * permission checking + * Created by jiangdongguo on 2019/6/27. + */ + +public class SplashActivity extends AppCompatActivity { + private static final String[] REQUIRED_PERMISSION_LIST = new String[]{ + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.RECORD_AUDIO, + }; + private static final int REQUEST_CODE = 1; + private List mMissPermissions = new ArrayList<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + setContentView(R.layout.activity_splash); + + if (isVersionM()) { + checkAndRequestPermissions(); + } else { + startMainActivity(); + } + } + + private boolean isVersionM() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + } + + private void checkAndRequestPermissions() { + mMissPermissions.clear(); + for (String permission : REQUIRED_PERMISSION_LIST) { + int result = ContextCompat.checkSelfPermission(this, permission); + if (result != PackageManager.PERMISSION_GRANTED) { + mMissPermissions.add(permission); + } + } + // check permissions has granted + if (mMissPermissions.isEmpty()) { + startMainActivity(); + } else { + ActivityCompat.requestPermissions(this, + mMissPermissions.toArray(new String[mMissPermissions.size()]), + REQUEST_CODE); + } + } + + @Override + public void onRequestPermissionsResult(final int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == REQUEST_CODE) { + for (int i = grantResults.length - 1; i >= 0; i--) { + if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { + mMissPermissions.remove(permissions[i]); + } + } + } + // Get permissions success or not + if (mMissPermissions.isEmpty()) { + startMainActivity(); + } else { + Toast.makeText(SplashActivity.this, "get permissions failed,exiting...",Toast.LENGTH_SHORT).show(); + SplashActivity.this.finish(); + } + } + + private void startMainActivity() { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + startActivity(new Intent(SplashActivity.this, USBCameraActivity.class)); + SplashActivity.this.finish(); + } + }, 3000); + } +} + diff --git a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java index c6ba68f..d76a0ac 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -26,6 +26,7 @@ import android.widget.Toast; import com.jiangdg.usbcamera.R; import com.jiangdg.usbcamera.UVCCameraHelper; +import com.jiangdg.usbcamera.application.MyApplication; import com.jiangdg.usbcamera.utils.FileUtils; import com.serenegiant.usb.CameraDialog; import com.serenegiant.usb.Size; @@ -226,7 +227,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog showShortMsg("sorry,camera open failed"); return super.onOptionsItemSelected(item); } - String picPath = UVCCameraHelper.ROOT_PATH + System.currentTimeMillis() + String picPath = UVCCameraHelper.ROOT_PATH + MyApplication.DIRECTORY_NAME +"images/"+ System.currentTimeMillis() + UVCCameraHelper.SUFFIX_JPEG; mCameraHelper.capturePicture(picPath, new AbstractUVCCameraHandler.OnCaptureListener() { @Override @@ -242,7 +243,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog return super.onOptionsItemSelected(item); } if (!mCameraHelper.isPushing()) { - String videoPath = UVCCameraHelper.ROOT_PATH + System.currentTimeMillis(); + String videoPath = UVCCameraHelper.ROOT_PATH + MyApplication.DIRECTORY_NAME +"videos/"+ System.currentTimeMillis(); FileUtils.createfile(FileUtils.ROOT_PATH + "test666.h264"); // if you want to record,please create RecordParams like this RecordParams params = new RecordParams(); diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml new file mode 100644 index 0000000..e0951d2 --- /dev/null +++ b/app/src/main/res/layout/activity_splash.xml @@ -0,0 +1,38 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png index cde69bc..c96d22b 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png index c133a0c..c96d22b 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png index bfa42f0..c96d22b 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 324e72c..c96d22b 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index aee44e1..c96d22b 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c9ecc62..60b5af8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - UVCCamera + AndroidUSBCamera diff --git a/build.gradle b/build.gradle index d525477..22ea390 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,6 @@ buildscript { jcenter() } dependencies { - // gradle插件版本 classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' } @@ -28,7 +27,7 @@ ext { commonLibVersion= '2.12.4' versionCompiler = 27 versionTarget = 27 - minSdkVersion = 21 + minSdkVersion = 23 versionNameString = '1.0.0' javaSourceCompatibility = JavaVersion.VERSION_1_8 javaTargetCompatibility = JavaVersion.VERSION_1_8 diff --git a/libusbcamera/src/main/java/com/jiangdg/usbcamera/utils/FileUtils.java b/libusbcamera/src/main/java/com/jiangdg/usbcamera/utils/FileUtils.java index cf5af28..ab4f9f4 100644 --- a/libusbcamera/src/main/java/com/jiangdg/usbcamera/utils/FileUtils.java +++ b/libusbcamera/src/main/java/com/jiangdg/usbcamera/utils/FileUtils.java @@ -7,7 +7,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -/** 创建文件 +/** * * Created by jiangdongguo on 2017/10/18. */