在我的应用程序中,我正在向用户请求位置许可。当用户允许位置许可时,我检查GPS是否启用。如果GPS不可用,则应显示自定义对话框。但问题是在允许之后对话框没有显示出来。我已经使用调试器进行了检查,它通过了对话框的代码,但它没有显示对话框。
/**
* show LocationRequestDialog to enable location
*/
public void showEnableLocatioAlert(final Context mContext, int id) {
mLocationDialog = new Dialog(getActivity());
mAppData.mDialogsList.add(mLocationDialog);
mLocationDialog.setCancelable(false);
mLocationDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
mLocationDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mLocationDialog.setContentView(R.layout.dialog_internet_not_avail);
TextView titleTV = (TextView) mLocationDialog.findViewById(R.id.dialogTitleTV);
TextView bodyTV = (TextView) mLocationDialog.findViewById(R.id.dialogMessageTV);
titleTV.setText(mContext.getString(R.string.gps_disabled));
bodyTV.setText(mContext.getString(R.string.enable_gps));
Button yesBT = (Button) mLocationDialog.findViewById(R.id.yesBT);
Button noBT = (Button) mLocationDialog.findViewById(R.id.noBT);
yesBT.setText(getString(R.string.enable));
noBT.setText(getString(R.string.cancel));
yesBT.setVisibility(View.VISIBLE);
noBT.setVisibility(View.VISIBLE);
yesBT.requestLayout();
noBT.requestLayout();
final Fragment fragment = getActivity().getSupportFragmentManager().findFragmentById(id);
yesBT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLocationDialog.dismiss();
mAppData.isSettingsOrGalleryOpened = true;
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
}
});
noBT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLocationDialog.dismiss();
}
});
mLocationDialog.show();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == Constants.LOCATION_PERMISSIONS) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//locateMe();
showEnableLocatioAlert(getActivity(), R.id.containerFL);
} else {
Utils.getInstance().showPermissionDialog(getActivity(), mView, true);
}
}
}
任何帮助将不胜感激 感谢