Skip to content

Commit 0746261

Browse files
committed
Specify targetSdkVersion to 26 and request WRITE_EXTERNAL_STORAGE
dynamically at application startup to meet updated Google Play requirements.
1 parent 144eea5 commit 0746261

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

sview/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.sview"
44
android:versionCode="16"
5-
android:versionName="16.12"
5+
android:versionName="19.01"
66
android:installLocation="auto">
77
<application android:label="@string/app_name"
88
android:hasCode="true"
@@ -227,7 +227,7 @@
227227
<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>
228228
</application>
229229

230-
<uses-sdk android:minSdkVersion="15" />
230+
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" />
231231
<uses-feature android:glEsVersion="0x00020000"/>
232232
<uses-permission android:name="android.permission.INTERNET" />
233233
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

sview/src/com/sview/StActivity.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public void onCreate(Bundle theSavedInstanceState) {
146146
myContext = new ContextWrapper(this);
147147
myContext.getExternalFilesDir(null);
148148

149+
askUserPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, null);
150+
149151
mySensorMgr = (SensorManager )getSystemService(Context.SENSOR_SERVICE);
150152
mySensorOri = mySensorMgr.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
151153
if(mySensorOri == null) {
@@ -172,6 +174,53 @@ public void onCreate(Bundle theSavedInstanceState) {
172174
updateHideSystemBars(myToHideStatusBar, myToHideNavBar);
173175
}
174176

177+
/**
178+
* Request user permission.
179+
*/
180+
protected void askUserPermission(String thePermission, String theRationale) {
181+
// Dynamically load methods introduced by API level 23.
182+
// On older system this permission is granted by user during application installation.
183+
java.lang.reflect.Method aMetPtrCheckSelfPermission, aMetPtrRequestPermissions, aMetPtrShouldShowRequestPermissionRationale;
184+
try {
185+
aMetPtrCheckSelfPermission = myContext.getClass().getMethod("checkSelfPermission", String.class);
186+
aMetPtrRequestPermissions = getClass().getMethod("requestPermissions", String[].class, int.class);
187+
aMetPtrShouldShowRequestPermissionRationale = getClass().getMethod("shouldShowRequestPermissionRationale", String.class);
188+
} catch(SecurityException theError) {
189+
//postMessage("Unable to find permission methods:\n" + theError.getMessage());
190+
return;
191+
} catch(NoSuchMethodException theError) {
192+
//postMessage("Unable to find permission methods:\n" + theError.getMessage());
193+
return;
194+
}
195+
196+
try {
197+
//int isAlreadyGranted = myContext.checkSelfPermission(thePermission);
198+
int isAlreadyGranted = (Integer )aMetPtrCheckSelfPermission.invoke(myContext, thePermission);
199+
if(isAlreadyGranted == android.content.pm.PackageManager.PERMISSION_GRANTED) {
200+
return;
201+
}
202+
203+
//boolean toShowInfo = shouldShowRequestPermissionRationale(thePermission);
204+
boolean toShowInfo = theRationale != null && (Boolean )aMetPtrShouldShowRequestPermissionRationale.invoke(this, thePermission);
205+
if(toShowInfo) {
206+
postMessage(theRationale);
207+
}
208+
209+
// show dialog to user
210+
//requestPermissions (new String[]{thePermission}, 0);
211+
aMetPtrRequestPermissions.invoke(this, new String[]{thePermission}, 0);
212+
} catch(IllegalArgumentException theError) {
213+
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
214+
return;
215+
} catch(IllegalAccessException theError) {
216+
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
217+
return;
218+
} catch(java.lang.reflect.InvocationTargetException theError) {
219+
postMessage("Internal error: Unable to call permission method:\n" + theError.getMessage());
220+
return;
221+
}
222+
}
223+
175224
/**
176225
* Handle new open file event.
177226
*/

0 commit comments

Comments
 (0)