Skip to content

Commit

Permalink
Specify targetSdkVersion to 26 and request WRITE_EXTERNAL_STORAGE
Browse files Browse the repository at this point in the history
dynamically at application startup to meet updated Google Play requirements.
  • Loading branch information
gkv311 committed Jan 16, 2019
1 parent 144eea5 commit 0746261
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sview/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sview"
android:versionCode="16"
android:versionName="16.12"
android:versionName="19.01"
android:installLocation="auto">
<application android:label="@string/app_name"
android:hasCode="true"
Expand Down Expand Up @@ -227,7 +227,7 @@
<activity android:name="com.sview.CrashReportActivity" android:label="@string/app_crash_name" android:configChanges="orientation|keyboardHidden"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></activity>
</application>

<uses-sdk android:minSdkVersion="15" />
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" />
<uses-feature android:glEsVersion="0x00020000"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
49 changes: 49 additions & 0 deletions sview/src/com/sview/StActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public void onCreate(Bundle theSavedInstanceState) {
myContext = new ContextWrapper(this);
myContext.getExternalFilesDir(null);

askUserPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, null);

mySensorMgr = (SensorManager )getSystemService(Context.SENSOR_SERVICE);
mySensorOri = mySensorMgr.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
if(mySensorOri == null) {
Expand All @@ -172,6 +174,53 @@ public void onCreate(Bundle theSavedInstanceState) {
updateHideSystemBars(myToHideStatusBar, myToHideNavBar);
}

/**
* Request user permission.
*/
protected void askUserPermission(String thePermission, String theRationale) {
// Dynamically load methods introduced by API level 23.
// On older system this permission is granted by user during application installation.
java.lang.reflect.Method aMetPtrCheckSelfPermission, aMetPtrRequestPermissions, aMetPtrShouldShowRequestPermissionRationale;
try {
aMetPtrCheckSelfPermission = myContext.getClass().getMethod("checkSelfPermission", String.class);
aMetPtrRequestPermissions = getClass().getMethod("requestPermissions", String[].class, int.class);
aMetPtrShouldShowRequestPermissionRationale = getClass().getMethod("shouldShowRequestPermissionRationale", String.class);
} catch(SecurityException theError) {
//postMessage("Unable to find permission methods:\n" + theError.getMessage());
return;
} catch(NoSuchMethodException theError) {
//postMessage("Unable to find permission methods:\n" + theError.getMessage());
return;
}

try {
//int isAlreadyGranted = myContext.checkSelfPermission(thePermission);
int isAlreadyGranted = (Integer )aMetPtrCheckSelfPermission.invoke(myContext, thePermission);
if(isAlreadyGranted == android.content.pm.PackageManager.PERMISSION_GRANTED) {
return;
}

//boolean toShowInfo = shouldShowRequestPermissionRationale(thePermission);
boolean toShowInfo = theRationale != null && (Boolean )aMetPtrShouldShowRequestPermissionRationale.invoke(this, thePermission);
if(toShowInfo) {
postMessage(theRationale);
}

// show dialog to user
//requestPermissions (new String[]{thePermission}, 0);
aMetPtrRequestPermissions.invoke(this, new String[]{thePermission}, 0);
} catch(IllegalArgumentException theError) {
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
return;
} catch(IllegalAccessException theError) {
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
return;
} catch(java.lang.reflect.InvocationTargetException theError) {
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
return;
}
}

/**
* Handle new open file event.
*/
Expand Down

0 comments on commit 0746261

Please sign in to comment.