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.
Related
KeyboardView has been deprecated official by android team in API level 29 and i didn't able to find the alternative way for this. Please let me know if there any alternative?
The only solution Google suggests is copying KeyboardView.java and Keyboard.java files to your local project from Android AOSP. With some customization I managed to make it work as old deprecated KeyboardView and Keyboard Android's classes.
You will also have your local copy of com.android.internal.R attributes (stylable) from from here
You can notice, it is annotated as
<!-- {#deprecated Copy this definition into your own application project.} -->
Google:
This class was deprecated in API level 29. This class is deprecated
because this is just a convenient UI widget class that application
developers can re-implement on top of existing public APIs. If you
have already depended on this class, consider copying the
implementation from AOSP into your project or re-implementing a
similar widget by yourselves
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.
I am writing my own SDK on android and as such creating my own jar.
Now I create documentation of my SDK using droiddoc tool.
In my framework files(.java), there are many APIs that I have marked with #hide
Now this is the current state:
a) all APIs marked with #hide are hidden in documentation.
b) These APIs marked hidden is INCLUDED in class files in generated jar file.(I use Java decompiler to check this).
Now when I include this jar in eclipse and use Ctrl+space on my class object to find its options, i can see that hidden APIs are actually visible and accessible here.
Am I missing anything here, and do I need to add any special flags in make file? Or is this a normal behaviour?
I found out that:
android.jar has all classes from com.android.internal removed, and all
classes, enums, fields and methods marked with #hide removed as well
So the classes with #hide are not included on jar -> that's why they are not accessible in eclipse.
Furthermore:
When you launch your application on device it loads framework.jar
(roughly this is equivalent of android.jar on the device) which is
uncut and has all the internal API classes and all hidden API
components.
Have a look over this post and this answer
Hope you find an alternative solution for hiding things
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.
It's weird I found PackageManager has public APIs like installPackage(...)/deletePackage(...) although in the comment it's marked as Hide, here http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/content/pm/PackageManager.java#PackageManager.deletePackage%28java.lang.String%2Candroid.content.pm.IPackageDeleteObserver%2Cint%29, but the reference page google provides hide this API.
So my question is how can I access such APIs?
Thank you all very much for help.
Kindest regards,
Nessus.
It was declared as public just to simplify the SDK developers life. But it never was expected to be called by outside developers. See also this post.
But if you really need to call this method, you can use reflection. Thought I suggest to look around for an alternative solution using official API.
In general you should not use "hidden" APIs in your applications. These methods are for internal usage and can be changed or even removed without notice. They are often not available for non-system applications due to permission restriction. If you want to use these APIs in your application then you may build your app within the platform build.
There is also a workaround to build application that uses hidden API in Eclipse: you can collect compiled framework libraries from the platform build and add them to build path as "User library", framework_intermediates/classes-full-debug.jar should be enough for the package manager.