I want to use Country Detector which I can see in android sdk-23 location folder.
But even when I import whole location package, this class is not found.
I've even kept min sdk support as 23 only.
What am I missing on? Thanks a lot in advance!
You do not instantiate this class directly; instead, retrieve it through
* {#link android.content.Context#getSystemService
* Context.getSystemService(Context.COUNTRY_DETECTOR)}.
For more refer you can open that java file and check
The class CountryDetector may be in the sources but it is not included in the official API - and the API is the library your project uses as main library.
Therefore you can not access this class directly.
In this special case CountryDetector is a system service which you can request via Context.getSystemService (see answer from Shanmugapriya D).
In other cases the following applies:
If you want to use this unofficial class you have to use it via Java reflection.
See for example here:
Android and reflection
Alternatively you can try to build a JAR file and add it in Gradle as provided.
Related
I am trying to use the class SntpClient that should be in the android.net package, but Android Studio is telling me it cannot find it. Indeed when I look through the source jars (of both API 19 and API 21), the class is not there. However according to grepcode it should be.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/net/SntpClient.java
What am I doing wrong?
Google has chosen not to make all public classes available as part of the SDK. Visibility is controlled by the #hide comment tag as described here.
I'm not sure why they chose to hide SntpClient particularly, but provided you respect the terms of the Apache license you can copy the source into your application without much modification.
My application requires a method to be accessed from a class Trace.java, which is present in the package android.os.Trace. I have added the appropriate import statement in order to do this. But the build system shows an error mentioning that 'Trace class not found'.
But surprisingly the methods of some other classes in the same package, i.e. android.os are at all accessible. Would anyone address about this anomaly ?
Or is it due to limitations imposed on importing of this Trace.java class by android build system?
I am not using Android SDK but building the app directly along with along with JB source tree. The root directory of app has been put at the proper location in the android source tree.
Thanks in advance.
Check the sources of the class. If a method in the documentation has tag #hide then this method will be not included into SDK and, thus, will be not available for your application. However, I think you can call this method using reflection (if there is no security checks implemented for it).
It seems that this class is not public, and I have to access TELEPHONY_STATUS variables in this class because I see in android source code that the values can change considering what api version you are using.
Read this post from the android-developer mailing list.
android.provider.Telephony is part of the Open Source releases, but never included as part of the Official SDK.
You can view it, to understand how the system works, but you can't actually use it in your apps.
As it says in the post,
No, it does not appear in the SDK, and this means
you should not try to use it from your applications.
I am a Computer Science undergraduate student and I am creating an Android app that using an API to interact with an execution server.
The server takes a xml file and do various stuff with it(get data, process data etc.)and then gives back data as output. Both input and output are exchanged via this API.
The problem is that the API references code from javax.xml.bind, for example, JAXBContext while android doesn't have javax.xml.bind package in its core. (a well known issue)
Feasible solutions on the internet seems to be repackaging the code I need, but I don't know exactly what suppose to be.
Since the API reference classes in javax.xml.bind and javax.net, I guess I have to extract code from these 2 packages and make them part of the API (I have access to API source) and then repackage the API. However, I guess classes inside javax.xml.bind might have dependencies on other classes that not supported by Android, so does javax.net. (Please forgive me if this is stupid thought...)
So anyone know : whether there are classes, which codes in javax.xml.bind and javax.net depends on, not supported by android ?
Bit of tricky question really..
I will be really appreciated if you can provide a work around that enable a Android app to call an API that reference codes inside javax.xml.bind.
Try JiBX (http://jibx.sourceforge.net/), it's a small and fast footprint, Android compatible, XML binding framework.
I ended up with repacking those package which exists in standard Java library but not in Android. Basically, just get source code of all those missing packages and then put them into the API source and rename them into a name that is different from the original one and then change corresponding code in API that reference these methods as well (you have to use a different name, otherwise code reference methods in these package will still looking for methods in the core Library (i.e Android API)
Anyway, hope it helps. If you have the same problem.
If you have any better suggestion. Please share it!
Now I am doing an android project(Api level 8),I install JD-Eclipse(decompiler) to know the flow of program execution.The decompiled 'android.jar' contains full of abstract classes and interfaces, then where is the actual class containing the body to be executed? What is the name of that jar file?
You probably won't find what you are looking for. The android.jar is an API and as that not directly executable, there isn't even any guarantee that it contains such code.
If you want to start creating an application, just go to the developer page and start reading through the documentation on how to set up the development environment, how to program against the API, how to test your application and, finally, how to deploy it on an actual device.
The lifecycle of an activity for example can be found in the documentation.
Android.jar contains the Android API (Classes, interfaces, ..). If you want to see the rest, download the source from Android Git repository or via SDK Manager.