Skip to content
Snippets Groups Projects
Commit 8ee4529d authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Check read permission with StartActivity context

On Samsung Galaxy devices, app context seems to not be always ready
parent eae98504
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,9 @@
package org.videolan.vlc;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
......@@ -96,20 +94,10 @@ public class StartActivity extends Activity {
}
private void startMedialibrary(final boolean firstRun, final boolean upgrade) {
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (!VLCApplication.getMLInstance().isInitiated() && Permissions.canReadStorage())
startService(new Intent(MediaParsingService.ACTION_INIT, null, StartActivity.this, MediaParsingService.class)
.putExtra(EXTRA_FIRST_RUN, firstRun)
.putExtra(EXTRA_UPGRADE, upgrade));
}
};
final Context ctx = VLCApplication.getAppContext();
if (ctx != null)
runnable.run();
else
new Handler().postDelayed(runnable, 500);
if (!VLCApplication.getMLInstance().isInitiated() && Permissions.canReadStorage(StartActivity.this))
startService(new Intent(MediaParsingService.ACTION_INIT, null, StartActivity.this, MediaParsingService.class)
.putExtra(EXTRA_FIRST_RUN, firstRun)
.putExtra(EXTRA_UPGRADE, upgrade));
}
private boolean showTvUi() {
......
......@@ -73,9 +73,14 @@ public class Permissions {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static boolean canReadStorage() {
return canReadStorage(VLCApplication.getAppContext());
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static boolean canReadStorage(Context context) {
if (!AndroidUtil.isICSOrLater)
return VLCApplication.getAppContext().getExternalFilesDir(null) != null;
return !AndroidUtil.isMarshMallowOrLater || ContextCompat.checkSelfPermission(VLCApplication.getAppContext(),
return context.getExternalFilesDir(null) != null;
return !AndroidUtil.isMarshMallowOrLater || ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment