Skip to content

Commit

Permalink
Fixed demo crash when permission is dinied
Browse files Browse the repository at this point in the history
  • Loading branch information
BoleLiu committed Feb 22, 2022
1 parent 9a034a5 commit 9f84a81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.qiniu.droid.rtc.demo.service.DownloadService;
import com.qiniu.droid.rtc.demo.ui.RadioGroupFlow;
import com.qiniu.droid.rtc.demo.utils.Config;
import com.qiniu.droid.rtc.demo.utils.PermissionChecker;
import com.qiniu.droid.rtc.demo.utils.QNAppServer;
import com.qiniu.droid.rtc.demo.utils.ToastUtils;
import com.qiniu.droid.rtc.demo.utils.Utils;
Expand Down Expand Up @@ -124,6 +125,9 @@ public void onClickToSetting(View v) {
}

private void startConference(final String roomName) {
if (!isPermissionOK()) {
return;
}
if (!handleRoomInfo()) {
return;
}
Expand Down Expand Up @@ -252,6 +256,15 @@ private void goToDownload(String downloadUrl) {
startService(intent);
}

private boolean isPermissionOK() {
PermissionChecker checker = new PermissionChecker(this);
boolean isPermissionOK = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checker.checkPermission();
if (!isPermissionOK) {
ToastUtils.showLongToast(this, "Some permissions is not approved !!!");
}
return isPermissionOK;
}

private final RadioGroup.OnCheckedChangeListener mOnCheckedChangeListener = (group, checkedId) -> {
switch (group.getCheckedRadioButtonId()) {
case R.id.camera_capture_button:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,28 +319,27 @@ protected void onPause() {
}

@Override
public void finish() {
if (isFinishing()) {
return;
}
if (mIsAdmin && mIsMergeStreaming) {
// 如果当前正在合流,则停止
mClient.stopLiveStreaming(mCurrentMergeConfig);
mIsMergeStreaming = false;
}
if (mIsAdmin && mIsDirectStreaming) {
// 如果当前正在单路转推,则停止
mClient.stopLiveStreaming(mCurrentDirectConfig);
mIsDirectStreaming = false;
protected void onDestroy() {
super.onDestroy();
if (mClient != null) {
if (mIsAdmin && mIsMergeStreaming) {
// 如果当前正在合流,则停止
mClient.stopLiveStreaming(mCurrentMergeConfig);
mIsMergeStreaming = false;
}
if (mIsAdmin && mIsDirectStreaming) {
// 如果当前正在单路转推,则停止
mClient.stopLiveStreaming(mCurrentDirectConfig);
mIsDirectStreaming = false;
}
// 离开房间
mClient.leave();
mClient = null;
}
mUpdateNetWorkQualityInfoTask.cancel();
mClient.unpublish(mLocalTrackList);
// 离开房间
mClient.leave();
mClient = null;
// 反初始化
QNRTC.deinit();

mUpdateNetWorkQualityInfoTask.cancel();
if (mTrackWindowFullScreen != null) {
mTrackWindowFullScreen.dispose();
}
Expand All @@ -349,7 +348,6 @@ public void finish() {
}
mTrackWindowsList.clear();
mPopWindow = null;
super.finish();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public void onBackPressed() {
saveUserName();
}

private boolean isPermissionOK() {
PermissionChecker checker = new PermissionChecker(this);
boolean isPermissionOK = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checker.checkPermission();
if (!isPermissionOK) {
ToastUtils.showLongToast(this, "Some permissions is not approved !!!");
}
return isPermissionOK;
}

private void saveUserName() {
final String userName = mUsernameEditText.getText().toString();
if (userName.isEmpty()) {
Expand All @@ -72,9 +63,6 @@ private void saveUserName() {
ToastUtils.showShortToast(this, getString(R.string.wrong_user_name_toast));
return;
}
if (!isPermissionOK()) {
return;
}

Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(Config.USER_NAME, userName);
Expand Down

0 comments on commit 9f84a81

Please sign in to comment.