Browse Source

add checking permissions and adjust min SDK to API23

main
Jiangdg 6 years ago
parent
commit
27f682a327
  1. 13
      app/src/main/AndroidManifest.xml
  2. 5
      app/src/main/java/com/jiangdg/usbcamera/application/MyApplication.java
  3. 11
      app/src/main/java/com/jiangdg/usbcamera/utils/CrashHandler.java
  4. 99
      app/src/main/java/com/jiangdg/usbcamera/view/SplashActivity.java
  5. 5
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  6. 38
      app/src/main/res/layout/activity_splash.xml
  7. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher.png
  8. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher.png
  9. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher.png
  10. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  11. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  12. 2
      app/src/main/res/values/strings.xml
  13. 3
      build.gradle
  14. 2
      libusbcamera/src/main/java/com/jiangdg/usbcamera/utils/FileUtils.java

13
app/src/main/AndroidManifest.xml

@ -4,8 +4,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--全局异常检测,需添加-->
<!--android:name=".application.MyApplication"-->
<application
android:name=".application.MyApplication"
android:allowBackup="true"
@ -13,13 +12,21 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.jiangdg.usbcamera.view.USBCameraActivity">
<activity android:name="com.jiangdg.usbcamera.view.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".view.USBCameraActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
</application>
</manifest>

5
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() {

11
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);

99
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<String> 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);
}
}

5
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();

38
app/src/main/res/layout/activity_splash.xml

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="410dp"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="Welcome to use!"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:textSize="14sp"
android:textStyle="italic"
android:text="Author: jiangdongguo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="5dp"
android:textStyle="italic"
android:textSize="14sp"
android:text="Email:765067602@qq.com"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="last modify 2019.6"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="bottom|center_horizontal"
android:paddingBottom="20dp"
android:layout_weight="1"/>
</LinearLayout>

BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 43 KiB

BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 43 KiB

BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 43 KiB

BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 43 KiB

BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 43 KiB

2
app/src/main/res/values/strings.xml

@ -1,3 +1,3 @@
<resources>
<string name="app_name">UVCCamera</string>
<string name="app_name">AndroidUSBCamera</string>
</resources>

3
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

2
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.
*/

Loading…
Cancel
Save