Android Application - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Application class.

This code example shows how to use the following methods:getSystemService
      @Override public void run() { 
        Application app = (Application) getTargetContext().getApplicationContext();
        String simpleName = SpoonInstrumentationTestRunner.class.getSimpleName();
 
        // Unlock the device so that the tests can input keystrokes. 
        ((KeyguardManager) app.getSystemService(KEYGUARD_SERVICE)) //
            .newKeyguardLock(simpleName) //
            .disableKeyguard();
        // Wake up the screen. 
        ((PowerManager) app.getSystemService(POWER_SERVICE)) //
            .newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, simpleName) //
            .acquire();
      } 
    }); 
 
    super.onStart(); 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:getPackageName
	 * Parses the deploy.json file if it exists 
	 */ 
	public TiDeployData(Application app)
	{ 
		File extStorage = Environment.getExternalStorageDirectory();
		File deployJson = new File(new File(extStorage, app.getPackageName()), "deploy.json");
 
		if (deployJson.exists()) {
			readDeployData(deployJson);
		} 
	} 
 
	protected void readDeployData(File deployJson)
	{ 
		try { 
			FileInputStream stream = new FileInputStream(deployJson);
			deployData = new JSONObject(KrollStreamHelper.toString(stream));
			Log.d(TAG, "Read deploy data: " + deployData.toString(), Log.DEBUG_MODE);
 
		} catch (FileNotFoundException e) {
7
CodeRank
This code example shows how to use the following methods:startActivity
        } 
    } 
 
    @Implementation 
    public void startActivityForResult(Intent intent, int requestCode) {
        intentRequestCodeMap.put(intent, requestCode);
        startedActivitiesForResults.add(new IntentForResult(intent, requestCode));
        getApplicationContext().startActivity(intent);
    } 
 
    public void receiveResult(Intent requestIntent, int resultCode, Intent resultIntent) {
        Integer requestCode = intentRequestCodeMap.get(requestIntent);
        if (requestCode == null) {
            throw new RuntimeException("No intent matches " + requestIntent + " among " + intentRequestCodeMap.keySet());
        } 
        try { 
            Method method = Activity.class.getDeclaredMethod("onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class);
            method.setAccessible(true);
            method.invoke(realActivity, requestCode, resultCode, resultIntent);
        } catch (IllegalAccessException e) {
7
CodeRank
This code example shows how to use the following methods:getResources
 
    protected Resources resources;
 
    @Inject 
    public ResourcesProvider(Application application) {
        resources = application.getResources();
    } 
 
    public Resources get() {
        return resources;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:unregisterActivityLifecycleCallbacks
        MainLifecycleDispatcher.get().unregisterActivityLifecycleCallbacks(callback);
    } 
 
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    private static void postIcsUnregisterActivityLifecycleCallbacks(Application application, ActivityLifecycleCallbacksCompat callback) {
        application.unregisterActivityLifecycleCallbacks(new ActivityLifecycleCallbacksWrapper(callback));
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:
    private ViewGroup child3;
    private View child3a;
    private View child3b;
 
    @Before public void setUp() throws Exception { 
        Application context = new Application();
        ShadowApplication.bind(context, new ResourceLoader(10, R.class, null, null));
 
        root = new FrameLayout(context);
 
        child1 = new View(context);
        child2 = new View(context);
        child3 = new FrameLayout(context);
        child3a = new View(context);
        child3b = new View(context);
 
        root.addView(child1);
        root.addView(child2);
        root.addView(child3);
 
6
CodeRank
This code example shows how to use the following methods:getResources
 
            Object value = null;
 
            try { 
 
                final Resources resources = application.getResources();
                final int id = getId(resources,annotation);
                final Class<?> t = field.getType();
 
                if (String.class.isAssignableFrom(t)) {
                    value = resources.getString(id);
                } else if (boolean.class.isAssignableFrom(t) || Boolean.class.isAssignableFrom(t)) {
                    value = resources.getBoolean(id);
                } else if (ColorStateList.class.isAssignableFrom(t)  ) {
                    value = resources.getColorStateList(id);
                } else if (int.class.isAssignableFrom(t) || Integer.class.isAssignableFrom(t)) {
                    value = resources.getInteger(id);
                } else if (Drawable.class.isAssignableFrom(t)) {
                    value = resources.getDrawable(id);
                } else if (String[].class.isAssignableFrom(t)) {
6
CodeRank
This code example shows how to use the following methods:getSharedPreferences
 
    @Override 
    public EncryptedSharedPreferences get() { 
        SharedPreferences sharedPreferences;
        if (preferencesName != null) {
            sharedPreferences = application
                    .getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
        } else { 
            sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application);
        } 
 
        return new EncryptedSharedPreferences(application, sharedPreferences);
    } 
 
    public static class PreferencesNameHolder { 
 
        @Inject(optional = true) 
        @SharedPreferencesName 
        protected String value;
    } 
6
CodeRank
This code example shows how to use the following methods:getSystemService, registerReceiver
 
            // Keep reference to app 
            this.app = app;
 
            // Registering receiver to handle network changes 
            app.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
 
            // Getting connectivity manager and current network type 
            conMgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
            if (conMgr != null) {
                final NetworkInfo netInfo = conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                if (netInfo != null) {
                    currentNetworkSubType = netInfo.getSubtype();
                } 
            } 
        } 
    } 
 
    /** 
     * Build the AndroidHttpClient. 
6
CodeRank
This code example shows how to use the following methods:getSharedPreferences
 
    @Override 
    public EncryptedSharedPreferences get() { 
        SharedPreferences sharedPreferences;
        if (preferencesName != null) {
            sharedPreferences = application
                    .getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
        } else { 
            sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application);
        } 
 
        return new EncryptedSharedPreferences(application, sharedPreferences);
    } 
 
    public static class PreferencesNameHolder { 
 
        @Inject(optional = true) 
        @SharedPreferencesName 
        protected String value;
    } 
6
CodeRank

Related Android Application Questions & Answers:

Other Android Application Examples

9:	import com.android.volley.toolbox.Volley;
10:	
11:	public class AppController extends Application {
12:	
13:		public static final String TAG = AppController.class

Read More

See Code Examples for Android Application Methods: