How to create TelephonyDisplayInfo object in android R device - android

I want to get getOverrideNetworkType() in android Like as Android CA 5G NSA NR but Enable to Create TelephonyDisplayInfo object to get this. I am using this code but get
TelephonyDisplayInfo mTelephonyDisplayInfo;
mTelephonyDisplayInfo = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
but get error:-
TelephonyDisplayInfo() is not public in android.telephony.TelephonyDisplayInfo. Cannot be accessed from outside package this error.

Comment from Google support:
Although the constructor is public, it's #hide and not a part of the
API surface, so it shouldn't be accessible to developers. To get the
TelephonyDisplayInfo, please use
PhoneStateListener#onDisplayInfoChanged instead. Closing this as
working as intended.

Related

Android 7.0/API24: How to check for notification access (Settings.Secure.enabled_notification_listeners)

In Android 6.0/API23 and earlier, the following used to work:
String settingEnabled = android.provider.Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners");
In Android 7.0 Nougat/API24 this seems to be no longer supported, because the code above returns null.
It actually was never mentioned here: https://developer.android.com/reference/android/provider/Settings.Secure.html
How do we check if our app has notification access in Android 7.0 Nougat API24?
Edit: It seems that actually that after you first gained the access in the settings, the code above returns the correct state. But not on the initial request after installation.
Use this:
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages (context);

invoking createDisplay on android.view.SurfaceControl using reflection returns null

I am trying to call createDisplay method on android.view.SurfaceControl using reflection but it is returning null on Marshmallow device. I Don't know why.
The reason to do is to create virtualdisplay without using MediaProjection API.
Following is the code.
Class surfaceControlClass = Class.forName("android.view.SurfaceControl");
Class cls = surfaceControlClass;
IBinder token = (IBinder) cls.getDeclaredMethod("createDisplay", new Class[]{String.class, Boolean.TYPE}).invoke(null, new Object[]{name, Boolean.valueOf(false)});
You need System Permission(android.permission.ACCESS_SURFACE_FLINGER) to do that, check your LogCat and you will find permission warning.
Actually you can't make it work unless you have the Platform Signature of your device.
But you can test it on emulator using the default AOSP signature.

make getSystemService() recognize our new system service

I'm using the book "Embedded Android".
I'm making a new System Service using AOSP(4.0.3_r1).
I want my system service to be registered in frameworks/base/core/java/android/content/app/ContextImpl.java so that I can use it through getSystemService() method.
The problem is, I can't find the app folder under content:androidroot/frameworks/base/core/java/android/content/app/ContextImpl.java
But, I found it in:androidroot/frameworks/base/core/java/android/app/ContextImpl.java
Are these 2 files the same? or is it just missing(the content/app folder)?
Any idea on what to do?
Karim wrote his book mostly orienting on Android 2.3.4 version. Something can be changed from this time. This is an example what has been changed.
Are these 2 files the same? or is it just missing(the content/app folder)?
These are the same files.
Any idea on what to do?
As I said the implementation has been changed. I looked into the code and here what you can change to make your code working (I can only suppose because I did not actually build my code). In the static block of ContextImpl class you need to add the following code:
registerService(ACCOUNT_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(OPERSYS_SERVICE);
IOpersysService service = IOpersysService.Stub.asInterface(b);
return new OpersysManager(service);
}});
You need to use SystemServer which holds all system services' names.
You should check this link out:
http://processors.wiki.ti.com/index.php/Android-Adding_SystemService

How to get the crash info from ApplicationErrorReport class?

