what is REQUEST_CHECK_SETTING? - android

I'm following this doc: https://developer.android.com/training/location/change-location-settings.html
REQUEST_CHECK_SETTING isn't defined but used, and I can't find its value after doing several searchs, all I found is that : What is the value of REQUEST_CHECK_SETTINGS?
someone giving it a "random" value (provided link not working), can someone please tell me how to get the value? or am I supposed to define it myself?
Thank you.

REQUEST_CHECK_SETTING isn't defined but used
The "training" at the Android developer site routinely skips stuff.
can someone please tell me how to get the value? or am I supposed to define it myself?
You are supposed to define it yourself. startResolutionForResult() works like startActivityForResult(), requestPermissions(), and similar methods:
You supply an int to the call
You get that int in the callback (e.g., onActivityResult() for startActivityForResult()), to help you identify what call triggered the callback
In this sample app, I used a value of 61124 (defined there as REQUEST_RESOLUTION) in my startResolutionForResult() call.

Related

is onActivityResult fundamentally broken?

Some implementations of it, as well as seemingly some devices, seemingly never return RESULT_OK which equals -1, and just return a misleading 0 while including all the necessary data in the Intent extras
I've seen a lot of Google example code simply not do a condition on the resultCode anymore, but they can deprecate it without breaking anything, given Google's propensity to deprecate completely non functional methods because they like their new name more, they could overload a new onActivityResult to simply not have the resultCode as a method parameter.
I was wondering if there is a technical explanation or a blog post for what that particular message passing protocol has seemed to simply fail, without any update in the documentation saying "hey maybe don't rely on the resultCode following any rhyme or reason"
The result code value is a contract defined by the specific activity's implementation. The only contract defined by Android proper is that the result code is an integer.
Android defined simple constants for success (RESULT_OK) and fail (RESULT_CANCEL), but it's up to the activity to decide if it wants to use those, for what purpose, to use different values, or to not even set a result code (in which case the default is RESULT_CANCEL). In many cases, a simple success or fail isn't complete enough and activities return other int values.
So, the short answer is you need to consult the source of the activity to see what it does (or the documentation, but the contract is unlikely to be defined there).

DataUsage by a single API/webservice call

I need to find how much data is consumed by single webservice/API call. I have searched a lot and found this:
commonsguy/cw-andtuning
How can I find the data usage on a per-application basis on Android?
But these gives me DataUsage of whole application, i want to find it for single API/webservice call.
THere is no built in way to do that. You'd need to do it yourself, by adding the size of the data returned each time you call it.
If you execute one API call at the time, then you might look into android.net.TrafficStats. Inside it, there is a method android.net.TrafficStats#getUidTxPackets(int uid) and android.net.TrafficStats#getUidRxPackets(int uid). You might obtain your application uid from android.content.pm.ApplicationInfo#uid.
Get the value before a call, then get it once again after a call, and count the difference.
However, be advised:
Before android.os.Build.VERSION_CODES#JELLY_BEAN_MR2, this may return UNSUPPORTED

Xposed module for whatsapp implement last seen tweaks

I've developed an xposed module for whatsapp.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
I wanted to add feature to hide our own last seen still see others or report a fake last seen for eg: 1 Jan 1970.
I made following assumptions:
To do that first I hooked date and System.currentTimeInMillis methods to make whatsapp think its 1 Jan 1970. That worked but still last seen was shown perfectly.
Assumption: The last seen time value is directly taken from the server
Then I looked in the source to find where last_seen preference is referenced. Turns out it is only referenced in SettingsPrivacy activity's class.
Assumption: To hide our last seen and still see others we need to change last seen preference to 'visible to all' and turn that back to off once we get the last seen.
but the problem is it uses onPreferenceChangeListener. We cannot hook a method from the interface directly.
I cannot find the subclass which implements onPreferenceChangeListener as the classes shown in code are synthetic.
Please if anyone can help me with this, it will be great. I need to find which is preferencechangelistener for that preference. Rest I will manage.
This is kind of a brute force trick to get the implementation but I guess you can hook the app ClassLoader.loadClass and for each loaded class check if it implements the interface. If so hook its onPreferenceChangeListener.
I found a way to do it and its working.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
The way to do it is by hooking a method which takes a preference as argument. We create a preference ( com.whatsapp.preference.WAprivacy preference to be precise ) and then pass this preference with last seen set to desired value to the method. And we are done.
It is working so far.

what should callerContext param be for Fresco's prefetchToBitmapCache?

In order to implement image pre-fetching, we get the ImagePipeline and call prefetchToBitmapCache on it. however, both the API Javadoc (http://frescolib.org/javadoc/reference/com/facebook/imagepipeline/core/ImagePipeline.html#prefetchToBitmapCache(com.facebook.imagepipeline.request.ImageRequest, java.lang.Object) and the plain doc (http://frescolib.org/docs/using-image-pipeline.html#) are incorrect. specifically , they leave out the description and example for what the second method parameter is. I am talking about the Object callerContext . which since its an object isn't an android Context. I'm guessing that because the type is an object, not a Context. Could the documentation be updated and/or someone explain what the caller context is supposed to be?
Thank you!
So I posted this question a while back on the fresco github (https://github.com/facebook/fresco/issues/609) and I was told the documentation would be updated. I'm posting my results here since it is likely others might look here. I still haven't seen any updates to frescolib.org or anywhere else. I decided to figure it out myself. Basically, if you're using SimpleDraweeView and its respective ImageRequest (which the prefetch call needs) , then you would notice that setting the uri on the view creates a DraweeController with a null callerContext. I figured that might be what is needed here. Sure enough, I made the call to prefetchToBitmapCache(draweeController, null) and its prefetched! I know that because I waited for a bit and turned off the data. also this call was only active on a select imageview. the other did not load. I can't be sure this is the right way to do it, ntil they come out with the right documentation. but like i said it works.

difference between intent.setClass() and intent.setComponent()

I am looking at a tutorial and see the author using intent.setClass() to get the to the next Activity and then on the same page he uses intent.setComponent() to get to the next Activity.
So what is the difference and what is the advantage in using any of them?
Other than different parameters.
intent.setcomponent() = Explicitly set the component to do the handling of the intent.
intent.setClass() = Convenience for calling setComponent(ComponentName) with the name returned by a Class object.
another difference is that .setComponent() can find the appropiate class for you.
*From android Developers*
SetComponent Android Dev
You should only set this value when you know you absolutely want a specific class to be used; otherwise it is better to let the system find the appropriate class so that you will respect the installed applications and user preferences.

Categories

Resources