Thursday, 5 November 2015

Android API V - 23 NameValuePair Deprecated Solution

Hi 

By Brand New Android API V-23 update, all of our android developers are facing a big issue on "Apache HTTP Client Removal". In my circle also by update of API V-23 lots of developer unable to connect with sever Page.

Apache Removed Reference :

org.apache.http.NameValuePair;
org.apache.http.message.BasicNameValuePair;
Android 6.0 release removes support for the Apache HTTP client. But in our existing Android Projects we connected & Receive the JSON through the server page by using the Apache's NameValuePair & BasicNameValuePair till API V-22.

 Because of deprecated of Apache, we need to use HttpURLConnection, But the problem is have to change & correct all of your android Logic & Code in all projects.

My self i have try to find the solution by using the HttpURLConnection without changing your Logic & Code. i took small risk for you,  just by relax you may download my .AAR file and attach into your project and run with your same code by small changes.

(If it is useful to you don't forget to leave a comment)

Download my raj_namevaluepair.aar file & add it into your project.


Android Code to Use My .AAR file :


// my server page link
String URL_My_Server_Page="http://xxxxx.com/xxxxx/xxxxxxxx/xxxxxxx.php";
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jsonparser);
    tv_op = (TextView)findViewById(R.id.tv_op);
    listView = (ListView) findViewById(R.id.listView);
// class to execute the URL
new Page_Executer().execute();
}

class Page_Executer extends AsyncTask<String, String, String> {
    ProgressDialog p_dialog;
    String op_esult = null;
    @Override    protected void onPreExecute() {
        super.onPreExecute();
        p_dialog = new ProgressDialog(JSONParser.this);
        p_dialog.setTitle("Loading");
        p_dialog.setCancelable(false);
        p_dialog.setIndeterminate(false);
        p_dialog.show();
    }

    @Override    protected String doInBackground(String... strings) {
        a_list = new ArrayList();
        try {
// My class to handle            
R_JSONParser raj_parser = new R_JSONParser();
// My NameValuePair to pass your parameters            
ArrayList<R_NameValuePair> n_pair = new ArrayList<>();
// can pass number of parameters as you need            
n_pair.add(new R_NameValuePair("",""));
// method to return the result as string , you need to pass server page link, Method, Parameters with values            
op_esult = raj_parser.Load_Data_From_URL(URL_My_Server_Page, "GET", n_pair);
            Log.d("result", op_esult);
// As usual you can handle JSONArray & JSONObject            
JSONArray j_array = new JSONArray(op_esult);
            for (int i = 0; i < j_array.length(); i++) {
                JSONObject j_obj_t = j_array.getJSONObject(i);
                String MS01key = j_obj_t.getString("MS01key");
                String BloodGroupName = j_obj_t.getString("BloodGroupName");
                a_list.add(new Raj_B(MS01key, BloodGroupName));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Raj_Adapter r_adptr = new Raj_Adapter(getApplicationContext(), R.layout.list_a, a_list);
        listView.setAdapter(r_adptr);
        p_dialog.dismiss();
    }
}


The Output is :



Enjoy..,

Have A Happy Day..,

Monday, 26 October 2015

Upload Selected Image On Server

Hi!

  Some of our Android developers are struggle with Images, for Upload on Server & Download from the server.

Normally we can Upload & Download Images from the server, But the thing is, the Base64 is the only format to help us. In this blog i have explain how to do this, and i have reduce your working time, within 3 Mins you can do this, Needn't to R&D for this i have done and attached my Raj_Img_Upload.aar file for you. Just download the file and fallow the below.

As usual we can use Json format to Upload & Download the image. But the method should be "POST".

Link to Download My .aar file  download this .aar file and add in your project, That's all.


My Activity Class :

public class MainActivity extends ActionBarActivity {


// Image Button to set the selected Image
    ImageButton img_btn_prf_img;

// My .AAR file to handle all your risk part.
    Raj_Image_Handler raj_Handler;
// TextView to show your converted format (Image into Base64)
    TextView base_64_txt;
// To open up Image Gallery 
    private static final int GALLERY = 1;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img_btn_prf_img = (ImageButton) findViewById(R.id.img_btn_prf_img);
        base_64_txt = (TextView) findViewById(R.id.base_64_txt);
// Pass your ImageButton & Activity to my .aar
        raj_Handler = new Raj_Image_Handler(getApplicationContext(), img_btn_prf_img);

        img_btn_prf_img.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
// Get Default Bitmap date what i have set
                Bitmap Image = raj_Handler.get_Image();
                img_btn_prf_img.setImageBitmap(null);
                if (Image != null)
                    Image.recycle();
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"), GALLERY);
            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == GALLERY && resultCode != 0) {
            Uri mImageUri = data.getData();
// Pass the selected image Uri to my .aar
String enc_img = raj_Handler.set_Image_From_Gallery(mImageUri);
// get the Base64 format of your selected Image
            base_64_txt.setText(enc_img);
        }
    }
}









