Skip to content

Instantly share code, notes, and snippets.

@novoda
novoda / Android
Created April 21, 2010 23:03
Android: Enforcing a wakelock is sometimes necessary but should be used with caution as it will take it's toll on the battery.
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
public class DoNotDimScreen extends Activity {
private PowerManager.WakeLock wl;
@Override
@novoda
novoda / List music files
Created April 21, 2010 23:01
Android: List all music files
//Retrieve a list of Music files currently listed in the Media store DB via URI.
//Some audio may be explicitly marked as not being music
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
@novoda
novoda / Android: get IP Address
Created April 21, 2010 22:58
Android: Get the IP Address of the current device. In the latest versions of Android on the trunk this built into the platform so you will probably be able to just call an intent.
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);
public String intToIp(int i) {
return ((i >> 24 ) & 0xFF ) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +