-
Notifications
You must be signed in to change notification settings - Fork 53
/
MainBuilderActivity.java
65 lines (56 loc) · 2.43 KB
/
MainBuilderActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.lypeer.fcpermissions;
import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.lypeer.fcpermission.FcPermissionsB;
import com.lypeer.fcpermission.impl.OnPermissionsDeniedListener;
import com.lypeer.fcpermission.impl.OnPermissionsGrantedListener;
import java.util.List;
/**
* Created by lypeer on 16/9/1.
*/
public class MainBuilderActivity extends AppCompatActivity {
private static final int RC_CAMERA = 2333;
private FcPermissionsB mFcPermissionsB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_request_camera).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requestCameraPermission();
}
});
}
private void requestCameraPermission() {
mFcPermissionsB = new FcPermissionsB.Builder(this)
.onGrantedListener(new OnPermissionsGrantedListener() {
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
}
})
.onDeniedListener(new OnPermissionsDeniedListener() {
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
}
})
.positiveBtn4ReqPer(android.R.string.ok)
.negativeBtn4ReqPer(R.string.cancel)
.positiveBtn4NeverAskAgain(R.string.setting)
.negativeBtn4NeverAskAgain(R.string.cancel)
.rationale4ReqPer(getString(R.string.prompt_request_camara))//必需
.rationale4NeverAskAgain(getString(R.string.prompt_we_need_camera))//必需
.requestCode(RC_CAMERA)//必需
.build();
mFcPermissionsB.requestPermissions(Manifest.permission.CAMERA);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mFcPermissionsB.onRequestPermissionsResult(requestCode , permissions , grantResults , this);
}
}