Convert From Base64 to Image :

If you want to convert from Base64 to Image please do the fallowing

//ImageButton for check the output 
ImageButton imb_set;

imb_set = (ImageButton) findViewById(R.id.imb_set);

// Action to convert Base64 to Image
imb_set.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {

// Single line parameter (ImageButton & Base64 output)
        raj_Handler.set_Image_Base_64(imb_set,your_base64_string);
    }
});


Sample APK: Download APK

Out Put:



Enjoy!..,

Thank You!

Have A Happy Day..,

Friday, 12 June 2015

Android Bar/QR Code Scanner!

Hi!

Today i am going to show the example how to read Bar / QR Code form android device.


1) Function on Call Class to Scan the Sequence

// startActivityForResult for safety carry of sequence.
Intent int_brcd = new Intent(PO_Entry.this, InitiatBarCd.class);
startActivityForResult(int_brcd, 3);


2) Class to Scan the Bar/QR Code


package vgs.raj.tot.ivnt;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;


public class InitiatBarCd extends ActionBarActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_po__entry);

        IntentIntegrator scanIntegrator = new IntentIntegrator(this);
        scanIntegrator.initiateScan();
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanningResult = IntentIntegrator.parseActivityResult(
                requestCode, resultCode, intent);
        if (scanningResult != null) {
            playSound();
            String scanContent = scanningResult.getContents();
            Intent int_get_br_bk = new Intent();
            int_get_br_bk.putExtra("ip_br_code", scanContent);
            setResult(3, int_get_br_bk);
            finish();
        } else {
            Toast.makeText(getApplicationContext(), "No scan data received!",
                    Toast.LENGTH_SHORT).show();
        }
    }

    public void playSound() {
        MediaPlayer mp = MediaPlayer.create(InitiatBarCd.this,
                R.drawable.camerasound);
        mp.start();
    }

    @Override    public void onBackPressed() {
        // super.onBackPressed();        finish();
    }
}


3) Class To receive the sequence of Code


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        if (resultCode == 3) {
            String brcode_val = data.getStringExtra("ip_br_code");
            et_po_enty_brcd.setText(brcode_val);
        }
    }
}

Thank You!

Please Leave Your Comment..,

Have A Happy Day..,

Monday, 4 May 2015

Storage On Android

Hi!

In Android to store the data, we are using the fallowing  format

On server :  SQL , MySQL & etc..,
On Local  : SharedPreferences & SQLite

Today i am going to cover about the SQLite. The SQLite is a lightweight library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

Because of it's nature we are using the SQLite to store the data on the OS of ANDROID & IOS, etc..,

In Android we should extends the super class of SQLiteOpenHelper, the Helper class contains two superclass methods onCreate() & onUpgrade(). On the Oncreate method is used to create the tables, the  onUpgrade method is used to Update the tables.
For this class we should create one constructor which will carry the Database details to the superclass.

All the fields should be PRIVATE, STATIC & FINAL.

Android Code : 


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Selvaraj on 4/28/2015.
 */

public class Hotel_DB extends SQLiteOpenHelper
{

    private static final int Db_Version = 1;
    private static final String Db_Name = "hotelvgs3";

    private static final String Tb_booking = "Tb_booking";

    // Field for Room Booking
    final String Book_Rm_ID="IAvil_ID";

    final String Book_Rm_in_fl_date="Book_Rm_in_fl_date";
    final String Book_Rm_out_fl_date="Book_Rm_out_fl_date";
    final String Book_Rm_in_dt="Book_Rm_in_dt";
    final String Book_Rm_in_day="Book_Rm_in_day";
    final String Book_Rm_in_mnth="Book_Rm_in_mnth";
    final String Book_Rm_in_year="Book_Rm_in_year";
    final String Book_Rm_out_dt="Book_Rm_out_dt";
    final String Book_Rm_out_day="Book_Rm_out_day";
    final String Book_Rm_out_mnth="Book_Rm_out_mnth";
    final String Book_Rm_out_year="Book_Rm_out_year";

