Code example for JSONStringer

Methods: endObject, key, object, toString, value

0
	private static void logHeader(Context context) {
		TelephonyManager mTelephonyMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
		String imei = mTelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE  
 
		try { 
			JSONStringer js = new JSONStringer();
			js.object();
			js.key("imei");
			js.value(imei);
			js.key("time");
			js.value(System.currentTimeMillis());
			js.key("package");
			js.value(context.getApplicationInfo().packageName);
			js.key("application");
			js.value(context.getApplicationInfo().name);
			js.key("os.name");
			js.value(System.getProperty("os.name"));
			js.key("os.arch");
			js.value(System.getProperty("os.arch"));
			js.key("os.version");
			js.value(System.getProperty("os.version"));
			 
            PackageManager pm = context.getPackageManager(); 
            try {  
            	PackageInfo pi; 
            	// Version  
            	pi = pm.getPackageInfo(context.getPackageName(), 0); 
            	js.key("versionName");
            	js.value(pi.versionName); 
            	js.key("versionCode");
            	js.value(pi.versionCode); 
            } catch (NameNotFoundException e) { 
            	Log.e(TAG,"Checking package info", e);
            }  
        	js.key("phoneModel");
        	js.value(android.os.Build.MODEL);
        	js.key("androidVersion");
        	js.value(android.os.Build.VERSION.RELEASE); 
			 
			js.endObject();
			log(LOGTYPE_HEADER, js.toString());
		} 
		catch (Exception e) {
			Log.e(TAG,"Creating log data (header)", e);
		} 
	}