ANDROID: Fix deprecated Handler()
Also remove permission request for external storage from API 33 and above since it no longer works
This commit is contained in:
parent
56e753df7d
commit
8141ee1cbb
5 changed files with 26 additions and 18 deletions
|
@ -32,6 +32,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.media.AudioManager;
|
||||
//import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
@ -277,6 +278,7 @@ public class CustomKeyboardView extends View implements View.OnClickListener {
|
|||
private final WeakReference<CustomKeyboardView> mListenerReference;
|
||||
|
||||
public CustomKeyboardViewHandler(CustomKeyboardView listener) {
|
||||
super(Looper.getMainLooper());
|
||||
mListenerReference = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
package org.scummvm.scummvm;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -237,6 +238,7 @@ public class MultitouchHelper {
|
|||
private final WeakReference<MultitouchHelper> mListenerReference;
|
||||
|
||||
public MultitouchHelperHandler(MultitouchHelper listener) {
|
||||
super(Looper.getMainLooper());
|
||||
mListenerReference = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -805,9 +805,12 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
|
|||
@Override
|
||||
protected String[] getAllStorageLocations() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
|
||||
&& (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
||||
|| checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
|
||||
) {
|
||||
// In Tiramisu (API 33) and above, READ and WRITE external storage permissions have no effect,
|
||||
// and they are automatically denied -- onRequestPermissionsResult() will be called without user's input
|
||||
requestPermissions(MY_PERMISSIONS_STR_LIST, MY_PERMISSION_ALL);
|
||||
} else {
|
||||
return ExternalStorage.getAllStorageLocations(getApplicationContext()).toArray(new String[0]);
|
||||
|
@ -1084,15 +1087,13 @@ public class ScummVMActivity extends Activity implements OnKeyboardVisibilityLis
|
|||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == MY_PERMISSION_ALL) {
|
||||
int numOfReqPermsGranted = 0;
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0) {
|
||||
for (int iterGrantResult: grantResults) {
|
||||
if (iterGrantResult == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[0] + " permission was granted at Runtime");
|
||||
++numOfReqPermsGranted;
|
||||
} else {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[0] + " permission was denied at Runtime");
|
||||
}
|
||||
// If request is canceled, the result arrays are empty.
|
||||
for (int i = 0; i < grantResults.length; ++i) {
|
||||
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[i] + " permission was granted at Runtime");
|
||||
++numOfReqPermsGranted;
|
||||
} else {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[i] + " permission was denied at Runtime");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.scummvm.scummvm;
|
|||
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.content.Context;
|
||||
//import android.util.Log;
|
||||
|
@ -79,6 +80,7 @@ public class ScummVMEventsBase implements
|
|||
private final WeakReference<ScummVMEventsBase> mListenerReference;
|
||||
|
||||
public ScummVMEventHandler(ScummVMEventsBase listener) {
|
||||
super(Looper.getMainLooper());
|
||||
mListenerReference = new WeakReference<>(listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,12 @@ public class SplashActivity extends Activity {
|
|||
hideSystemUI();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
|
||||
&& (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
||||
|| checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
|
||||
) {
|
||||
// In Tiramisu (API 33) and above, READ and WRITE external storage permissions have no effect,
|
||||
// and they are automatically denied -- onRequestPermissionsResult() will be called without user's input
|
||||
requestPermissions(MY_PERMISSIONS_STR_LIST, MY_PERMISSION_ALL);
|
||||
} else {
|
||||
startActivity(new Intent(this, ScummVMActivity.class));
|
||||
|
@ -49,15 +52,13 @@ public class SplashActivity extends Activity {
|
|||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == MY_PERMISSION_ALL) {
|
||||
int numOfReqPermsGranted = 0;
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0) {
|
||||
for (int iterateGrantResult: grantResults) {
|
||||
if (iterateGrantResult == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[0] + " permission was granted at Runtime");
|
||||
++numOfReqPermsGranted;
|
||||
} else {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[0] + " permission was denied at Runtime");
|
||||
}
|
||||
// If request is canceled, the result arrays are empty.
|
||||
for (int i = 0; i < grantResults.length; ++i) {
|
||||
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[i] + " permission was granted at Runtime");
|
||||
++numOfReqPermsGranted;
|
||||
} else {
|
||||
Log.i(ScummVM.LOG_TAG, permissions[i] + " permission was denied at Runtime");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue