Refer to the resource directory Android module / library

0

I have an Android module aboutscreenlibrary , which is to implement an information activity about the app.

Module: aboutscreenlibrary

With a AboutActivity activity that loads a menu to see what's new, which should be obtained from res/raw/changelog.txt directories:

res/drawable
   /layout
   /menú
   /raw/changelog.txt
        credits.txt

Inside that module I have a

public class CustomDialogHTML extends DialogFragment...'
    ...
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ...
        Uri uri = Uri.parse(getArguments().getString("uri", ""));            
        String fileName = uri.getHost();
        ...
        InputStream inputStream = getResources().openRawResource(
                getResources().getIdentifier(fileName,
                        "raw", getActivity().getApplicationContext().getPackageName()));

Project

I only call the activity of the module, in the project the res/raw/... directory does not exist since in principle I wanted to have them inside the module.

In Debug mode everything works correctly, that's when I change to reléase that shows me empty.

The error I think is in

getResources().getIdentifier(fileName,"raw", getActivity().getApplicationContext().getPackageName() since that refers to the context of the activity and not the module.

How can I refer to the resource directory of the module?

    
asked by Webserveis 06.06.2017 в 19:18
source

1 answer

0

Try this form by getting the resource id, if it exists by creating the InputStream:

InputStream inputStream = null;
int resId = getApplicationContext().getResources().getIdentifier(fileName, "raw", getApplicationContext().getPackageName());
  if(resId != 0){
          //Si existe el recurso lo obtiene.
        inputStream = getResources().openRawResource(resId);
  }
    
answered by 06.06.2017 в 19:37