Skip to content

Instantly share code, notes, and snippets.

novoda / Android
Created Apr 21, 2010
Android: Enforcing a wakelock is sometimes necessary but should be used with caution as it will take it's toll on the battery.
View Android
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
public class DoNotDimScreen extends Activity {
private PowerManager.WakeLock wl;
novoda / List music files
Created Apr 21, 2010
Android: List all music files
View List 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 = {
novoda / Android: get IP Address
Created Apr 21, 2010
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.
View Android: get IP Address
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) + "." +
You can’t perform that action at this time.