    final String Book_Rm_adlt="Book_Rm_adlt";
    final String Book_Rm_chld="Book_Rm_chld";

    final String Book_Rm_rom_typ="Book_Rm_rom_typ";
    final String Book_Rm_rom_rate="Book_Rm_rom_rate";
    final String Book_Rm_tot_rom="Book_Rm_tot_rom";

    final String Book_Rm_cust_fname="Book_Rm_cust_fname";
    final String Book_Rm_cust_lname="Book_Rm_cust_lname";
    final String Book_Rm_email="Book_Rm_email";
    final String Book_Rm_mob="Book_Rm_mob";
    final String Book_Rm_adrs="Book_Rm_adrs";
    final String Book_Rm_status="Book_Rm_status";

    final String Book_Rm_ack_tot="Book_Rm_ack_tot";
    final String Book_Rm_ack_advnc="Book_Rm_ack_advnc";






    public Hotel_DB(Context context) {
        super(context, Db_Name, null, Db_Version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String CREATE_BOOKING_TABLE="CREATE TABLE " +Tb_booking+"("+Book_Rm_ID+" INTEGER PRIMARY KEY,"+Book_Rm_in_fl_date+" TEXT," +
                Book_Rm_out_fl_date+" TEXT,"+Book_Rm_in_dt+" TEXT,"+Book_Rm_in_day+" TEXT,"+Book_Rm_in_mnth+" TEXT,"+Book_Rm_in_year+
                " TEXT,"+Book_Rm_out_dt+" TEXT,"+Book_Rm_out_day+" TEXT,"+Book_Rm_out_mnth+" TEXT,"+Book_Rm_out_year+
                " TEXT,"+Book_Rm_adlt+" TEXT,"+Book_Rm_chld+" TEXT,"+Book_Rm_rom_typ+" TEXT,"+Book_Rm_rom_rate+" TEXT,"+Book_Rm_tot_rom+
                " TEXT,"+Book_Rm_cust_fname+" TEXT,"+Book_Rm_cust_lname+" TEXT,"+Book_Rm_email+" TEXT,"+Book_Rm_mob+" TEXT,"+Book_Rm_adrs+
                " TEXT,"+Book_Rm_status+" TEXT, "+Book_Rm_ack_tot+" TEXT, "+Book_Rm_ack_advnc+" TEXT "+")";
        
        db.execSQL(CREATE_BOOKING_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS"+Tb_booking);
        onCreate(db);
    }

    // Add Objects on the table
    public void addBooking(Booking_B Rpl_lst)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(Book_Rm_in_fl_date,Rpl_lst.getBook_Rm_in_fl_date());
        values.put(Book_Rm_out_fl_date,Rpl_lst.getBook_Rm_out_fl_date());
        values.put(Book_Rm_in_dt,Rpl_lst.getBook_Rm_in_dt());
        values.put(Book_Rm_in_day,Rpl_lst.getBook_Rm_in_day());
        values.put(Book_Rm_in_mnth,Rpl_lst.getBook_Rm_in_mnth());
        values.put(Book_Rm_in_year,Rpl_lst.getBook_Rm_in_year());
        values.put(Book_Rm_out_dt,Rpl_lst.getBook_Rm_out_dt());
        values.put(Book_Rm_out_day,Rpl_lst.getBook_Rm_out_day());
        values.put(Book_Rm_out_mnth,Rpl_lst.getBook_Rm_out_mnth());
        values.put(Book_Rm_out_year,Rpl_lst.getBook_Rm_out_year());
        values.put(Book_Rm_adlt,Rpl_lst.getBook_Rm_adlt());
        values.put(Book_Rm_chld,Rpl_lst.getBook_Rm_chld());
        values.put(Book_Rm_rom_typ,Rpl_lst.getBook_Rm_rom_typ());
        values.put(Book_Rm_rom_rate,Rpl_lst.getBook_Rm_rom_rate());
        values.put(Book_Rm_tot_rom,Rpl_lst.getBook_Rm_tot_rom());
        values.put(Book_Rm_cust_fname,Rpl_lst.getBook_Rm_cust_fname());
        values.put(Book_Rm_cust_lname,Rpl_lst.getBook_Rm_cust_lname());
        values.put(Book_Rm_email,Rpl_lst.getBook_Rm_email());
        values.put(Book_Rm_mob,Rpl_lst.getBook_Rm_mob());
        values.put(Book_Rm_adrs,Rpl_lst.getBook_Rm_adrs());
        values.put(Book_Rm_status,Rpl_lst.getBook_Rm_status());
        values.put(Book_Rm_ack_tot,Rpl_lst.getBook_Rm_ack_tot());
        values.put(Book_Rm_ack_advnc,Rpl_lst.getBook_Rm_ack_advnc());

        db.insert(Tb_booking, null, values);
        db.close();
        Log.d("BD Log", "EXECUTIVE SUCESS");
    }

    // Select list of all available records
    public ArrayList<Booking_B> get_All_Booking()
    {
        ArrayList<Booking_B> repay_list=new ArrayList<Booking_B>();
        String sltqry="SELECT * FROM "+ Tb_booking+" ORDER BY "+Book_Rm_cust_fname+" DESC";
        SQLiteDatabase db=this.getWritableDatabase();
        Cursor cursor=db.rawQuery(sltqry, null);
        if(cursor.moveToFirst())
        {
            do{
                Booking_B repy=new Booking_B();
                //exe.setId(String.valueOf(Integer.parseInt(cursor.getString(0))));
                repy.setBook_Rm_in_fl_date(cursor.getString(1));
                repy.setBook_Rm_out_fl_date(cursor.getString(2));
                repy.setBook_Rm_in_dt(cursor.getString(3));
                repy.setBook_Rm_in_day(cursor.getString(4));
                repy.setBook_Rm_in_mnth(cursor.getString(5));
                repy.setBook_Rm_in_year(cursor.getString(6));
                repy.setBook_Rm_out_dt(cursor.getString(7));
                repy.setBook_Rm_out_day(cursor.getString(8));
                repy.setBook_Rm_out_mnth(cursor.getString(9));
                repy.setBook_Rm_out_year(cursor.getString(10));
                repy.setBook_Rm_adlt(cursor.getString(11));
                repy.setBook_Rm_chld(cursor.getString(12));
                repy.setBook_Rm_rom_typ(cursor.getString(13));
                repy.setBook_Rm_rom_rate(cursor.getString(14));
                repy.setBook_Rm_tot_rom(cursor.getString(15));
                repy.setBook_Rm_cust_fname(cursor.getString(16));
                repy.setBook_Rm_cust_lname(cursor.getString(17));
                repy.setBook_Rm_email(cursor.getString(18));
                repy.setBook_Rm_mob(cursor.getString(19));
                repy.setBook_Rm_adrs(cursor.getString(20));
                repy.setBook_Rm_status(cursor.getString(21));
                repy.setBook_Rm_ack_tot(cursor.getString(22));
                repy.setBook_Rm_ack_advnc(cursor.getString(23));
                repay_list.add(repy);
            }
            while (cursor.moveToNext());
        }

        cursor.close();
        db.close();
        return repay_list;
    }

    // Delete on Object from the database
    public void Delete_Booking(Booking_B contact) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(Tb_booking, Book_Rm_cust_fname + " = ?",
                new String[] { String.valueOf(contact.getBook_Rm_cust_fname()) });
        db.close();
    }

    
    // Select list of records by passing one parameter
    public List<Booking_B> get_Single_Bk_Detail_List(String fist_nm)
    {

        List<Booking_B> BBilllist=new ArrayList<Booking_B>();
        SQLiteDatabase db=this.getWritableDatabase();
        Cursor cursor=db.rawQuery("SELECT * FROM "+Tb_booking+" WHERE "+Book_Rm_cust_fname+" = ?",new String[] { fist_nm });
        if(cursor.moveToFirst())
        {
            do{
                Booking_B gn=new Booking_B();
                gn.setBook_Rm_cust_fname(cursor.getString(1));
                gn.setBook_Rm_cust_lname(cursor.getString(2));
                gn.setBook_Rm_mob(cursor.getString(3));
                gn.setBook_Rm_adrs(cursor.getString(4));
                BBilllist.add(gn);
            }
            while(cursor.moveToNext());
        }
        return BBilllist;

    }

