Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; public class Main { public static Object get(Context context, String name) { if (context == null || name == null) { throw new IllegalArgumentException("Context and key must not be null"); } Object systemService = context.getSystemService(name); if (systemService == null) { context = context.getApplicationContext(); systemService = context.getSystemService(name); } if (systemService == null) { throw new IllegalStateException(name + " not available"); } return systemService; } }