Android Studio: Choosing the application directory with the setConfig () method

advertisements

I am trying to find my application's path after its installation and initializing a XML file as a config file by giving its path in app/config directory.

I made lots of research here but could not solve my problem: The config file is not initialized/recognized/seen by the application. The error is always about not loading the config.

I have tried many ways to get path but the result did not change. Related part of my code is :

            Context context = new Context();
            PackageManager m = getPackageManager();
            String s = getPackageName();
            PackageInfo p = m.getPackageInfo(s, 0);
            s = p.applicationInfo.dataDir;
            s +=  "/app/config/xmlsignature-config.xml";
            context.setConfig(new Config(s));

Thank you in advance..


You shouldn't instantiate your context. That's created by Android for you.

You should change:

Context context = new Context();

to: Context context = getContext(); or Context context = getApplicationContext();