How to parsing Large json in android

public static void getLargeJsonFromServer(String url) {
HttpResponse response = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
request.setHeader(“Content-type”, “application/json”);
JSONStringer jsonReq = new JSONStringer().object().key(“Name”)
.value(“value”).endObject();

StringEntity entity = new StringEntity(jsonReq.toString());
request.setEntity(entity);
response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity responseEntity = response.getEntity();
 Gson gson = new Gson();
InputStream in = responseEntity.getContent();
JsonReader reader = new JsonReader(new InputStreamReader(in,
“UTF-8”));
reader.beginArray();
while (reader.hasNext()) {
/**
*  get data from pojo class using Google gson and write your custom logic
*/
Your_Pojo_Class pojo_object = gson.fromJson(reader,
                            Your_Pojo_Class.class);

}
reader.endArray();
reader.close();
} else {
Log.v(“HTTP STATUS”, response.getStatusLine().getStatusCode()
+ “”);
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

how to find out force close bugs in android?

device-2013-11-25-145841 device-2013-11-25-150201device-2013-11-25-145641

we can trace force close bug in real time in android and  we can show custom Messages instead of “Unfortunately app has stopped”.

For download link here

In Any Activity we should write one line of code ( ExceptionFinder.getException(this) ) before calling  setContentView(R.layout.activity_main);

import android.app.Activity;
/**
*
* @author venkypokala
*
*/

public class ExceptionFinder {

public static void getException(Activity activity) {
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(activity));

}
}

/**
*
* @author venkypokala
*
*/
public class ExceptionHandler implements
java.lang.Thread.UncaughtExceptionHandler {
private final Context myContext;

public ExceptionHandler(Context context) {
myContext = context;
}

public void uncaughtException(Thread thread, Throwable exception) {
StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
System.err.println(stackTrace);

/**
*  we can call out Activity or Dialog
*/
Intent intent = new Intent(myContext, ForceCloseActivity.class);
intent.putExtra(ForceCloseActivity.STACKTRACE, stackTrace.toString());
myContext.startActivity(intent);

Process.killProcess(Process.myPid());
System.exit(10);
}
}

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.forceclose.R;
/**
*
* @author venkypokala
*
*/
public class ForceCloseActivity extends Activity {
static final String STACKTRACE = “stacktrace”;
String stackTrace=null;
private TextView exceptionText;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
stackTrace = getIntent().getStringExtra(STACKTRACE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.error_popup2);
initGUI();
setEvents();
}

private void setEvents() {

((Button) findViewById(R.id.ok_button))
.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Log.v(“Force”, stackTrace);

}
});

((Button) findViewById(R.id.report))
.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v(“Force”, stackTrace);

exceptionText.setVisibility(View.VISIBLE);
exceptionText.setText(stackTrace);
}
});
}

private void initGUI() {
exceptionText=(TextView)findViewById(R.id.exceptionText);
}
}

How to get Large images from server in android?

    public final Bitmap getImageFromServer(final String imageUrl) {
        Bitmap bitmap = null;
        try {
            if (imageUrl != null && !imageUrl.equals(“”)) {
                URL Url = new URL(imageUrl);
                return BitmapFactory.decodeStream(Url.openStream());
            }
        } catch (MalformedURLException e) {

        } catch (OutOfMemoryError e) {

            bitmap = null;
        } catch (IOException e) {

            bitmap = null;
        } catch (Exception e) {

            bitmap = null;
        }
        return bitmap;
    }

Mobile Operating Systems Comparison

iOS 6 Android BlackBerry OS Windows Phone 7
Vote 2 6 0 0
Compatible devices iPhone, iPod, iPad HTC, Samsung Galaxy, Motorola BlackBerry torch, bold, curve… Windows Phone, Nokia lumia 710
Latest version 6.0.1 4.2.1 7.1 7.10.8107.79
Release date 2012 Nov 1 2012 Nov 29 2011 May 1 2012 Jan 4
Open source No Yes No No
SDK platform availability
Windows No Yes Yes Yes
Mac OS Yes Yes No No
Linux No Yes No No
Technical details
Multitasking Yes Yes Yes Yes
Adobe Flash support No Yes No Yes
Market place
Market name App Store Google Play BlackBerry App World Windows Phone Marketplace
Number of apps 1000000 + 600000 + 16000 2400 +
Additional
Site relatif au SDK apple.com/… android.com/… blackberry.com/… microsoft.com/…
Website apple.com/… android.com blackberry.com/… windowsphone7.com
Wikipedia wikipedia.org/… wikipedia.org/… wikipedia.org/… wikipedia.org/…

How to store and get String in SharedPreferences in android?

Session are useful when you want to store user data globally through out the application. This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences. The problem with storing data in global variable is data will be lost once user closes the application, but storing the data in shared preferences will be persistent even though user closes the application.   

// -store value———
    public void setShared_Preferences(String m_key, String name, String value) {

        SharedPreferences preferences = getSharedPreferences(m_key,
                MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(name, value);
        editor.commit();
    }

    // -get  value———-
    public String getShared_Preferences(String m_key, String name) {
        SharedPreferences myPrefs = getSharedPreferences(m_key,
                MODE_WORLD_READABLE);
        String resgid = myPrefs.getString(name, “”);
        return resgid;
    }

How to get Latitude and Longitude using Gps and Network in android?

We should give two permission in AndroidManifest file.

1. <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />
2. <uses-permission android:name=”android.permission.INTERNET” />

//——-Java code————

public class MainActivity extends Activity implements LocationListener {

    LocationManager Locationm;
    public static Location lastbestlocation_trck = null;
   public static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
    public static final long MIN_TIME_BW_UPDATES = 1000*60*1; // 1 minute

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainlayout);
        
        if (lastbestlocation_trck == null) {
            Locationm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

           // ——–Gps provider—
            Locationm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    Constants.MIN_TIME_BW_UPDATES,
                    Constants.MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

          // ——–Network provider—
            Locationm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                    Constants.MIN_TIME_BW_UPDATES,
                    Constants.MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
        }
   
    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        try {
            double latitude = 0, longitude = 0;
            if (isBetterLocation(location, lastbestlocation_trck)) {
              lastbestlocation_trck = location;
                latitude = location.getLatitude();
                longitude = location.getLongitude();
                }

        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    @Override
    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        // TODO Auto-generated method stub
    }

    protected boolean isBetterLocation(Location location,
            Location currentBestLocation) {
        if (currentBestLocation == null) {
            // A new location is always better than no location
            if (location.getProvider().contains(“gps”)) {
                return true;
            } else {
                return false;
            }
        }

        // Check whether the new location fix is newer or older
        boolean isSignificantlyNewer = location.getTime() > currentBestLocation
                .getTime();

        // If it’s been more than two minutes since the current location, use
        // the new location
        // because the user has likely moved
        if (!isSignificantlyNewer) {
            return false;
        }
        // Check whether the new location fix is more or less accurate
        int accuracyDelta = (int) (location.getAccuracy() – currentBestLocation
                .getAccuracy());
        boolean isLessAccurate = accuracyDelta > 0;
        boolean isMoreAccurate = accuracyDelta < 0;
        boolean isSignificantlyLessAccurate = accuracyDelta > 200;

        // Check if the old and new location are from the same provider
        boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());

        // Determine location quality using a combination of timeliness and
        // accuracy
        if (isMoreAccurate) {
            return true;
        } else if (isSignificantlyNewer && !isLessAccurate) {
            return true;
        } else if (isSignificantlyNewer && !isSignificantlyLessAccurate
                && isFromSameProvider) {
            return true;
        }
        return false;
    }
    /** Checks whether two providers are the same */
    private boolean isSameProvider(String provider1, String provider2) {
        if (provider1 == null) {
            return provider2 == null;
        }
        return provider1.equals(provider2);
    }
 
}

 

Free Cloud Storages

Cloud storage is becoming very much popular industry years by years.Many IT giants come into Cloud as its future growth.Now you might be thinking

What is Cloud Storage?

Cloud storage is “a networked online storage” hosted by Third Parties.Suppose you have some data or files on Dropbox.Then you can access that data from your office,from your home as well as you can share that data to your friends via a single link.It’s like a Team Workplace!!

There are lots of free Online Cloud Storage Sites.I am using few of them.With their Services,Security.I had tried to do some Top 10 Free Online Cloud Storage Sites  list of best cloud storage providers which may give you around 140 GB Free Secured Space on Cloud.

1. DropBox – 2GB to 18GB

dropbox

One of the most popular ever service was founded by two MIT students.There are 50 Million people who use Dropbox around the globe.Dropbox gives you 2GB space for free when you signup.

If you refer your friend to join Dropbox,then you get 500 MB Space.This space can be increased upto 18 GB.There are also some options like to connect account.

The Good : Simplest & Auto Back Up
The Bad : Limited Space when you sign up

Dropbox Sign Up

2. Box – 5GB

Box is one of the simplest to use ever Cloud Storage.Box is being used by 10 million individuals, small businesses and Fortune 500 companies.I am using Box.I can see which of my files are downloaded by how many times.Box provides you limited file Size upto 100 MB.So you can not upload Movies!!;-)

The Good : Simplest & Secured
The Bad : Limited File Size=100 MB

Box Sign Up

3. Google Drive – 5GB

From its name,You can think that it’s Google Service.Yes,It is.Now I think you will not mind to use Google Drive.You can Login with your existing Google Account to use Google Drive

The Good : No need to Signup,If you have already Google account!!

Google Drive Sign In

4. SkyDrive – 7GB

“SkyDrive” service is provided by Microsoft.Sky Drive is a formerly known as Windows Live SkyDrive.Yes,It is also like Google Drive.If you have Windows Live or Outlook.com account.You can easily Sign In with your existing account.

The Good : No need to Signup,If you have already Live or Outlook.com account!!

The Bad :Limited File Size =300 MB.

Sky Drive Sign In

5. Amazon Cloud Drive – 5GB

Amazon Cloud Drive service provided by famous Amazon online shop.If you signup with Amazon,then you will get 5 GB space for free.

Amazon Cloud Drive Sign Up

6. SugarSync – 5GB

SugarSync is one of the fastest becoming cloud service .Due to its availability of every platforms,SugarSync is becoming very popular among lots of users.They support all Apps not only Android,iPhone but BlackBerry, Symbian and many more!!

SugarSync Sign Up

7. 4Shared – 15GB

4Shared is one of the Online Storage Provider who gets lots of visits from Search Engines.If any users who shared public any file,then because of  its systematic file storage,they get good number of visits from Search Engines.This is the success story of 4Shared!!

The Bad : Your free account is only for 180 Days & Limited File Size = 2048MB

4Shared Sign Up

8. iDrive – 15GB

From the name,You may be thinking It must be an Apple services.No,iDrive is not an Apple service.iCloud is an Apple service.It is a special online cloud storage service for Database Backups.Cnet gives 4.5 out of 5 to iDrive.

iDrive Sign Up

9. Adrive – 50GB

I think the highest amount of Free Online Cloud Storage provides by ADrive.Though User Interface is not quite good,But for 50GB,you should not mind to create account!!

The Good : 50 GB Storage!!
The Bad  : Not compatible with Android App,No online collaboration,Forum Support Only.Limited File Size = 2GB

Adrive Sign Up

10. MegaCloud – 8GB to 18 GB

Megacloud is one of the good feature File Versioning.You can review and retrieve your previous files whenever you like.You can also get extra 10 GB by inviting your friends.

 

How to Integrate slide menu in android?

Slide menu component support android version 2.2 and above. we should using android support jar v4

