RSS

With my Android Guru Mark Murphy


In 2009, I bought 3 books of Mark Murphy on Android (http://commonsware.com/warescription) and afterwords I shared those books over a file sharing site. Mark Murphy emailed me and told that I am doing a wrong thing.

In 2011, I met this man at Droidcon UK 2011 and I told him about that incident. It was a great event for me to have him in the same frame of a photo.

 
1 Comment

Posted by on April 21, 2012 in Uncategorized

 

Android: How to get Address from geolocation using Geocoder


Class: HttpRetriever

public class HttpRetriever {
	private DefaultHttpClient client = new DefaultHttpClient();

	public String retrieve(String url) {
		HttpGet getRequest = new HttpGet(url);
		try {
			HttpResponse getResponse = client.execute(getRequest);
			final int statusCode = getResponse.getStatusLine().getStatusCode();
			if (statusCode != HttpStatus.SC_OK) {
				Log.w(getClass().getSimpleName(), "Error " + statusCode
						+ " for URL " + url);
				return null;
			}
			HttpEntity getResponseEntity = getResponse.getEntity();

			if (getResponseEntity != null) {
				return EntityUtils.toString(getResponseEntity);
			}
		} catch (IOException e) {
			getRequest.abort();
			Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
		}
		return null;

	}
}

Method: getAddressFromGPSData

public static final String GOOGLE_GEOCODER = "http://maps.googleapis.com/maps/api/geocode/json?latlng=";

public static String getAddressFromGPSData(double lat, double longi) {
		HttpRetriever agent = new HttpRetriever();
		String request = GOOGLE_GEOCODER + lat + ","
				+ longi + "&sensor=true";
		// Log.d("GeoCoder", request);
		String response = agent.retrieve(request);
		String formattedAddress = "";
		if (response != null) {
			Log.d("GeoCoder", response);
			try {
				JSONObject parentObject = new JSONObject(response);
				JSONArray arrayOfAddressResults = parentObject
						.getJSONArray("results");
				JSONObject addressItem = arrayOfAddressResults.getJSONObject(0);
				formattedAddress = addressItem.getString("formatted_address");
			} catch (JSONException e) {

				e.printStackTrace();
			}

		}

		// Log.d("GeoCoder", response);
		return formattedAddress;
	}
 
5 Comments

Posted by on March 12, 2012 in Uncategorized

 

Android: How to get Installed Applications List from your Application


Class: InstalledAppData

public class InstalledAppData{
	private String deviceId;
	private String packageName;
	private String appName;
	private String installTime;
	private String status;

	public InstalledAppData(String deviceId, String packageName,
			String appName, long installTime, String status) {
		super();
		this.deviceId = deviceId;
		this.packageName = packageName;
		this.appName = appName;
		long time = installTime;
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String datetime = sdf.format(date);
		this.installTime = datetime;
		this.status = status;
	}
	public String getDeviceId() {
		return deviceId;
	}
	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
	}
	public String getPackageName() {
		return packageName;
	}
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}
	public String getAppName() {
		return appName;
	}
	public void setAppName(String appName) {
		this.appName = appName;
	}
	public long getInstallTime() {
		try {
			DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = (Date) formatter.parse(this.installTime);
			return date.getTime();

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public void setInstallTime(long installTime) {
		long time = installTime;
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String datetime = sdf.format(date);
		this.installTime = datetime;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
}

Add the following methods in your Activity and show them in ListView using your custom ArrayAdapter
Method: importInstalledAppsData() returns an ArrayList of IntsalledAppData

public ArrayList<InstalledAppData> importInstalledAppsData(){
    ArrayList<InstalledAppData> appList=new ArrayList<InstalledAppData>();
    PackageManager pkgManager=getApplicationContext().getPackageManager();
    List<ApplicationInfo> packages=getInstalledApplicationsList(pkgManager);
    String deviceId=Util.getDeviceId(getApplicationContext());
    
    for (ApplicationInfo packageInfo : packages) {
	String packageName=packageInfo.packageName;
	String appName="";
	String appFile = packageInfo.sourceDir;
	long installTime = new File(appFile).lastModified();
	String status="s";
	if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
            appName = (String) pkgManager.getApplicationLabel(packageInfo);
        } 
        else {
	    appName = (String) pkgManager.getApplicationLabel(packageInfo);
	}
			
	InstalledAppData data=new InstalledAppData(deviceId, packageName, appName, installTime, status);
        appList.add(data);
	
		
    }
    return appList;
}

Method: getInstalledApplicationsList returns List of ApplicationInfo

public List<ApplicationInfo> getInstalledApplicationsList(PackageManager pm) {
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    return packages;
}
 
2 Comments

Posted by on January 26, 2012 in Uncategorized

 

Droidcon 2011


Droidcon London Oct 6-7

 
Leave a comment

Posted by on September 30, 2011 in Uncategorized

 

Android: Client Server Communication


 
1 Comment

Posted by on September 30, 2011 in Android, Tutorial

 

Tags: ,

Android Tutorial: Working with Lists and ListActivity


 
5 Comments

Posted by on September 15, 2011 in Android, Tutorial, User Interface

 

Tags: ,

Android Google Maps Tutorial


 
Leave a comment

Posted by on September 14, 2011 in Uncategorized