How to create NotificationManager Policy correctly? - android

I am facing a problem with the NotificationManager Policy.
Let's say I just want to be interrupted by alarms. Then I specify that as the Category (NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS) but what values should I pass to create the Policy? I am talking about the priorityCallSenders, and the priorityMessageSenders. No calls and no messages are allowed, only alarms, so why should I have to specify a value for them?
The available values are:
PRIORITY_SENDERS_ANY
PRIORITY_SENDERS_CONTACTS
PRIORITY_SENDERS_STARRED
Which one should I use? The code results messy and confusing if I specify I want only alarms BUT then use the constant PRIORITY_SENDERS_ANY.
For you to remember, here I paste the call to create the Policy:
myPolicy = new NotificationManager.Policy(NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS, iCallsPrioritySenders, iMessagesPrioritySenders);
myNotificationManager.setNotificationPolicy(myPolicy);
On the other had, and I suspect that the issue might come from here, I am not able to set this values correctly in Xiaomi.
I have tried in Huawei and Android Emulator setting a value like this (even when it is not allowed by Android documentation):
NotificationManager.Policy(NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS, -1, -1);
and it works well with both. But the problem is with Xiaomi. For some reason, calls/messages are always accepted and I am not able to disable calls. It looks like must be Any, Contacts or Starred.
Any light in this issue and the right values to pass?

Related

GAv4 for android: can deviceCategory value be overriden?

I need to manually override the value that Google analytics sends for the deviceCategory predefined user dimension (let's say that instead of "mobile", I need It to be "android phone"). But I couldn't find anywhere in the SDK documentation if this is possible or not, and how to do it, other than using a custom dimension, which is not what I want.
Is this even possible?
You can definitely override some of the default dimensions as shown here You could probably follow the same algo to override other dimensions.
Another thing I'd try is looking at the network request and seeing if deviceCategory can be overriden by setting it as an event propery.
Finally, you can always override any field if you use GTM inbetween, but it's kind of an overkill. You don't want to use it just to slightly shift the field value.
I would generally suggest either not touching it at all if you're just renaming it for the comfort of the analyst or using a custom dimension/event propery to track it if it's a separate datapoint.

Unable to increase the output volume

Tried endpoint.audDevManager().setOutputVolume(percentage), with values ranging between 100-1999. Unfortunately, it's not resulting in any increase in volume.
The documentation suggests that:
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps flags.
And I've already ensured that this flag is set. Is there anything else that I need to take care of?
Sauw Ming suggested (over mail) to use AudioMedia::adjustRxLevel(float level) instead, and that fixed the issue for values of level over 3.0. At least that's when there was perceivable difference in volume.
I also worked with endpoint.audDevManager().setOutputVolume(percentage) and it works after the call start.I got the change of volume.Also i used the range 1-100.Please check it with this settings.

Attach custom metric to HitBuilders.TransactionBuilder in Android Analytics v4

How can I attach a custom metric value to HitBuilders.TransactionBuilder in the following fashion? I want to associate a transaction with a value.
tracker.send(new HitBuilders.TransactionBuilder()
.setOtherAttributes(...)
.setCustomMetric(1, 10)
.build());
The rest of the data are successfully sent, but the custom metric is always 0.
It seems your code is correct. You can try to setCustomDimension instead of setCustomMetric, you only have to transform float to string.
Your code is correct. What you need to check is the server side reports you build.
Make sure you created a Custom metric in Admin - Custom Definitions - Custom metrics. Once created, custom metrics will initially appear with a 3 to 4 hours delay on the server. Give them some time to appear there. Finally, you need to create a report to see the result. Make sure you choose the right time intervals and don't add too many metric and filters, otherwise you won't see data. Make first reposts as simple as possible. I hope this helps.
The problem was with that the scope of the custom metric was not Hit and that I was looking at a custom report widget matched by Product. The value appeared when I changed the column.

How to get programmatically the data usage limit set by user on Android OS configuration?

User can define at Data Usage screen a limite and/or a warning limit for mobile data usage. So how can I get this information by code?
Screen of Data Usage configuration of native OS.
I wanna the limit value and warning value.
I've already tried this but not work and always return NULL to both:
final Long recommendedBytes = DownloadManager.getRecommendedMaxBytesOverMobile( this.context );
final Long maximumBytes = DownloadManager.getMaxBytesOverMobile( this.context );
// recommendedBytes and maximumBytes are NULL
And TrafficStats class just have a data transferred not the limits.
After days searching and research about this problem I couldn't find a answer for that. Bellow I will lift every attempt that I did.
1. Download Manager
With this class you can start download over any network or device
state and it will handle all states e.g. network loss, device reboot,
etc...
There are two methods called getMaxBytesOverMobile and
getRecommendedMaxBytesOverMobile, they was a pretty candidate
to solve this problem at first time. But after code tests and
Download Manager implementantion research I'd found that there is
no way to get thoose values by DownloadManager.
Reason
Thoose methods call Settings.Secure.getLong with they
respective labels
Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE and
Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE in
the turn makes a call to a lazy String map inside inside a
inner class called NameValueCache.
Ok so far but none of inner classes or Settings implementation it
self use DOWNLOAD_MAX_BYTES_OVER_MOBILE or
DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE inside.
I considered the lazy map was populate by a third entity, what
actually happens, so I found the NameValueTable Settings
inner class that handle the new values to lazy map. The
putString is a protected method call by Settings.Secure
and Settings.System inner classes (calls of Secure and
System).
So I could conclude that if the OS implementantion do not put thoose String values I can't get them.
2. TrafficStats
Just a quick look on official reference I could notice that it will
not help me because this class just provide the amount of bytes and
packages that was trafficked since last device boot.
http://developer.android.com/reference/android/net/TrafficStats.html
3. NetworkPolicyManager and NetworkPolicy
As #bina posted here the both classes are hidden and could not
be use by normal apps e.g. that will be published in Google Play.
https://stackoverflow.com/a/24445424/575643
4. ConnectivityManager
In short, you just can get the NetworkInfo that not provide
much information about user preferences (really none!). Just provide
informations about network and e.g. mobile network provider.
http://developer.android.com/reference/android/net/ConnectivityManager.html
After all I assume that no way to get this information nowadays. Please if you read it and found a way post here!
Thanks for all.
PS.: Sorry by english mistakes.
Do you want to get limit value(5GB) and warnning value(2GB) in this example?
If so, you can get limitBytes and warningBytes by the following code, if you can use android.permission.MANAGE_NETWORK_POLICY and android.permission.READ_PHONE_STATE.
However, android.permission.MANAGE_NETWORK_POLICY protectionLevel is signature.
NetworkPolicyManager manager = (NetworkPolicyManager) getSystemService("netpolicy");
NetworkPolicy[] networkPolicies = manager.getNetworkPolicies();
Log.d("NetworkPolicy", "limitBytes is " + networkPolicies[0].limitBytes);
Log.d("NetworkPolicy", "warningBytes is " + networkPolicies[0].warningBytes);
(NetworkPolicyManager and NetworkPolicy classes are hidden)

what is mean by "If two apps register ranges with the same id, they clobber eachother" in IBeacon Android

I just start with IBeacon. There is one is issue specified in IBeacon Android, "If two apps register ranges with the same id, they clobber eachother". I did not get perfect idea about this.
If anybody knows about this then please help me.
You don't need to worry about this. In theory, if two apps were sharing the same instance of the Android iBeacon Library, and they both passed the same unique id when defining their Region objects, the second app would overwrite the Region of the first app.
Because there is no easy way to make two apps use the same service instance, this is not a practical concern, except for very advanced users. I put this in the documentation for the library mostly as a note to myself to fix this in the future.
Example (don't do this):
// App 1
Region region1 = new Region("myUniqueId", "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0", 1, 2);
iBeaconManager.startMonitoringBeaconsInRegion(region1);
// App 2 - the startMonitoring call will actually alter the region1 definition above
// because the two Region objects have the same "myUniqueId" identifier
Region region2 = new Region("myUniqueId", "5A4BCFCE-174E-4BAC-A814-092E77F6B7E5", 3, 4);
iBeaconManager.startMonitoringBeaconsInRegion(region2);

Categories

Resources