FolioReader-Android
FolioReader-Android copied to clipboard
App crashes when trying to open raw using folioreader in android 11 but runs perfectly on 10 and below
Issue / Feature - Folioreader crashes app
FolioReader version - com.folioreader:folioreader:0.5.1
FolioReader Stock / Modified -
Android SDK - min(22) target(30)
Mobile / Tablet / Emulator Info -
Crash / Error - --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zeoharlem.ezivah, PID: 5844
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.speech.tts.TextToSpeech.setOnUtteranceCompletedListener(android.speech.tts.TextToSpeech$OnUtteranceCompletedListener)' on a null object reference
at com.folioreader.ui.folio.mediaoverlay.MediaController$2.onInit(MediaController.java:114)
at android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:862)
at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:840)
at android.speech.tts.TextToSpeech.
Steps to reproduce / Describe in detail -
Hi, Have you solved this issue
I have solved this issue, if your app is targeting android 11 then the READ/WRITE EXTERNAL_STORAGE Permissions are ignored, and also android:requestLegacyExternalStorage="true"
is also ignore but you have to keep these in manifest in order to be compatible for devices below Android 11. So for android 11 add the following permission in the manifest file.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and in FileUtils.saveEpubFileAndLoadLazyBook(,,,) check for permission using the following method
private static boolean checkPermission(Context context) { if (SDK_INT >= Build.VERSION_CODES.R) { return Environment.isExternalStorageManager(); } else { int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; } }
if the app doesn't have manage external storage
permission or then request that permission by using the following method
private static void requestPermission(Context context) { Activity activity = (Activity) context; if (SDK_INT >= Build.VERSION_CODES.R) { try { Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse(String.format("package:%s", context.getApplicationContext().getPackageName()))); activity.startActivityForResult(intent, 2296); } catch (Exception e) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); activity.startActivityForResult(intent, 2296); } } else { //below android 11 ActivityCompat.requestPermissions((Activity) context, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); } }
if the user has the permission then continue with the normal flow
I have solved this issue, if your app is targeting android 11 then the READ/WRITE EXTERNAL_STORAGE Permissions are ignored, and also
android:requestLegacyExternalStorage="true"
is also ignore but you have to keep these in manifest in order to be compatible for devices below Android 11. So for android 11 add the following permission in the manifest file.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and in FileUtils.saveEpubFileAndLoadLazyBook(,,,) check for permission using the following method
private static boolean checkPermission(Context context) { if (SDK_INT >= Build.VERSION_CODES.R) { return Environment.isExternalStorageManager(); } else { int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; } }
if the app doesn't have
manage external storage
permission or then request that permission by using the following methodprivate static void requestPermission(Context context) { Activity activity = (Activity) context; if (SDK_INT >= Build.VERSION_CODES.R) { try { Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse(String.format("package:%s", context.getApplicationContext().getPackageName()))); activity.startActivityForResult(intent, 2296); } catch (Exception e) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); activity.startActivityForResult(intent, 2296); } } else { //below android 11 ActivityCompat.requestPermissions((Activity) context, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); } }
if the user has the permission then continue with the normal flow
I will try this and revert.. thank you...
I have solved this issue, if your app is targeting android 11 then the READ/WRITE EXTERNAL_STORAGE Permissions are ignored, and also
android:requestLegacyExternalStorage="true"
is also ignore but you have to keep these in manifest in order to be compatible for devices below Android 11. So for android 11 add the following permission in the manifest file.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and in FileUtils.saveEpubFileAndLoadLazyBook(,,,) check for permission using the following method
private static boolean checkPermission(Context context) { if (SDK_INT >= Build.VERSION_CODES.R) { return Environment.isExternalStorageManager(); } else { int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; } }
if the app doesn't have
manage external storage
permission or then request that permission by using the following methodprivate static void requestPermission(Context context) { Activity activity = (Activity) context; if (SDK_INT >= Build.VERSION_CODES.R) { try { Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse(String.format("package:%s", context.getApplicationContext().getPackageName()))); activity.startActivityForResult(intent, 2296); } catch (Exception e) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); activity.startActivityForResult(intent, 2296); } } else { //below android 11 ActivityCompat.requestPermissions((Activity) context, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); } }
if the user has the permission then continue with the normal flow
thanks for your response.. checking that method saveEpubFileAndLoadLazyBook there was no checking of permission but i cannot edit it cos it's a readonly file... kindly advise on how to go about it
I have solved this issue, if your app is targeting android 11 then the READ/WRITE EXTERNAL_STORAGE Permissions are ignored, and also
android:requestLegacyExternalStorage="true"
is also ignore but you have to keep these in manifest in order to be compatible for devices below Android 11. So for android 11 add the following permission in the manifest file.<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and in FileUtils.saveEpubFileAndLoadLazyBook(,,,) check for permission using the following method private static boolean checkPermission(Context context) { if (SDK_INT >= Build.VERSION_CODES.R) { return Environment.isExternalStorageManager(); } else { int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; } } if the app doesn't havemanage external storage
permission or then request that permission by using the following method private static void requestPermission(Context context) { Activity activity = (Activity) context; if (SDK_INT >= Build.VERSION_CODES.R) { try { Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse(String.format("package:%s", context.getApplicationContext().getPackageName()))); activity.startActivityForResult(intent, 2296); } catch (Exception e) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); activity.startActivityForResult(intent, 2296); } } else { //below android 11 ActivityCompat.requestPermissions((Activity) context, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); } } if the user has the permission then continue with the normal flowthanks for your response.. checking that method saveEpubFileAndLoadLazyBook there was no checking of permission but i cannot edit it cos it's a readonly file... kindly advise on how to go about it
Hi I hope you are doing well, So as you said that file is readOnly that means you have implemented FolioReader dependency, this way libraries won't be editable so what you have that (that's what I do most of the time) you have to add the folioReader as a module in your project. This way you will have access to all of the file and you can change anything like you do in your app module.
Download the folioReader library code from this repo, place the folioReader folder in your project folder, add the name in gradle settings file and you are good to go for more information you can google or you can view the demo app in this repo. I hope this will help
@awaisabbasaa11 thanks for the response so far... it is difficult adding folioreader as module to project. i want to ask if you can add it to a dummy project and share the link to the project... your response is greatly appreciated
@zeoharlem Sorry for being late, https://github.com/UmarAlyas0078/FolioModule here is a link of demo repository with some customization already done, so to undo any customization please reimport the folio Reader. :)
I have solved this issue, if your app is targeting android 11 then the READ/WRITE EXTERNAL_STORAGE Permissions are ignored, and also
android:requestLegacyExternalStorage="true"
is also ignore but you have to keep these in manifest in order to be compatible for devices below Android 11. So for android 11 add the following permission in the manifest file.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and in FileUtils.saveEpubFileAndLoadLazyBook(,,,) check for permission using the following method
private static boolean checkPermission(Context context) { if (SDK_INT >= Build.VERSION_CODES.R) { return Environment.isExternalStorageManager(); } else { int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; } }
if the app doesn't have
manage external storage
permission or then request that permission by using the following methodprivate static void requestPermission(Context context) { Activity activity = (Activity) context; if (SDK_INT >= Build.VERSION_CODES.R) { try { Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse(String.format("package:%s", context.getApplicationContext().getPackageName()))); activity.startActivityForResult(intent, 2296); } catch (Exception e) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); activity.startActivityForResult(intent, 2296); } } else { //below android 11 ActivityCompat.requestPermissions((Activity) context, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); } }
if the user has the permission then continue with the normal flow
I think we can fix this by replacing the permissions request :
if (ContextCompat.checkSelfPermission(...
with something like
if (!checkPermission(this)) { requestPermission(this) finish() }else{ setupBook() }
Guys, we still have access to public directories :)
So, solution can be like this:
Before:
public static String getFolioEpubFolderPath(Context context, String epubFileName) { return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + FOLIO_READER_ROOT + "/" + epubFileName; }
After:
public static String getFolioEpubFolderPath(Context context, String epubFileName) { return context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/" + FOLIO_READER_ROOT + "/" + epubFileName; }
hi @awaisabbasaa11 do you have folioreader module in dummy project for kotlin? Thank you!
@zeoharlem Sorry for being late, https://github.com/UmarAlyas0078/FolioModule here is a link of demo repository with some customization already done, so to undo any customization please reimport the folio Reader. :)
Hi @awaisabbasaa11, i have tried everything but this is not working like the app not working 11 upwards, the code is breaking. do you have any suggestion