Skip to content

Commit

Permalink
Better permission prompts
Browse files Browse the repository at this point in the history
Version 1.3
  • Loading branch information
blackboxembedded committed Jan 13, 2023
1 parent bc07ebe commit fe746bb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.blackboxembedded.wunderlinqgopro"
minSdkVersion 23
targetSdkVersion 32
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="30" />

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"/>

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
Expand All @@ -33,8 +37,7 @@
<activity
android:name=".DeviceScanActivity"
android:exported="true"
android:launchMode="singleTask"
android:label="@string/app_name">
android:launchMode="singleTask">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,14 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
return;
}

checkPermissions();

}

@Override
protected void onResume() {
super.onResume();

// Check permissions
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_FINE_LOCATION);
}

// Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled,
// fire an intent to display a dialog asking the user to grant permission to enable it.
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S ||
Expand Down Expand Up @@ -464,6 +461,49 @@ public void onDismiss(DialogInterface dialog) {
}
}
}

//Check Permissions
void checkPermissions(){
// Check permissions
if ((android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S) &&
(ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.location_request_alert_title));
builder.setMessage(getString(R.string.location_request_alert_body));
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(DeviceScanActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_FINE_LOCATION);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.show();
} else if ((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) &&
(ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED)){
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.bt_request_alert_title));
builder.setMessage(getString(R.string.bt_request_alert_body));
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(DeviceScanActivity.this, new String[]{Manifest.permission.BLUETOOTH_SCAN}, PERMISSION_REQUEST_BLUETOOTH_SCAN);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.show();
}
}

//start timer function
void startTimer() {
if(!timerRunning) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<string name="negative_location_alert_title">Location Request Denied</string>
<string name="negative_location_alert_body">Location Permissions are required for Bluetooth scanning</string>

<string name="location_request_alert_title">Location Permission Required</string>
<string name="location_request_alert_body">The WunderLINQ GoPro Remote needs access to your location to scan for nearby GoPro Cameras.</string>
<string name="bt_request_alert_title">Bluetooth Permission Required</string>
<string name="bt_request_alert_body">The WunderLINQ GoPro Remote needs the Bluetooth scanning permission to scan for nearby GoPro Cameras. </string>

<string name="btscan_alert_title">Bluetooth Scan Request</string>
<string name="btscan_alert_body">Location Permissions are required for Bluetooth scanning</string>
<string name="negative_btscan_alert_title">Location Request Denied</string>
Expand Down

0 comments on commit fe746bb

Please sign in to comment.