    // Update Table By Objects

public int update_Plt_Detail(Mngr_Updt_B mngr_up_likst) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(price, mngr_up_likst.getPrice());
    values.put(status, mngr_up_likst.getStatus());

    return db.update(Tb_Plt_Detail, values, plat_number + " = ?",
            new String[]{String.valueOf(mngr_up_likst.getPlat_number())});
}

}


On The above code the "Booking_B" is the Business class for the Objects.

Lets Enjoy The Android..,

Thank You!

Have A Happy Day..,


Tuesday, 21 April 2015

Working With Google Map On Android Studio

Hi!

Working with Android Studio will make some problem when compare with Eclipse IDE, while working on google map we are using V2 & so on.

But in Android Studio Automatically it will generate the Layout file, if you unable to call the marker, do the fallowing by editing your XML & Java file..,


Layout File :

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>


Java Class:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Agent_Track extends FragmentActivity implements OnMapReadyCallback {

    private SupportMapFragment sMapFragment;
    double LLangi,LLatitude;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agent__track);
        String LL=getIntent().getStringExtra("LLangi");
        String LLe=getIntent().getStringExtra("LLatitude");
        LLangi=Double.valueOf(LL);
        LLatitude=Double.valueOf(LLe);
        sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
        sMapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng one = new LatLng(10.178, 122.560);
        //LatLng zoomg = new LatLng(10.730278, 122.548889);

        //googleMap.setBuildingsEnabled(true);
        //googleMap.setMyLocationEnabled(true);
        //googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        //googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(zoomg , 12));

        googleMap.addMarker(new MarkerOptions()
                .title("Demo Location")
                .snippet("Ha, Ha, Ha..,")
                .position(one)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}


