申请camera与record audio权限

申请camera与record audio权限
pull/107/head
xufulong 5 years ago
parent 409cadf625
commit 52d302d59f
  1. 11
      app/src/main/java/com/frank/ffmpeg/activity/BaseActivity.java
  2. 7
      app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java

@ -2,6 +2,7 @@ package com.frank.ffmpeg.activity;
import android.Manifest; import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -28,13 +29,19 @@ public abstract class BaseActivity extends AppCompatActivity implements View.OnC
private final static int REQUEST_CODE = 1234; private final static int REQUEST_CODE = 1234;
private final static String[] permissions = new String[] { private final static String[] permissions = new String[] {
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE}; Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO};
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestPermission(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& checkSelfPermission(permissions[0]) != PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(permissions[1]) != PackageManager.PERMISSION_GRANTED ) {
requestPermission();
}
setContentView(getLayoutId()); setContentView(getLayoutId());
} }

@ -1,6 +1,5 @@
package com.frank.ffmpeg.activity; package com.frank.ffmpeg.activity;
import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.hardware.Camera; import android.hardware.Camera;
import android.media.AudioFormat; import android.media.AudioFormat;
@ -29,7 +28,6 @@ import com.frank.live.param.VideoParam;
public class LiveActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener, LiveStateChangeListener { public class LiveActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener, LiveStateChangeListener {
private final static String TAG = LiveActivity.class.getSimpleName(); private final static String TAG = LiveActivity.class.getSimpleName();
private final static String[] permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
private final static String LIVE_URL = "rtmp://192.168.1.102/live/stream"; private final static String LIVE_URL = "rtmp://192.168.1.102/live/stream";
private final static int MSG_ERROR = 100; private final static int MSG_ERROR = 100;
private SurfaceHolder surfaceHolder; private SurfaceHolder surfaceHolder;
@ -59,7 +57,6 @@ public class LiveActivity extends BaseActivity implements CompoundButton.OnCheck
hideActionBar(); hideActionBar();
initView(); initView();
requestPermission(permissions);
initPusher(); initPusher();
} }
@ -114,7 +111,9 @@ public class LiveActivity extends BaseActivity implements CompoundButton.OnCheck
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
livePusher.release(); if (livePusher != null) {
livePusher.release();
}
} }
@Override @Override

Loading…
Cancel
Save