I have an app that needs to create a file in an app-specific directory, but that file need to be public so it can be edited by another app, so I need a path like this "/storage/emulated/0/Android/data/com.my.app/files"
I already checked Xamarin Documentation and I found what I need. Based on that Documentation I can use this method Android.Content.Context.GetExternalFilesDir(string type).
But I get this error when I call that method.
An object reference is required for the non-static field, method, or property 'Context.GetExternalFilesDir(string)'
I also already check this forum but found no luck
Any ideas how to solve this issue ?
To get privateExternalStorage you can use this
Android.App.Application.Context.GetExternalFilesDir(null).AbsolutePath;
Related
I'm trying to get started writing to a file in Kotlin on Android. I found this answer: here
The answer suggests doing a:
val path = context.getFilesDir()
However, this doesn't work for me. The IDE complains that context is an unresolved reference. So I guess this needs to be declared and initialised first somewhere. Any ideas where I am going wrong? What should I do to fix this?
I have MyAppProject as android application project and MyLibProject as android library project.
I have strings.xml(2 strings) and one xyz.java class in MyLibProject.
xyz.java class has 2 get methods to access the strings.xml values.
I have added reference library project "MyLibProject" in "MyAppProject" application project.
For some usecase, I will check whether Library project xyz.java class is in classpath then get the
values from xyz.class.
How to access the strings.xml texts in xyz.java class get method?
As far as I'm aware, you should be able to access any references via a fully qualified name for the R file you're attempting to access, via the Context. Something like (untested):
Context.getString(com.YOUR.LIB.R.string.YOURSTRING));
Failing that, you could possibly import the com.YOUR.LIB.R file directly into your activity.
Hope this helps! And I hope that I understand what you're trying to achieve. If not, please provide more information and possibly some code you've already tried, may help explain your problem :)
This question has been very old, but creating Android libraries will never get old. I have been working on creating Android libraries for a few days now, and myself encountered this issue of not been able to use res directory resources in library's java files due to some reason. After 2 days of searching, I found that I was missing package declaration in my library's manifest file.
So, to make it working, check if you have declared package in manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourpackage">
</manifest>
It worked for me after this change, now I can use resources in library's java files. I hope it works for you too.
i search how can i get the IMSI number of android devices.
and i understand that i have to use SystemProperty class as it explained here:
getting IMSI from android phone?
but when i am trying to pass this parameter, TelephonyProperties.PROPERTY_IMSI, to the SystemPropery class it shows me this error:
"cannot be resolved to a variable"
The link you posted has the answer, those properties are not publicly accessible, you can use tricks to get to them but there is no guarantee that they will exist in all/future releases/devices.
https://stackoverflow.com/a/5656732/329034
I am working on the android gingerbread source code. I want to know where the method implementaions of these .aidl files are done so that i can add my own method and defination. I have searched everywhere through the framework folder of source code but not found. I espacially want the ITelephony.aidl Inteface methods implementation. Please tell me the location path taking framework as root OR some idea on how and where they are implemented.
I think what you are looking for is in packages/apps/Phone/src/com/android/phone/. Specifically, PhoneInterfaceManager.java has these methods, but I believe it is just a layer on top of the various Phone class implementations.
Is there a way to get the application's directory to save private data to a file for my application directly from the NDK? In other words, I need an equivalent of the Java function mContext.getFilesDir().
I have noted that other posts such as this one:
Android NDK Write File
mention what is the 'usual' place for this directory to be. But for it to be correct in all versions and all devices, an equivalent system call is surely necessary.
I am currently using a NativeActivity and no Java at all.
Thank you for your time.
I have custom helper class for accessing various paths, for the data directory I do this:
Read /proc/self/cmdline or /proc/**MyPID**/cmdline
Append the results from #1 to /data/data/
Example results:
/data/data/com.yourcompany.yourproduct/
If you are using NativeActivity then you have access from native code to an ANativeActivity instance (see <ndk_root>/platforms/android-9/arch-arm/usr/include/android/native_activity.h) which has internalDataPath and externalDataPath members.