Convert time in long to specific date format – SimpleDateFormat in action!

Here is that pretty snippet for converting long to specific date format:

public static String getDate(long milliSeconds, String dateFormat)
{
// Create a DateFormatter object for displaying date in specified format.
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
// Create a calendar object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}

I took source from: http://stackoverflow.com/a/7954038/619673

Continue reading “Convert time in long to specific date format – SimpleDateFormat in action!”

How to run an android application using .apk file?

Here is the example how to run apk when you do not know what is the apk’s name.

First you need to call aapt to get info about AndroidManifest.xml from interesting apk. I will show you example on WifiKillDOwnloader.apk
In console you call:

aapt d xmltree WiFiKillDownloader.apk AndroidManifest.xml > manifest.txt

Console will output this:

Continue reading “How to run an android application using .apk file?”

adb command – reboot in specific device

First we need to know what devices we have by running command in console:
adb devices
[spoiler title=”Output”]

List of devices attached
01e010f522900141        device
192.168.56.102:5555     device

[/spoiler]

Or we can use with param -l for additional description.
adb devices -l
[spoiler title=”Output”]

List of devices attached
01e010f522900141       device product:occam model:Nexus_4 device:mako
192.168.56.102:5555    device product:vbox86tp model:Google_Nexus_7_2013___5_0_0___API_21___1200x1920 device:vbox86tp

[/spoiler]

And then when we know the specific address of our device, we can call to it our command for example:
adb -s 192.168.56.102:5555 reboot

Hackathon in Connectmedica, Warsaw

Connectmedica Hackathon – Have fun, making apps, meet amazing people
Saturday, February 7, 2015

This will be (afik) the second hackathon in Connectmedica, Warsaw, Poland.
Last time I was having great time and the atmosphere was insane!

Organisers offer:

great fun , meeting interesting people, competitions , prizes and free eat and energetics drinks

It is worth to go and at least just to checkout what’s going on.
Happy coding there!

More info here

Working example POST in android

Here is another short (IMHO) example how to post in android app.

private void postSms(String text) {
URL url;
HttpURLConnection urlConnection = null;

try {
url = new URL("http://yourserver.com/sendsms");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sms", text));//POST param as "sms"

OutputStream os = urlConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(params));
writer.flush();
writer.close();
os.close();

String status = new String(Streams.getBytes(urlConnection.getInputStream()));
Log.d(TAG, new Exception().getStackTrace()[0].getMethodName() + ":insert status=" + status);

} catch (MalformedURLException | ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

This is a method for concatenating parameters for POST

Continue reading “Working example POST in android”