Source code link

device-2013-01-25-104412device-2013-01-25-104530

 

Activity-1

public class MainActivity extends Activity {

private ScrollerLinearLayout sideSlideLayout;

private ListView listView;
private final String[] menuTitles = { “Biraynis”, “Sample”, “Contorll” };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

init();
setMenuButton();
setListView();
setContent(0);
}

private void init() {
this.sideSlideLayout = (ScrollerLinearLayout) findViewById(R.id.menu_content_side_slide_layout);

}

private void setMenuButton() {
ImageView menuButton = (ImageView) findViewById(R.id.main_tmp_button);
menuButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sideSlideLayout.scroll();
listView.setVisibility(View.VISIBLE);
}
});
}

private void setListView() {

ArrayList<String> items = new ArrayList<String>();
for (int i = 0; i < menuTitles.length; i++) {
items.add(menuTitles[i]);
}

listView = (ListView) findViewById(R.id.menu_content_menulist);
listView.setFadingEdgeLength(0);

MenuAdapter menuAdapter = new MenuAdapter(this, items, this);
listView.setAdapter(menuAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setContent(arg2);
sideSlideLayout.scroll();

}
});

}

private void setContent(int position) {

}
}

Slide Menu Classes

MenuAdapter.java

public class MenuAdapter extends BaseAdapter {
private Context context;
private ArrayList<String> items;
private LayoutInflater inflater;

public MenuAdapter(Context context, ArrayList<String> items, Activity act) {
this.context = context;
this.items = items;
this.inflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.item_menu, null);
TextView title = (TextView) convertView.findViewById(R.id.menu_title);
title.setText(getItem(position));
return convertView;
}

@Override
public int getCount() {
return items.size();
}

@Override
public String getItem(int position) {
return items.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

}

ScrollerLinearLayout.java
public class ScrollerLinearLayout extends LinearLayout {

private Context context;
private Scroller scroller;
private float density;
private int scrollSizeWidth;

public ScrollerLinearLayout(Context context) {
super(context);
this.context = context;
init();
}

public ScrollerLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}

private void init() {
scroller = new Scroller(context);

WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int screenWidth = disp.getWidth();

DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay()
.getMetrics(metrics);
this.density = metrics.density;

scrollSizeWidth = (int) (screenWidth – (108 * density));

}

public void scroll() {
animationStart();
}

@Override
public void computeScroll() {
if (scroller.computeScrollOffset()) {

scrollTo(scroller.getCurrX(), scroller.getCurrY());
postInvalidate();
}
}

private void animationStart() {
if (scroller.getCurrX() < 0)
scroller.startScroll(scroller.getCurrX(), scroller.getCurrY(), -1
* scroller.getCurrX(), 0, 500);
else
scroller.startScroll(scroller.getCurrX(), scroller.getCurrY(),
-scrollSizeWidth, 0, 500);

invalidate();
}
}

Activity–layout

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:background=”@drawable/actionbar_background”
android:layout_height=”match_parent” >

<EditText
android:id=”@+id/hi”
android:layout_width=”120dp”
android:layout_height=”wrap_content”
android:layout_alignParentTop=”true”
android:background=”@drawable/edit” />

<ListView
android:id=”@+id/menu_content_menulist”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_below=”@+id/hi” >
</ListView>

<RelativeLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >

<side.menu.scroll.ScrollerLinearLayout
android:id=”@+id/menu_content_side_slide_layout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”45dp”
android:background=”@drawable/ab_solid_example”
android:orientation=”horizontal” >

<ImageView
android:id=”@+id/main_tmp_button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/actionbar_background”
android:src=”@drawable/download” />

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_weight=”1″ />

<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/sr” />
</LinearLayout>

<LinearLayout
android:id=”@+id/menu_content_root”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”@drawable/bg_groud” />
</side.menu.scroll.ScrollerLinearLayout>
</RelativeLayout>

</RelativeLayout>