The question is pretty straight forward, How do I find out how much mobile data (in GB or MB) has the user used in the current month?
As it has been reported as off topic, I want to clarify that the data usage is supposed to be checked via code in an app.
Is there some code I can use to check for the users used data?
See: https://developer.android.com/reference/android/net/TrafficStats.html
Try:
Toast.makeText(this, android.net.TrafficStats.getMobileRxBytes()+"Bytes", Toast.LENGTH_SHORT).show();
getMobileRxBytes() Return number of bytes received across mobile networks since device boot.
Related
I'm using Connectivity library to see the internet(Wifi or network data) is active and saving the data in Storage if there is no connectivity(Offline) and synchronize with server when connected to internet. I'm having issues in public places where the internet is consistently unstable(esp. in basements, offices, stores, Coffee shops etc., where there is internet connects in and out). When I check the Connectivity is active but by the time I started synchronizing internet goes offline (Something like this). this leads inconsistent /partial updates to the server. Also, in coffee shops and Airports where wifi gets connected but there will be "Agree Terms and Conditions" page to connect. Not all the browsers will take you to that page directly after joining the Wifi. In that case I see the wifi is active in Mobile but actually it is not activated until I accept the terms and Conditions in IE or some specific browser. Any one else having difficulty in handling these kind of issue from Mobile App?
My App - Hangs on Login screen if I'm trying to login when there is in-stable/in consistent internet.It thinks wifi is there but not.
IF I'm on a screen where I will display list, screen will show blank for infinite time. Adding timeout for server request/response or something will help such scenario.
I know I'm not handling this case in code to show some kind of error message but I need some guidance to detect these conditions suing CN1 API to handle through my app.Please advise.
Code:
public boolean isOffline() {
if (Connectivity.isConnected() && forceOffline) {
relogin();
}
return forceOffline || !Connectivity.isConnected();
}
The problem is that it's impossible to detect online/offline properly as you might be connected to a local wifi/network but it might be a bad connection that won't let you reach the server. As far as the library is concerned you are connected... But in reality you don't have a connection.
First set the timeout values in NetworkManager to lower values to improve the experience although this won't solve a situation where data starts downloading and stops in the middle.
Next you need to handle these cases one by one and provide the user with a way to toggle the offline mode. Unfortunately there is no silver bullet for network reliability. You just need to go through every path and try to detect these things.
I have an Arduino and an Android app which are communicating to each other via ethernet. The arduino shows a very simple webpage with only some values and an ID as seen below.
$1$201 //Value 1 ($1$): Temperature 20.1 degrees
$2$66 //Value 1 ($2$): Humidity 66%
$2$1 //Value 2 ($2$): Heating relay is on (1)
etc. up to 50 values
The Android app will read the data from this webpage as a string using a HTTP get request, filters the data and shows the values on a custom made screen. It is also possible to send some data to the arduino to change some settings or switch a relay or something. You can see is as some kind of thermostat. So far so good.
The "problem" is that I need to manualy update the data using a button. The question is: How can I update my values automatically?
I was thinking to just send a httpRequest every few seconds (polling), but I'm not sure if this is the way to go because it seems to use of lot of data.
Who can advise me what would be a good solution?
Regards,
Bas
The 'best' choice here will depend on your goals. Polling is easy to implement on the client (android) side. You could experiment with the optimal polling time depending on how 'fresh' your data needs to be compared to how much data you want your app to use. Alternatively, you could find or implement an http socket server such as ArduinoWebsocketServer, keeping in mind that the processor in your Arduino may or may not have the power needed to run this.
Does anybody know what is the limit of sent SMS messages at once? Or it is limited hourly or daily?
I have Nexus 4 (4.4.4 KitKat). I am developing app that sends SMS messages so it is really important to me. I've found a lot of information but it seems none of it is correctly...
Thanks!
According to the creator of this app https://play.google.com/store/apps/details?id=com.bamf.smslimittool.donate&hl=en, the limit, since 4.4.1, is 30 messages in 30 minutes.
It also notes that the limit is present to safeguard against malicous programs, so setting it very high is potentially a bad idea.
In CM11,
Open your Root Explorer.
Go in /data/data/com.android.providers.settings/databases/
Open settings.db your SQL editor
Open the database ‘Global’
Press the Menu button> New Record / New Table
As set name: sms_outgoing_check_max_count
As value (value) type the maximum number of sms you want, personally I put 2000
Taken from http://www.openeducationus.com/?p=101682
Some limit was introduced not later than Gingerbread. As far as I know, and I investigated thoroughly, it is generally impossible to override these limits on non-rooted devices. If possible, those are rare exceptions. But, if your app is supposed to send messages from your device only or from controlled number of devices, you may get around this problem by setting SMS_OUTGOING_CHECK_MAX_COUNT to a huge number (say 99999) in:
/data/data/com.android.providers.settings/databases/settings.db
table secure
table system
/data/data/com.google.android.gsf/databases/gservices.db
table main
I dont think it has got anything to do with Android. In India, it is governed by TRAI Regulations for SMS.
And the limit varies based on whether it is transactional SMS, promotional SMS or personal SMS
*TRAI : Telecom Regulatory Authority of India
I'm currently working on an application where the code uses the device IMEI number as a variable to store something in the DB. We need to see what device the reading originated from.
ie:
String IMEI = telephonyManager.getDeviceId();
However, I'm not sure how this will behave on phones without network access, such as a wifi only tablet. Will is return a unique value? Will it return null?
I know there are alternatives to using IMEI, and I don't need any explanation on what alternative values I can use. I only need to know what will happen when I call this on a phone with no network access. Please do not provide suggestions on alternative IDs or anything other than what I have asked. I appreciate you taking the time to read this question.
Thanks,
-Mark
You get null.
Just ran into this on an app I wrote 3 years ago, and only just converted to tablet format. I had forgotten we were using IMEI (against the advice you and I both received ;-) ) and we started sending a whole bunch of null device IDs to the server.
Sadly it took a whole lot of network logs before I tracked it down to that little hack.
Android provides the following method to determine the network operator:
http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperatorName()
However even the documentation specifically says:
Returns the alphabetic name of current registered operator.
Availability: Only when user is registered to a network. Result may be unreliable on CDMA networks (use getPhoneType() to determine if on a CDMA network).
The problem is that we need a reliable way to detect the carrier so we can identify the traffic source. Has anyone had a similar problem and if so, what is the best solution?
My phone is on Verizon Wireless. On a daily basis, I drive through areas where my phone is roaming and/or has poor reception. Using scripting layer for android, I will log the results of calling getOperatorName() once every ten minutes over the next week.
There is another method that might work in the android.telephony.cdma api. The documentation there is missing the reliability disclaimer. You would only get a Network ID instead of a name. Unfortunately, this requires API level 5 instead of 1 if that matters to you.
Logging the results of the getOperatorName() method yielded nothing special. When I had no service it consistently returned null and when I had service it consistently returned "Verizon Wireless." I'm sure that's not very helpful.
Edit: Addition and correction.
Added - Explanation of link
Corrected - API level 5 not 17
Edit 2: Test results
I am currently looking for a solution for this problem as well. According to this thread one could use CdmaCellLocation.getNetworkId and CdmaCellLocation.getSystemId. Since there are no CDMA networks in Germany, I am unable to check if this works...
You think maybe this was one precurser to Google pulling cdma support? Play within the frameworks or find you another playground is what I hear Google saying. Well that and the fact that carrier apps burned into roms have at times left gaping holes in security.
As to a possible answer to your question... from where are you able to pull info? APN settings might tell you or an assert to a known carrier line in build.prop could pull the info I might need for example. (I do the hobby roms). Then again if you physically inspect a phone, the carrier is usually branded ;) From what vantage are you pulling the info?
Rob