Android ICS (api 14) introduced the ApplicationErrorReport class with the following info:
CrashInfo BatteryInfo and ANRInfo. From the class overview it seems that this class refers to all application installed on the device and not for debugging your own personal application.
I cannot seem to reach that information (simulated crashes and anr's)
I tried this code:
ApplicationErrorReport appp = new ApplicationErrorReport();
CrashInfo test = appp.crashInfo;
Log.i(test.stackTrace);
but i get that test is null
How to get the crash information?
In the ApplicationErrorReport API it says:
ApplicationErrorReport()
Create an uninitialized instance of ApplicationErrorReport.
This means that the "type" of error is undefined, so it's not a crash report and therefore the crashinfo is null.
EDIT:
I took a look at the source code. You can instantiate the CrashInfo part via the method readFromParcel(in) where the first int in the parcel is the int corresponding to ApplicationErrorReport.TYPE_CRASH. Alternatively you can create a CrashInfo object yourself and assign it to the ApplicationErrorReport, but this again requires a parcel if you want to CrashInfo data to be filled.
I tried looking for code where it is used, but the only thing I could find is the ApplicationManagerNative (also using parcels).
case HANDLE_APPLICATION_CRASH_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
IBinder app = data.readStrongBinder();
ApplicationErrorReport.CrashInfo ci = new ApplicationErrorReport.CrashInfo(data);
handleApplicationCrash(app, ci);
reply.writeNoException();
return true;
})

Flickr API on Android?

I want to use Flickr API for downloading the images on Android Phone, can any one give or tell, me about the working sample of Flickr API on Andorid.
I have add the flickr.jar as the external library, and i have the "Key"and "Secret" but i do not know how to download the images.
All it takes is just 3 steps and you will have it implemented.
Step 1: Find your user id.
The easiest way is to use this service http://idgettr.com/
Step 2: Acquire you flickr api key
Just log-in to you account and click this link http://www.flickr.com/services/api/misc.api_keys.html
Step 3: Get the code from the example project from our blog
http://www.quintostdio.com/blog/archives/1117
Add you user id and api key on the FlickrActivity class (in the package com.quintostdio.test.flickr.ui) and run the example. You can copy paste the classes and add it to your project, with no more changes and it will work.
Hi I have built a Flickr Java library for Android: http://code.google.com/p/flickrj-android/
You'll need to look in their documentation on the Flickr site. Most likely will use the Java library and import it into your Android project.
Probably have to instantiate an object, using the Key and Secret. Once you have a valid authentication object, you'll use a provided method (from the docs) to get a picture.
Have a look here: http://www.flickr.com/services/api/
#Todd DeLand answer is pretty accurate even nowadays.
However, I'll speed you up the search and tell you that the flickrj-android is not anymore up to date, as you can check in the Downloads page https://code.google.com/archive/p/flickrj-android/downloads
The other project that is listed in the Flickr API page ( http://www.flickr.com/services/api/ ), Flickr4Java, it's definitely working nowadays since I just tested it today and so far is doing it's job pretty nicely.
Github repo: https://github.com/boncey/Flickr4Java
Gradle config to add in your project (be careful, since in the README it appears another Gradle configuration, which is for the project that Flickr4Java is based on, and is NOT working):
implementation "com.flickr4java:flickr4java:2.17"
As of today, Flickr4Java was last updated on Nov 11, 2017, which is not bad.
This is an example of how I sent a query to get the pictures around a certain location (latitude,longitude):
Thread thread = new Thread(new Runnable() {
#Override
public void run() {
try {
String apiKey = "MY_API_KEY";
String sharedSecret = "MI_API_SECRET";
REST rest = new REST();
Flickr flickrClient = new Flickr(apiKey, sharedSecret, rest);
SearchParameters searchParameters = new SearchParameters();
searchParameters.setLatitude(exampleLatitude);
searchParameters.setLongitude(exampleLongitude);
searchParameters.setRadius(3); // Km around the given location where to search pictures
PhotoList photos = flickrClient.getPhotosInterface().search(searchParameters,5,1);
} catch (Exception ex) {
Log.d(MapApplication.LOG_TAG, ex.getLocalizedMessage());
}
}
});
thread.start();
I would avoid flickr4java. I assumed it worked at first but after incorporating it in to my project I have found that it crashes the app intermittently. very annoying and has been a big waste of time :(. probably works fine under other java apps but does not seem to play well with android :(

Categories

Resources