android.content.Context - Application Context Information

This section provides tutorial example on how to display application context information using instance methods of the android.content.Context class like application package name, private file folder, private cache folder, etc.

For information about the running application itself, the object inherits some useful instance methods from the android.content.Context class:

I enhanced again my AboutAndroid application to display its context information using methods listed above:

 * Version 6.0 - Adding application context info
 * Copyright (c) 2015,, All Rights Reserved.
package com.herongyang;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.ScrollView;
import android.os.Environment;
public class AboutAndroid extends Activity {
   public void onCreate(Bundle savedInstanceState) {
      String msg = "";

      msg += "System properties\n";
      msg += "-------------\n";
      java.util.Properties props = System.getProperties();
      java.util.Enumeration e = props.propertyNames();
      while (e.hasMoreElements()) {
         String k = (String) e.nextElement();
         String v = props.getProperty(k);
         msg += k+": "+v+"\n";

      msg += "\n";
      msg += "Environment variables\n";
      msg += "-------------\n";
      java.util.Map envs = System.getenv();
      java.util.Set keys = envs.keySet();
      java.util.Iterator i = keys.iterator();
      while (i.hasNext()) {
         String k = (String);
         String v = (String) envs.get(k);
         msg += k+": "+v+"\n";

      msg += "\n";
      msg += "Environment folders\n";
      msg += "-------------\n";
      msg += "Data folder: "
      msg += "Download cache folder: "
      msg += "External Storage folder: "
      msg += "Root folder: "

      msg += "\n";
      msg += "Application context info\n";
      msg += "-------------\n";
      msg += "Cache folder: "
      msg += "External cache folder: "
      msg += "File folder: "
      msg += "OBB folder: "
      msg += "Package name: "
      msg += "Package code path: "
      msg += "Package resource path: "

      TextView tv = new TextView(this);
      ScrollView sv = new ScrollView(this);

2. Uninstall the previous version, build, install and run this new version. I get the following extra information at the end:

Cache folder: /data/data/com.herongyang/cache
External cache folder: /storage/sdcard/Android/data/com.herongyang/cache
File folder: /data/data/com.herongyang/files
OBB folder: /storage/sdcard/Android/obb/com.herongyang
Package name: com.herongyang
Package code path: /data/app/com.herongyang-1/base.apk
Package resource path: /data/app/com.herongyang-1/base.apk

Below was some system properties I got from my Android 4.0.3 emulator created with Android SDK R17:

Cache folder: /data/data/com.herongyang/cache
External cache folder: /mnt/sdcard/Android/data/com.herongyang/cache
File folder: /data/data/com.herongyang/files
OBB folder: /mnt/sdcard/Android/obb/com.herongyang
Package name: com.herongyang
Package code path: /data/app/com.herongyang-1.apk
Package resource path: /data/app/com.herongyang-1.apk

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

AboutAndroid - Application to Retrieve System Information

 java.lang.System Class - Accessing System Information

 Creating Android Project for Simple Application

 Build, Install and Run Android Application

 System.getProperties() - Retrieving System Properties

 android.widget.ScrollView Class - Scrolling Text View

 System.getenv() Method - System Environment Variables

 android.os.Environment Class - Environment Folders

android.content.Context - Application Context Information Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

 Building Your Own Web Browser

 Android Command Line Shell

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials


 Full Version in PDF/EPUB