Android How to calculate network usage packet/data - java

Now a days Internet access is very costly.The provider used charges like hell.
We do not use unlimited plan for internet.That's why I would like to develop an that can facilities to calculate(manage) network package/data usage.
Suppose I have activated 5GB data plan.So I need to check before surfing net,upload/download things.
I know some Data provider provides these facility .I want to capture network data packets on my android device by my app. But How can I do that into my own code.
Any help will be appreciated.
Thank you advance

Please check that.
TextView infoView = (TextView)findViewById(R.id.traffic_info);
String info = "";
info += "Mobile Interface:\n";
info += ("\tReceived: " + TrafficStats.getMobileRxBytes() + " bytes / " + TrafficStats.getMobileRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getMobileTxBytes() + " bytes / " + TrafficStats.getMobileTxPackets() + " packets\n");
info += "All Network Interface:\n";
info += ("\tReceived: " + TrafficStats.getTotalRxBytes() + " bytes / " + TrafficStats.getTotalRxPackets() + " packets\n");
info += ("\tTransmitted: " + TrafficStats.getTotalTxBytes() + " bytes / " + TrafficStats.getTotalTxPackets() + " packets\n");
infoView.setText(info);

Use TrafficStats class starting in APILevel 8.
You get overall usage per radio access technology and per app.
See http://developer.android.com/reference/android/net/TrafficStats.html
It's all static methods, for example call TrafficStats.getMobileRxBytes()

Related

How to get a proper restaurant bill setText?

this is the code I used for the restaurant bill. I want the outcome like a real recipe, but the problem is the text I get is next to each other instead of underneath. This is the outcome..
Can someone help me with this?
BonField.setText("\tKassabon\n" +
"Klantnummer:" + klant +
"\n=================================================================\t " +
"\n======================================================\t " +
"\nBtw 6%:\t\t\t\t\t" + BTW +
"\nSub Totaal:\t\t\t\t\t" + SubTotaal +
"\nTotaal bedrag:\t\t\t\t\t" + Totaal +
"\nContant betaald:\t\t\t\t\t" + Totaal +
"\n======================================================\t " +
"\nDatum: " + Tdate.format(timer.getTime()) +
"\t\tTijd: " + tTime.format(timer.getTime()) +
"\n\n\tBedankt voor uw bezoek, graag tot ziens\n" );
First things first: Never format your textbox or any other visual element by it content directly in final builds of your applications. Although it is understandable for debug usage and stuff, you'll probably need to handle auto adjustment things within final builds.
Secondly: Too few info to help you, bro. Think and express properly when asking questions or you'll keep having your questions underrated.
Good luck with your work!

Consecutive log prints - only the first printed (no visible error)

I have this code fragment in my java class:
catch (AuthenticationFailedException afe) {
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + "E-Mail " + protocol + encStr + " login failed on " + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer());
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + afe.getMessage());
IlientConf.logger.debug("Email integration AuthenticationFailedException", afe);
return false;
}
IlientConf.logger is a log4j logger.
The actual log that is printed contains only the first line. This is it:
[someuser,sapunlock#someuser.com#outlook.office365.com] E-Mail pop3
(SSL) login failed on sapunlock#someuser.com#outlook.office365.com
The second and the third log statements are lost somehow.
I really need the stack trace of the error, but I can't get it.
No other related error is shown in the log.
Please help me understand what the reason for this is.
P.S.: Of course I can change the log statements to show this better, but this is deployed at a customers environment and needs to be solved before the next version.

Sending Calendar Events (Invitations) using iCal4j library (Java - Spring)

This question is relating to iCal4j library integration with a Java (Spring) application.
Use case -
In my application, when a user creates an event from the UI, the invitees should receive a calendar invitation, which they can add to their personal calendar (Google calendar, Outlook calendar or even Thundarbird calendar) by simply clicking on the event. Also, the event organizer should receive a calendar invitation of the same event.
Concern -
While attendees receive the calendar invitation to the created event in the correct format (Google Calendar, Outlook and Thundarbird) via an email, the organizer receives an empty email with an attachment (invite.ics). Please note that this concern only raises in Gmail mail and Outlook mail clients. In Thunderbird, even the organizer receives a complete event request.
(Please refer the attached code snippet and images for further clarification).
Please let me know how to resolve this issue or any alternate libraries or solutions I can use to get this done.
Thanks in advance.
StringBuffer buffer = sb.append( "BEGIN:VCALENDAR\n" +
"PRODID:-//PROD_NAME//PROD_ORG//EN\n" +
"VERSION:2.0\n" +
"X-WR-RELCALID:"+calendarEmail.getxWrRelcalid()+"\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
calendarEmail.getAttendeeString() +
calendarEmail.getOrganizerString() +
"DTSTART:" + calendarEmail.getDtStart() + "\n" +
calendarEmail.getRruleString() +
"DTEND:" + calendarEmail.getDtEnd() + "\n" +
"LOCATION:" + calendarEmail.getLocation() + "\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:"+calendarEmail.getSequence()+"\n" +
"UID:" + calendarEmail.getUid() + "\n" +
"DTSTAMP:" + calendarEmail.getDtStamp() + "\n" +
"STATUS:"+calendarEmail.getEventStatusString()+"\n" +
"CATEGORIES:" + calendarEmail.getCategory() + "\n" +
"DESCRIPTION:" + calendarEmail.getDescription() + "\n" +
"SUMMARY:" + calendarEmail.getSummary() + "\n" +
"PRIORITY:5\n" +
"CLASS:" + calendarEmail.getPublicity() + "\n" +
"BEGIN:VALARM\n" +
"TRIGGER:" + calendarEmail.getAlarmTrigger() + "\n" +
"ACTION:" + calendarEmail.getAlarmAction() + "\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR" );
I think this is more a question of how the iCalendar specification works. Specifically you may want to look at:
https://www.rfc-editor.org/rfc/rfc5546#section-3.2.2
In your case your program is acting on behalf of the Organizer, so I'm not sure you can send a "REQUEST" to the Organizer user.
You probably need to send a "PUBLISH" method to the Organizer user:
https://www.rfc-editor.org/rfc/rfc5546#section-3.2.1
You may also want to consider the SENT-BY parameter on your Organizer property to indicate the Organizer user didn't send the request (unless you want REPLYs to go back to your program):
https://www.rfc-editor.org/rfc/rfc5545#section-3.2.18

GWT Java calculate days between two dates on the server side

I am using GWT java. I have a report on the client side that I want to export to csv. So I am trying to create the report on the server side to pass back to the client side as a csv file so the user can store the csv file in their selected destination.
The following code works on the client side; however, does not work on the server side (i.e., "Print 6." is displayed and "Print 7." is not displayed on the server side). There is no error message. The dates are "2016-11-09" and "2000-02-02".
System.out.println(todays_date);
System.out.println(pack.getDob());
System.out.println("Print 6.");
float diffDOB = (CalendarUtil.getDaysBetween(pack.getDob(), todays_date));
System.out.println("Print 7.");
I was talking about this with a fiend, who is not a programmer, and she said why not just send the MS Excel formula. Brilliant! So I have removed all the calclations and am now sending:
fileContent.append(pack.getSurname() + "," + pack.getFirstname() + "," + pack.getScout_no() + "," +
pack.getgroup() + "," + pack.getDob() + "," + '"' + "=ROUNDDOWN(((TODAY()-E"+row+")/365),1)" + '"' + "," +
pack.getstartDate() + "," + '"' + "=ROUNDDOWN(((TODAY()-G"+row+")/365),1)" + '"' + "," +
'"' + "=EDATE(E"+row+",216)" + '"' + "\n");
The only issue now is that spaces in the string fields appear as + in the output file.

Processing pagination in LinkedIn API

I'm trying to retrieve all of my network updates using the linkedin-j API. I can fetch the first 10 updates, but do not know how to retrieve any more.
The following code retrieves the first 10 updates:
Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.STATUS_UPDATE));
System.out.println("Total updates fetched:" + network.getUpdates().getTotal());
for (Update update : network.getUpdates().getUpdateList()) {
System.out.println("-------------------------------");
System.out.println(update.getUpdateKey() + ":" + update.getUpdateContent().getPerson().getFirstName() + " " + update.getUpdateContent().getPerson().getLastName() + "->" + update.getUpdateContent().getPerson().getCurrentStatus());
if (update.getUpdateComments() != null) {
System.out.println("Total comments fetched:" + update.getUpdateComments().getTotal());
for (UpdateComment comment : update.getUpdateComments().getUpdateCommentList()) {
System.out.println(comment.getPerson().getFirstName() + " " + comment.getPerson().getLastName() + "->" + comment.getComment());
}
}
}
There is another method called network.getUpdates().getStart(), but I don't know how to implement it. I've been at this for hours, and any advice would be appreciated.
If you would like to use pagination in linkedin-j, then you could use getNetworkUpdates(Set, int, int) along with network.getUpdates().getTotal().
public Network getNetworkUpdates(Set<NetworkUpdateType> updateTypes, int start, int count);

Categories

Resources