remove rxpermissions with context compat instead

This commit is contained in:
王劲鹏 2020-02-28 12:00:25 +08:00 committed by osborn
parent 1a754b2558
commit 59a767fcc6
2 changed files with 28 additions and 17 deletions

View File

@ -33,7 +33,6 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.2.2' implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.3.7' implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.3.7'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation "io.reactivex.rxjava2:rxjava:2.2.15" implementation "io.reactivex.rxjava2:rxjava:2.2.15"
api 'org.greenrobot:eventbus:3.1.1' api 'org.greenrobot:eventbus:3.1.1'
implementation 'com.lahm.library:easy-protector-release:1.1.1' implementation 'com.lahm.library:easy-protector-release:1.1.1'

View File

@ -2,24 +2,25 @@ package pub.doric.devkit.ui;
import android.Manifest; import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.tbruyelle.rxpermissions2.RxPermissions;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.DoricContextManager; import pub.doric.DoricContextManager;
import pub.doric.devkit.DevKit; import pub.doric.devkit.DevKit;
@ -42,23 +43,34 @@ public class DoricDevActivity extends AppCompatActivity {
setContentView(R.layout.layout_debug_context); setContentView(R.layout.layout_debug_context);
initViews(); initViews();
} else { } else {
if (DevKit.isRunningInEmulator) { if (!DevKit.isRunningInEmulator) {
DevKit.ip = "10.0.2.2"; DevKit.ip = "10.0.2.2";
DevKit.getInstance().connectDevKit("ws://" + DevKit.ip + ":7777"); DevKit.getInstance().connectDevKit("ws://" + DevKit.ip + ":7777");
} else { } else {
final RxPermissions rxPermissions = new RxPermissions(this); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
Disposable disposable = rxPermissions != PackageManager.PERMISSION_GRANTED) {
.request(Manifest.permission.CAMERA) if (ActivityCompat.shouldShowRequestPermissionRationale(this,
.subscribe(new Consumer<Boolean>() { Manifest.permission.CAMERA)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA,}, 1);
}
}
}
}
}
@Override @Override
public void accept(Boolean grant) throws Exception { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grant) { super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
Intent intent = new Intent(DoricDevActivity.this, ScanQRCodeActivity.class); Intent intent = new Intent(DoricDevActivity.this, ScanQRCodeActivity.class);
startActivity(intent); startActivity(intent);
} }
} }
});
}
} }
} }