By edit your xml file you can show your location on Map with Marker..,

Thank You!

Have A Happy Day..,

Friday, 13 February 2015

Custom Battery icon and time display

Hi!

          If we wants to create our application should have the uniqueness, we have to crate tour own theme. today i am going to give you the tips and code. How to Custom Our Own Battery Icon & Time Displaying..,


1) On the activity class create your own  Broadcast receiver
2) Have to create own battery icon for according to the status of the battery like..,
(Charging, Battery full, 5%,10,50%,80%,100%  and etc..,)


//TextView for display the Time
TextView header_tv_time;
header_tv_time = (TextView) findViewById(R.id.header_tv_time);
header_tv_time.setText(getCurrentTime());

// ImageView for battery 
ImageView header_imv_btry;
header_imv_btry = (ImageView) findViewById(R.id.header_imv_btry);
this.registerReceiver(this.BRecer, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));

// BroadcastReceiver for Battery 
private BroadcastReceiver BRecer = new BroadcastReceiver() {
@Override
public void onReceive(Context ctxt, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);

if (level == 0) {
header_imv_btry.setImageResource(R.drawable.zero);
} else if (level >= 1 && level <= 5) {
header_imv_btry.setImageResource(R.drawable.five);
} else if (level >= 6 && level <= 10) {
header_imv_btry.setImageResource(R.drawable.ten);
} else if (level >= 11 && level <= 15) {
header_imv_btry.setImageResource(R.drawable.fiften);
} else if (level >= 16 && level <= 20) {
header_imv_btry.setImageResource(R.drawable.twenty);
} else if (level >= 19 && level <= 25) {
header_imv_btry.setImageResource(R.drawable.twentyfive);
} else if (level >= 24 && level <= 30) {
header_imv_btry.setImageResource(R.drawable.thrty);
} else if (level >= 29 && level <= 35) {
header_imv_btry.setImageResource(R.drawable.thrtyfive);
} else if (level >= 36 && level <= 40) {
header_imv_btry.setImageResource(R.drawable.fourty);
} else if (level >= 41 && level <= 45) {
header_imv_btry.setImageResource(R.drawable.fourtyfive);
} else if (level >= 46 && level <= 50) {
header_imv_btry.setImageResource(R.drawable.fifty);
} else if (level >= 51 && level <= 55) {
header_imv_btry.setImageResource(R.drawable.fiftyfive);
} else if (level >= 56 && level <= 60) {
header_imv_btry.setImageResource(R.drawable.sixty);
} else if (level >= 61 && level <= 65) {
header_imv_btry.setImageResource(R.drawable.sixtyfive);
} else if (level >= 66 && level <= 70) {
header_imv_btry.setImageResource(R.drawable.seventy);
} else if (level >= 71 && level <= 75) {
header_imv_btry.setImageResource(R.drawable.seventyfive);
} else if (level >= 76 && level <= 80) {
header_imv_btry.setImageResource(R.drawable.eigty);
} else if (level >= 81 && level <= 85) {
header_imv_btry.setImageResource(R.drawable.eigtyfive);
} else if (level >= 86 && level <= 90) {
header_imv_btry.setImageResource(R.drawable.ninty);
} else if (level >= 91 && level <= 95) {
header_imv_btry.setImageResource(R.drawable.nintyfive);
} else if (level >= 96 && level <= 100) {
header_imv_btry.setImageResource(R.drawable.sentm);
}
}
};

