SD-188 - navigate to phone settings if permission is denied
This commit is contained in:
parent
66625bcdd1
commit
81937a5e0f
@ -1,5 +1,6 @@
|
||||
package com.safemobile.enums;
|
||||
|
||||
public enum ProviderSettingsStatus {
|
||||
ACTION_APPLICATION_DETAILS_SETTINGS
|
||||
APPLICATION_DETAILS,
|
||||
SETTINGS
|
||||
}
|
||||
|
@ -3,18 +3,26 @@ package com.safemobile.helpers;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.safemobile.enums.ProviderSettingsStatus;
|
||||
|
||||
public class ProviderSettingsHelper {
|
||||
private static final String PACKAGE = "package";
|
||||
public static final String PACKAGE = "package";
|
||||
public static final String ACTION_APPLICATION_DETAILS_SETTINGS = Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
|
||||
public static final String ACTION_SETTINGS = Settings.ACTION_SETTINGS;
|
||||
|
||||
public static String getAction(ProviderSettingsStatus providerSettingsStatus){
|
||||
switch (providerSettingsStatus){
|
||||
case ACTION_APPLICATION_DETAILS_SETTINGS:
|
||||
return "android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS";
|
||||
private ProviderSettingsHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static String getAction(ProviderSettingsStatus providerSettingsStatus) {
|
||||
switch (providerSettingsStatus) {
|
||||
case APPLICATION_DETAILS:
|
||||
return ACTION_APPLICATION_DETAILS_SETTINGS;
|
||||
case SETTINGS:
|
||||
default:
|
||||
return "android.provider.Settings";
|
||||
return ACTION_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import com.google.android.gms.tasks.Task;
|
||||
|
||||
public interface IDialogService {
|
||||
Task<Boolean> showDialog(Activity activity, String title, String message, String cancel, String ok);
|
||||
Task<Boolean> showPermissionRequestDialog(Activity activity, String title, String message, String cancel);
|
||||
Task<Boolean> showPermissionRequestDialog(Activity activity, String message, String cancel);
|
||||
|
||||
void showError(Activity activity, String message);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class AppParams {
|
||||
|
||||
/* SafeMobile Dispatch */
|
||||
public static ArrayList<User> allUsers = new ArrayList<User>();
|
||||
public static Theme theme = Theme.SAFENET; // the Theme type
|
||||
public static Theme theme = Theme.SAFEDISPATCH; // the Theme type
|
||||
|
||||
|
||||
/* ***************************************** */
|
||||
|
@ -14,6 +14,7 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.gms.tasks.TaskCompletionSource;
|
||||
import com.safemobile.activities.AbstractEmptyActivity;
|
||||
import com.safemobile.activities.AbstractLiveActivity;
|
||||
import com.safemobile.activities.AbstractMessagesActivity;
|
||||
@ -21,6 +22,8 @@ import com.safemobile.activities.AbstractRadioActivity;
|
||||
import com.safemobile.activities.AbstractSDParentActivity;
|
||||
import com.safemobile.enums.AuthorizationCode;
|
||||
import com.safemobile.enums.AuthorizationStatus;
|
||||
import com.safemobile.enums.ProviderSettingsStatus;
|
||||
import com.safemobile.helpers.ProviderSettingsHelper;
|
||||
import com.safemobile.interfaces.IPermissionModule;
|
||||
import com.safemobile.interfaces.ITCPListener;
|
||||
import com.safemobile.interfaces.TCPEvent;
|
||||
@ -880,7 +883,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
tabHost.setCurrentTabByTag(TEXT);
|
||||
AppParams.crtTab = AppParams.Tabs.message;
|
||||
Vehicle vehicle = getVehicle4Imei(getImei());
|
||||
if(vehicle != null)
|
||||
if (vehicle != null)
|
||||
getMessageActivity().setScId(vehicle.sc_id);
|
||||
getMessageActivity().LASTMESSAGES = false;
|
||||
getMessageActivity().getLastSMS();
|
||||
@ -1057,7 +1060,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
SM.Debug("########### UPDATE");
|
||||
int scId = demoPosition % 3 == 0 ? 101 : 102;
|
||||
SuperVehicle superVehicle = (getSuperVehHash().get((long) scId));
|
||||
if(superVehicle != null)
|
||||
if (superVehicle != null)
|
||||
superVehicle.SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed);
|
||||
getLiveActivity().refreshMap();
|
||||
}
|
||||
@ -1782,7 +1785,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
Vehicle vehicle = getVehicle4Imei(getImei());
|
||||
if (vehicle != null)
|
||||
textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), vehicle.name));
|
||||
else textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), getImei()));
|
||||
else
|
||||
textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), getImei()));
|
||||
textViewNMMessage.setText(String.format("TYPE: %s", getMess()));
|
||||
// show layout
|
||||
layoutNewMessage.setVisibility(View.VISIBLE);
|
||||
@ -2233,13 +2237,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
SM.Debug("onRequestPermissionsResult", "[requestCode] " + requestCode );
|
||||
SM.Debug("onRequestPermissionsResult", "[requestCode] " + requestCode);
|
||||
String permission = "";
|
||||
switch (requestCode) {
|
||||
case PermissionModule.RECORD_AUDIO_PERMISSION_REQUEST_CODE:
|
||||
permission = Manifest.permission.RECORD_AUDIO;
|
||||
break;
|
||||
default: throw new IllegalStateException("Unexpected value: " + requestCode);
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + requestCode);
|
||||
}
|
||||
|
||||
AuthorizationStatus result;
|
||||
@ -2252,13 +2257,13 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
if (permissions.length == 0)
|
||||
return;
|
||||
|
||||
if (permissions[0].equals(Manifest.permission.RECORD_AUDIO)){
|
||||
if (permissions[0].equals(Manifest.permission.RECORD_AUDIO)) {
|
||||
onAudioPermissionChanged(result);
|
||||
}
|
||||
}
|
||||
|
||||
private void onAudioPermissionChanged(AuthorizationStatus result) {
|
||||
if (result == AuthorizationStatus.AUTHORIZE){
|
||||
if (result == AuthorizationStatus.AUTHORIZE) {
|
||||
// select button
|
||||
buttonRadio.setSelected(true);
|
||||
// deselect other buttons
|
||||
@ -2276,23 +2281,38 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
getRadioActivity().allVehicle = getAllVehicle();
|
||||
getRadioActivity().UpdateVehicle();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DialogService dialogService = new DialogService();
|
||||
Task<Boolean> responseTask = dialogService.showPermissionRequestDialog(this, "title", "permissions denied", getString(R.string.cancel));
|
||||
Task<Boolean> responseTask = dialogService.showPermissionRequestDialog(this,
|
||||
getString(R.string.permissionBlocked, getString(R.string.microphone), getString(R.string.radio_tab), getString(R.string.microphone)),
|
||||
getString(R.string.cancel));
|
||||
responseTask.addOnCompleteListener(task -> waitForUserInput(task.getResult()));
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForUserInput(Boolean result) {
|
||||
if (result)
|
||||
{
|
||||
//navigate to phone's settings
|
||||
//ToDo: make the navigation .. see ProviderSettingsHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result) {
|
||||
final int requestCode = 1202;
|
||||
//navigate to application's settings
|
||||
String action = ProviderSettingsHelper.getAction(ProviderSettingsStatus.APPLICATION_DETAILS);
|
||||
if (action == null || action == "")
|
||||
return;
|
||||
|
||||
boolean isActionApplicationDetailsSettings = action.equals(ProviderSettingsHelper.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
|
||||
if (!ProviderSettingsHelper.canHandleAction(context, action))
|
||||
action = ProviderSettingsHelper.getAction(ProviderSettingsStatus.SETTINGS);
|
||||
|
||||
Intent intent = new Intent(action);
|
||||
|
||||
if (isActionApplicationDetailsSettings) {
|
||||
Uri uri = Uri.fromParts(ProviderSettingsHelper.PACKAGE, this.getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
}
|
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
this.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,12 @@ package com.safemobile.lib;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.gms.tasks.TaskCompletionSource;
|
||||
import com.safemobile.dispatch.R;
|
||||
import com.safemobile.interfaces.IDialogService;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class DialogService implements IDialogService {
|
||||
@Override
|
||||
public Task<Boolean> showDialog(Activity activity, String title, String message, String cancel, String ok) {
|
||||
@ -32,19 +29,22 @@ public class DialogService implements IDialogService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Boolean> showPermissionRequestDialog(Activity activity, String title, String message, String cancel) {
|
||||
return showDialog(activity,title,message,cancel, activity.getString(R.string.go_to_settings));
|
||||
public Task<Boolean> showPermissionRequestDialog(Activity activity, String message, String cancel) {
|
||||
return showDialog(
|
||||
activity,
|
||||
activity.getString(R.string.permission_denied),
|
||||
message,
|
||||
cancel,
|
||||
activity.getString(R.string.go_to_settings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(Activity activity, String message) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.DialoService_Info_ErrorMessage)
|
||||
.setMessage(message)
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(R.string.ok, (dialog, which) -> dialog.dismiss());
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
showDialog(
|
||||
activity,
|
||||
activity.getString(R.string.DialogService_Info_ErrorMessage),
|
||||
message,
|
||||
null,
|
||||
activity.getString(R.string.ok));
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +257,11 @@
|
||||
|
||||
|
||||
<string name="speedMph">%1$d mph</string>
|
||||
<string name="DialoService_Info_ErrorMessage">Oops, something happened</string>
|
||||
<string name="DialogService_Info_ErrorMessage">Oops, something happened</string>
|
||||
<string name="go_to_settings">Go to settings</string>
|
||||
<string name="permission_denied">Permission Denied</string>
|
||||
<string name="permissionBlocked">%1$s permission was not accepted. To be able to use the %2$s, please open application settings and grant the %3$s permission</string>
|
||||
<string name="microphone">Microphone</string>
|
||||
<string name="radio_tab">Radio Tab</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user