Thursday, December 3, 2015

Color Change On Click in Android

when click on Button or TextView or may be layout, when click then change background color. purpose of this, user can detect click or not on button.

when press button then color should be changed.

Save Value in SharedPreferences

Save Value in SharedPreferences 

In Android Save Value in key pair format we use SharedPreferences.

       SharedPreferences     myPrefs = getSharedPreferences("TAG", MODE_PRIVATE);
SharedPreferences.Editor myEditor = myPrefs.edit();

save value

      myEditor.putString("name", abc); // key pair
       myEditor.commit();


Save Boolean Value

      myEditor.putBoolean("key", abc); // key pair
       myEditor.commit();

Get Boolean Value 

boolean status= myEditor.getBoolean(key, false);

Get Save value 

     String name = myPrefs.getString("name", "");

Wednesday, December 2, 2015

JSON Parsing in Android

Parse data from server is many type like XML,DOM and JSON but JSON Parsing widely used, this topic we discuss JSON PARSING.

How to Parse JSON Object:

first we get data from server afterthat we parse, in JSON start with Object or Array.
{ }   =   Object

[ ]  = Array

so we check data is object or array.

    String result=  {"response":"100","data" : "Sucess"} 

It is start with object so first object parse then string.

try {
    JSONObject json = new JSONObject(result);
       String response= json.getString("response");                                   
       String data= json.getString("data");      
} catch (JSONException e) {
    e.printStackTrace();
}
we get response = 100;
and data= Sucess


Tuesday, December 1, 2015

Show Google Ads in Android(AdMob)

show advertising in android mobile like banner or full screen add.


Banner Ads in Android
AdMob in Android
First we need id for ads open https://apps.admob.com/ and monetise application . there are basically two type of ads .

First: Banner Ad (show banner at top or bottom)
Second Full Screen Ad(Interstitial Ads)

Banner Ad show


banner can be adjust according to app it may be top or bottom

add  Google Play Library 

        AdView mAdView = (AdView) findViewById(R.id.adViewHOME);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

AdMob XML File  :


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 
     <com.google.android.gms.ads.AdView
        android:id="@+id/adMob"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="YOUR BANNER ID" >
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

Manifest Permission

you must have set  internet permission.

 <uses-permission android:name="android.permission.INTERNET" />


Full Screen Ads : 


InterstitialAd mInterstitialAd;
AdRequest adRequestFull;

mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("YOUR ID");

adRequestFull = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build();
mInterstitialAd.loadAd(adRequestFull);