Posts

Showing posts with the label Android

Facebook SDK for android - How to share Session throughout all activities

A problem which I faced when using Facebook SDK for android was in my app login happens through one activity and posting to Facebook happens through another activity. So I had to retrieve the session which is opened in the LoginActitvity. Actually solution was simpler than I thought. To get the session from an another activity you can use the below method. private void getSession() { Session.openActiveSession(this, false, callback); } private Session.StatusCallback callback = new Session.StatusCallback() { public void call(Session session, SessionState state, Exception exception) { if (session.isOpened()) { //Do something } } };

Adding a Foursquare, Google+ like sliding drawer to your android app

Image
Currently Android SDK does not support such a feature. But this kind of designs are very popular between the users. But there are many open source libraries which facilitates sch omplementation. https://github.com/jfeinstein10/SlidingMenu is an open sorce sliding drawer library which is used many poplar android applications. Using this is prettry simple. This video  explains how to integrate with your android project. After the integration is done you can create a sliding drawer like this. Add the following code to onCreate() method of your activity.     menu = new SlidingMenu(this);     menu.setMode(SlidingMenu.LEFT);     menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);     menu.setShadowWidth(5);     menu.setFadeDegree(0.0f);     menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);     menu.setBehindWidth(150); //change width according to your device     menu.setMenu(R.layout.menu_frame); Here menu_frame is the layout of the sliding drawer. It has to be a

Using Geolocation API in phone gap

I am currently developing a Phonegap application for Google summer of Code 2012. I encountered some problems when using it and this is how I corrected them. Location not available- In android emulator does not automatically get the location. So we have to send a moc location to the emulator using DDMS perspective in eclipse. Phonegap documentation says to use the below method to get location. navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError); But this gave me an error with error code 2 unable to start geolocation service. I corrected it using the below method. navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError,{ enableHighAccuracy: true }); Note - This is only for testing in the emulator.

How to make a phone call in a Android application

This may a looks like a simple task. Actually it is a simple task. You can do it using few lines of code. But there are only few places which shows how to do it. So I decided to mention it here. public void onCallButtonClicked(View view) { String url = "tel:" + tpNo; Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); intent.setData(Uri.parse(url)); startActivity(intent); }

Android: Using Google maps app to show places in your application

Image
When we are developing android application with maps functionality normally developers tries to use Google maps API for this. But if your requirement is simple it may be more easy and effective to use existing maps application by a intent. In this application I'm going to show how to show the nearest hospital in your application. Note- To make this work your app and emulator must be created using Google APIs not android APIs. (Both are the same but if you are not using Google maps API map application functionality is not available to you). Here is the code, LocationManager  locMgr  = (LocationManager) getSystemService(Context. LOCATION_SERVICE); Location recentLoc = locMgr.getLastKnownLocation( LocationManager.GPS_PROVIDER); double lat = recentLoc.getLatitude(); double lon = recentLoc.getLongitude(); String geoURI = String.format("geo:%f,%f?q= hospital", lat, lon); Uri geo = Uri.parse(geoURI); Intent geoMap = new Intent(Intent.ACTION_VIEW, geo); startA