其他
快速迭代,PermissionX现在支持Java了!
.permissions(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS, Manifest.permission.CALL_PHONE)
.onExplainRequestReason { deniedList ->
showRequestReasonDialog(deniedList, "即将申请的权限是程序必须依赖的权限", "我已明白")
}
.onForwardToSettings { deniedList ->
showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(this, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
@Override
public void onClick(View view) {
}
});
public interface OnClickListener {
void onClick(View view);
}
}
}
explainReasonCallback = callback
return this
}
.permissions(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS, Manifest.permission.CALL_PHONE)
.onExplainRequestReason { scope, deniedList ->
scope.showRequestReasonDialog(deniedList, "即将申请的权限是程序必须依赖的权限", "我已明白")
}
.onForwardToSettings { scope, deniedList ->
scope.showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(this, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
.permissions(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS, Manifest.permission.CALL_PHONE)
.onExplainRequestReason(new ExplainReasonCallbackWithBeforeParam() {
@Override
public void onExplainReason(ExplainScope scope, List<String> deniedList, boolean beforeRequest) {
scope.showRequestReasonDialog(deniedList, "即将申请的权限是程序必须依赖的权限", "我已明白");
}
})
.onForwardToSettings(new ForwardToSettingsCallback() {
@Override
public void onForwardToSettings(ForwardScope scope, List<String> deniedList) {
scope.showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白");
}
})
.request(new RequestCallback() {
@Override
public void onResult(boolean allGranted, List<String> grantedList, List<String> deniedList) {
if (allGranted) {
Toast.makeText(MainActivity.this, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "您拒绝了如下权限:" + deniedList, Toast.LENGTH_SHORT).show();
}
}
});
...
<service ...
android:foregroundServiceType="location" />
</manifest>
...
<service ...
android:foregroundServiceType="location|camera|microphone" />
</manifest>
* Maintain the task chain of permission request process.
* @author guolin
* @since 2020/6/10
*/
public class RequestChain {
/**
* Holds the first task of request process. Permissions request begins here.
*/
private BaseTask headTask;
/**
* Holds the last task of request process. Permissions request ends here.
*/
private BaseTask tailTask;
/**
* Add a task into task chain.
* @param task task to add.
*/
public void addTaskToChain(BaseTask task) {
if (headTask == null) {
headTask = task;
}
// add task to the tail
if (tailTask != null) {
tailTask.next = task;
}
tailTask = task;
}
/**
* Run this task chain from the first task.
*/
public void runTask() {
headTask.request();
}
}
* Request permissions at once, and handle request result in the callback.
*
* @param callback Callback with 3 params. allGranted, grantedList, deniedList.
*/
public void request(RequestCallback callback) {
requestCallback = callback;
// Build the request chain.
// RequestNormalPermissions runs first.
// Then RequestBackgroundLocationPermission runs.
RequestChain requestChain = new RequestChain();
requestChain.addTaskToChain(new RequestNormalPermissions(this));
requestChain.addTaskToChain(new RequestBackgroundLocationPermission(this));
requestChain.runTask();
}
...
implementation 'com.permissionx.guolindev:permissionx:1.2.2'
}
...
implementation 'com.permissionx.guolindev:permission-support:1.2.2'
}
https://github.com/guolindev/PermissionX
Modified on