// Method for provide the current time in Hour:Minutes AM / PM
private String getCurrentTime() {
String delegate = "hh:mm aaa";
return (String) DateFormat.format(delegate, Calendar.getInstance()
.getTime());
}


Thats all..,

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,

Friday, 23 January 2015

Image Transaction in Android from Device To Server

Hi!

     Today lot of developer facing problem while  saving and retrieving images in Android from Device To Server and vice versa.

 This blog will be help you to solve this issue.

Step 1 :
call the gallery to select the image

Step 2 :
By using ActivityResultSet() we can receive the image

Step 3 :
Compress the image and convert into string

Code:

ImageView imv_tst_img;   // to set the output of the image
private static Bitmap Image = null; // Bitmap for handle the image compression
Button btn_rg_image;     // for action purpose
String Image_sv;           // to store the image as string

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rg__name);
imv_tst_img=(ImageView) findViewById(R.id.imv_tst_img);
btn_rg_image=(Button) findViewById(R.id.btn_rg_image);

btn_rg_image.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
imv_tst_img.setImageBitmap(null);
if (Image != null)
Image.recycle();
Intent intent = new Intent();
intent.setType("image/*");

// to call the Gallery intent
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"), GALLERY);
}
});
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GALLERY && resultCode != 0) {
Uri mImageUri = data.getData();
try {
// create the Bitmap by using the selected image
Image = Media.getBitmap(this.getContentResolver(), mImageUri);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
Bitmap bit_map = Bitmap.createBitmap(Image, 0, 0,
Image.getWidth(), Image.getHeight());
//compress the bitmap
bit_map.compress(Bitmap.CompressFormat.JPEG, 75, bao);
//converted as byte[] array
byte[] byt_ara = bao.toByteArray();
// Encode by Base64 and save as string
String encoded_btmp = Base64
.encodeToString(byt_ara, Base64.DEFAULT);
// in mycode i pass the string for public use
Image_sv = encoded_btmp;
Log.d("Image_Save", Image_sv);
System.out.println("Image _1 : "+Image_sv);

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

// Revers Process : method to convert the string into Bitmap and set it on the ImageViewer
public void set_Image() {
try {
byte[] decodedString = Base64.decode(Image_sv, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString,
0, decodedString.length);
imv_tst_img.setImageBitmap(decodedByte);
} catch (Exception e) {
// TODO: handle exception
Log.d("ERROR ON IMG", e.getMessage());
}
}

Thats All..,

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,

Thursday, 22 January 2015

How To Make Launcher App in Android

Hi!

    In some situation while the employees are using android device, we need to develop application which should allow the user to use only one particular Enterprise / Business Application, it should block the other application and all activity of the device. It called as Launcher Application.

In this post i am going to give idea only about how to Restrict/Stop all other application while Android device is booting. Because if you try this on your real device all your stored data will be deleted and unable to launch any other applications except your currently launched application.


     In some Business Purpose we need to all employees should work on only one Business Application, We should stop the employee to use the official device for entertainment and other personal purposes.


Work Flow ;


1) In Android we have to stop the Actionbar , Notifications & Other Service.
2) Even if the device is booting we should run our Business application only.


Waning ;


This is not a fun, if you using this technique on your real device, your all data will be lose and this will be your permanent application..,


I have mention everything in this link download , please Download and use carefully..,


Thank You!


Please Leave Your Comment..,


Have A Happy Day..,