Category Archives: android

Android 4.4 KitKat is out

Yesterday Android 4.4 KitKat was officially out and so is the ASOP for android-4.4_r1 (KRT16M) and so is the factory images for “hammerhead” for Nexus 5 (GSM/LTE) and so is the next API 19 SDK update.

Also there is the new JBQ:  Ed Heyl

here is link for android builders: https://groups.google.com/forum/#!topic/android-building/JVLaFRoJxFk

here is the changelog: http://web.djodjo.org/article/download/android/changelog/changelog_JLS36I-KRT16M

factory images and insecure boot image + deodex system can be found here: http://web.djodjo.org/article/download/android/ROM_images/factory-images-nexus5-hammerhead

detailed list of new features: http://developer.android.com/about/versions/kitkat.html

added razorg_4.3.1-JLS36I into the stock collection

for some time there has been an update for the new  Nexus 7 LTE and i just forgot to upload the images as usual.

changelog: http://web.djodjo.org/article/download/android/changelog/changelog_JSS15J-JLS36I

here it is with deodexed and insecure boot and adb: http://web.djodjo.org/article/download/android/ROM_images/factory_images_gn_razorg

New version of smali/baksmali and new download location

For a few weeks we have version 2.0 of smali/baksmali out of beta and ready for use. There is also a new download location for those.

Details about version 2 can be found here: https://code.google.com/p/smali/wiki/SmaliBaksmali20

Downloads are here: https://bitbucket.org/JesusFreke/smali/downloads

Http Clients in Android

When you come to use HTTP you may wonder which class to use to send and receive data.

There are 2 main

Options:

Which one to use?

Apache http clients are big and flexible implementations, however exactly because of this reason (complexity) they are not actively supported by Android team.

HttpURLConnection on the other hand is lighter and can serve the needs of most apps. It is also continuously improved by the Android team. Since Android 4.0 (Ice Cream Sandwich) it also  includes a response cache. This is quite handy however it is include from API 13 so to enabled it without impact earlier versions reflection can be used:

try {
           File httpCacheDir = new File(context.getCacheDir(), "http");
           long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
           Class.forName("android.net.http.HttpResponseCache")
                   .getMethod("install", File.class, long.class)
                   .invoke(null, httpCacheDir, httpCacheSize);
        catch (Exception httpResponseCacheNotAvailable) {
       }}

 Finally

As also stated in this post:

Apache HTTP client has fewer bugs on Eclair and Froyo. It is the best choice for these releases.

For Gingerbread and better, HttpURLConnection is the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. New applications should use HttpURLConnection; it is where we will be spending our energy going forward.

For more info on Http check http://web.djodjo.org/article/articles/android_articles/dev/web-and-services/http_access

Factory Images “razorg” for Nexus 7 [2013] (LTE)

The factory images for the new Nexus 7 (razorg) Android 4.3 (JLS36C) are out!

Official download link images(razorg): https://developers.google.com/android/nexus/images#razorg

… and binaries(deb): https://developers.google.com/android/nexus/drivers#razorg

Another download option + insecure boot image and deodexed system is here:

http://web.djodjo.org/article/download/android/ROM_images/factory_images_gn_razorg

Activity Layout Fragment attribute class: vs android:name

In case you wonder whether to use:

<fragment class="myapp.MyFragment" ..

or

<fragment android:name="myapp.MyFragment" ..

Well it doesn’t really matter. You can use both.

Lets see why in Activity.onCreateView source:

String fname = attrs.getAttributeValue(null, "class");
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
if (fname == null) {
    fname = a.getString(com.android.internal.R.styleable.Fragment_name);
}

So it seems it first checks for ‘class’ and if not there then for ‘android:name’.

SQLite and datetime notes

In SQLite3 there is no such datatype as DateTime or Date or Time. As noted here:

SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

  • TEXT as ISO8601 strings (“YYYY-MM-DD HH:MM:SS.SSS”).
  • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

So a simple example:

1) To insert

insert into sometable values( null, datetime('now') );

which will save smth like: 2013-09-08 19:41:16

or

insert into sometable values( null, strftime('%s', 'now'));

which will save the UNIX time in seconds: 1378669277

Note that in Android for example you can use SQLiteDatabase.insert method and pass System.currentTimeMillis() in the ContentValues, however do not forget to trim the miliseconds.

2) To select

So depends how the date is saved you will get string or a number. I personnaly like to use the UNIX time and so save the date and integer type.

In that case simple:

select my_datetime from sometable

will return just numbers. It is useful when you need it for comparison or ordering but for the user it is better to get is as readable datetime string as:

select datetime(my_datetime, 'unixepoch') from sometable

 

Android unique device identifiers, serial number and ANDROID_ID

There has been some discussions about unique device identifiers in Android.

Basically there are 3 main options (starting from the least recommended):

MAC Address or TelephonyManager –  not recomended

The mac address from WiFi or Bluetooth, however this is the best option as some devices does not have the specific hardware(wifi or bt), or depending on its status (off/disabled) mac cannot be obtained.

ANDROID_ID (from API 3) – can change after system update

Settings.Secure.ANDROID_ID is

A 64-bit number (as a hex string) that is randomly generated on the device’s first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.)

Constant Value: “android_id”
It can be obtained grammatically using this:
Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)

 

Serial Number (from API 9) – recommended

android.os.Build.SERIAL  –

A hardware serial number, if available. Alphanumeric only, case-insensitive.

is the serial number you see in the DDMS view in Eclipse or from the command “adb devices”. This can be obtained pragmatically from

android.os.Build.SERIAL

Conclusion

Its simple if you do not care to identify hardware  but installation go for ANDROID_ID, otherwise use android.os.Build.SERIAL.

Example

Here is a simple example of serial number and ANDROID_ID before and after android update.

Executed command:

adb devices

Executed code:

Log.i("TEST","android.os.Build.SERIAL: " + android.os.Build.SERIAL);
Log.i("TEST","Settings.Secure.ANDROID_ID: " + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID));

On Build: jwr66v

command:

List of devices attached
0039f663df121556        device

code:

I/TAG(8122): android.os.Build.SERIAL: 0039f663df121556
I/TAG(8122): Settings.Secure.ANDROID_ID: 5b79c0300c556842

On Build: jwr66y

command:

List of devices attached
0039f663df121556        device

code:

I/TAG(2861): android.os.Build.SERIAL: 0039f663df121556
I/TAG(2861): Settings.Secure.ANDROID_ID: 3dcc3d9765e7f1db