Monday, May 5, 2014

Activity as a dialog box in android



  • Create project named ActivityAsDialog.
  • Add following code in activity_main.xml layout file.

activity_main.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border_t"
    android:padding="20dp"
    android:orientation="vertical" >

    
    <TextView
        android:id="@+id/tvsmsNo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="SMS No"
        android:textSize="28dp"
        android:lines="1"
        android:textColor="#fff" />

    <TextView
        android:id="@+id/tvsmsBody"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="18dp"
        android:layout_marginTop="15dp"
        android:text="Body"
        android:maxLines="10"
        android:textColor="#fff" />

    <Button
        android:id="@+id/btnOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OK"
        android:textSize="28dp"
        android:padding="14dp"
        android:layout_marginTop="15dp"
        android:scrollbars="vertical"
        android:layout_gravity="center" />
    
</LinearLayout>

NOTE: Change root linear layout background "#000000" or set your image.Otherwise it will throw Exception - NoResourceFound.

  • Add following code in MainActivity.java file.

MainActivity.java


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvNo = (TextView)findViewById(R.id.tvsmsNo);
TextView tvBody = (TextView)findViewById(R.id.tvsmsBody);
Button btnOk = (Button)findViewById(R.id.btnOk);
String body = "Hi, How are you?";
tvNo.setText("SMS:9876543210");
tvBody.setText(body);
tvBody.setMovementMethod(new ScrollingMovementMethod());
btnOk.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MainActivity.this.finish();
}
});
}
}


  • Now Add following code in res/values/styles.xml file.

styles.xml



<style name="Theme.UserDialog" parent="android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>
    

  • At Last Change your activity theme in menifest.xml as below.

Menifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activityasadialogbox"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.UserDialog" >
        <activity
            android:name="com.example.activityasadialogbox.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

  • Done ! Now Run project.


Contact List With Checkbox - Part 1




  • Create Project named ContactList.
  • Add following permission in android menifest file.

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



  • Add Following Code in MainActivity.java file

MainActivity.java



import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

MyCustomAdapter dataAdapter = null;
Context context = this;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new LongOperation().execute();

checkButtonClick();

}

private class MyCustomAdapter extends ArrayAdapter<Phonebook> {

private ArrayList<Phonebook> phonebookList;

public MyCustomAdapter(Context context, int textViewResourceId,

ArrayList<Phonebook> pbList) {
super(context, textViewResourceId, pbList);
this.phonebookList = new ArrayList<Phonebook>();
this.phonebookList.addAll(pbList);
}

private class ViewHolder {
TextView name, number;
CheckBox selected;
ImageView imgView;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;

Log.v("ConvertView", String.valueOf(position));

if (convertView == null) {

LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

convertView = vi.inflate(R.layout.blacklist_layout, null);

holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.tvName);
holder.number = (TextView) convertView
.findViewById(R.id.tvNumber);
holder.selected = (CheckBox) convertView
.findViewById(R.id.checkBox1);
holder.imgView = (ImageView) convertView
.findViewById(R.id.imgView);

convertView.setTag(holder);

holder.selected.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Phonebook _state = (Phonebook) cb.getTag();
_state.setChecked(cb.isChecked());
}
});

} else {
holder = (ViewHolder) convertView.getTag();
}

Phonebook state = phonebookList.get(position);

holder.name.setText(state.getName());
holder.number.setText(state.getNumber());
holder.selected.setChecked(state.isChecked());
Log.v("getImgUri", "" + state.getImgUri());
holder.imgView.setImageURI(state.getImgUri());
if (holder.imgView.getDrawable() == null) {
holder.imgView.setImageResource(R.drawable.ic_launcher);
}
holder.selected.setTag(state);
return convertView;
}

}

private void checkButtonClick() {

Button myButton = (Button) findViewById(R.id.findSelected);

myButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
ArrayList<Phonebook> stateList = dataAdapter.phonebookList;
StringBuffer sb = new StringBuffer();

for (int i = 0; i < stateList.size(); i++) {
Phonebook state = stateList.get(i);
if (state.isChecked()) {
//Get selected contact information
//sb.append("\nImage URI:" + state.getImgUri().toString());
sb.append("\nName:" + state.getName());
sb.append("\nNumber:" + state.getNumber());
sb.append("\n-----");
}
}
Toast.makeText(context, ":" + sb.toString(), Toast.LENGTH_LONG)
.show();
}
});
}

ProgressDialog mProgressDialog;
Intent i;

private class LongOperation extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

runOnUiThread(new Runnable() {

@Override
public void run() {

ArrayList<Phonebook> phonebookList = new ArrayList<Phonebook>();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(
ContactsContract.Contacts.CONTENT_URI, null, null,
null, null);

if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

if (Integer
.parseInt(cur.getString(cur
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {

// get the phone number
Cursor pCur = cr
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?",
new String[] { id }, null);
while (pCur.moveToNext()) {
String phone = pCur
.getString(pCur
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Uri uri = Utils
.getPhotoUri(
Long.parseLong(Utils
.fetchContactIdFromPhoneNumber(
phone,
context)),
context);

// ---------------------------------------------------------------------------
Phonebook _states = new Phonebook(name,
phone, false, uri);
phonebookList.add(_states);
// ---------------------------------------------------------------------------
}
pCur.close();

}
}
// create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(MainActivity.this,
R.layout.blacklist_layout, phonebookList);
ListView listView = (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
}
});
}

}
});

return null;
}

@Override
protected void onPostExecute(Void result) {
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}

}

@Override
protected void onPreExecute() {
ShowLoading();
}

@Override
protected void onProgressUpdate(Void... values) {

}

}

private void ShowLoading() {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Loading Contacts ....");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
}


  • Add XML code in layout file, activity_main.xml

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            style="@style/titlebar_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:textSize="18dp"
            android:text="Contacts" />

        <Button
            android:id="@+id/findSelected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="Save"
            android:textColor="#ffffff" />
    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="#BC0061"
        android:dividerHeight="2dp"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:padding="10dp" />

</LinearLayout>

After Added above code you will get error in some code but don't worry.Go to step 2 and add remaining code.




Contact List With Checkbox - Part 2





  • Create new Class file, named Phonebook.java.

Phonebook.java



package com.example.contactlist;

import android.net.Uri;

public class Phonebook {

String number = null,name = null;
boolean isChecked = false;
Uri imgUri = null;
public Phonebook(String name,String number,boolean selected,Uri uri){
super();
this.name = name;
this.imgUri = uri;
this.isChecked = selected;
this.number = number;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isChecked() {
return isChecked;
}

public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}

public Uri getImgUri() {
return imgUri;
}

public void setImgUri(Uri imgUri) {
this.imgUri = imgUri;
}
}

  • Create another class file,named Utils.java

Utils.java

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;

public class Utils {

public static String fetchContactIdFromPhoneNumber(String phoneNumber,Context context) {
// TODO Auto-generated method stub

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));
Cursor cFetch = context.getContentResolver().query(uri,
new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup._ID },
null, null, null);

String contactId = "";

if (cFetch.moveToFirst()) {

cFetch.moveToFirst();

contactId = cFetch
.getString(cFetch.getColumnIndex(PhoneLookup._ID));

}

System.out.println(contactId);
return contactId;

}

public static Uri getPhotoUri(long contactId,Context context) {
ContentResolver contentResolver = context.getContentResolver();

try {
Cursor cursor = contentResolver
.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID
+ "="
+ contactId
+ " AND "

+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
+ "'", null, null);

if (cursor != null) {
if (!cursor.moveToFirst()) {
return null; // no photo
}
} else {
return null; // error in cursor process
}

} catch (Exception e) {
e.printStackTrace();
return null;
}

Uri person = ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, contactId);
return Uri.withAppendedPath(person,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}
}


  • Create layout xml file in res/layout,named blacklist_layout.xml

blacklist_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingLeft="3dip"
    android:paddingRight="3dip"
    android:paddingTop="3dip"
    android:paddingBottom="1dip" >

    <ImageView
        android:id="@+id/imgView"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:padding="5dp"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left|center"
        android:orientation="vertical"
        android:padding="6dip" >

        <TextView
            android:id="@+id/tvName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:textStyle="bold"
            android:textSize="15dp"
            android:textColor="#000" />

        <TextView
            android:id="@+id/tvNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Number"
            android:textSize="15dp"
            android:textColor="#000" />
    </LinearLayout>

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="right"
        android:textColor="#B40404" />

</LinearLayout>


  • Last but not the least, Add following code in styles.xml file.


<style name="titlebar_textview">
        <item name="android:textColor">#fff</item>
        <item name="android:textStyle">bold</item>
        <item name="android:padding">10dp</item>
    </style>

  • Done ! Now Run Program.

Download Full Source Code:Download Here !

Friday, May 2, 2014

AdSense Secrets 5 PDF FREE Download



Google AdSense is the powerful way to earn money from your online content . Getting AdSense approval itself is a difficult task these days and once approved , you can earn good income from your site.

But only 10% of AdSense owners are really making a nice income from it .Why? . The reason is another 90% are not effectively implemented AdSense on their website/blog.

After searching for a good AdSense e-book , I finally landed in the right place . AdSense Secrets 5  is  an e-book written by Joel Comm , who make hundreds of dollars per day with Google AdSense.  This is the best e-book I purchased this year.

Now you can download this E-book for free and I hope this will help you a lot in making your online revenue.

Download for FREE: FREE Download !


Tuesday, December 10, 2013

FTP Multiple files download in android


Here is the full source code,To Connect,authenticate and get files from FTP Server.Below requirements are needed for successfully connections.

Requirements:

  1. FTP server URL
  2. Username and Password

Steps:

  1. First of all we need to connect the FTP server using its URL.
  2. after successfully connection you need to authenticate and access your files.
  3. After login you can get all files and directories list.
  4. Now the main part is to get files one by one and save in your local device.

Here is the full source code for this operation, check below source code carefully.

import java.io.File;
import java.io.FileOutputStream;
import java.net.InetAddress;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

import android.content.Context;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

public class Downloads implements Runnable{

String TAG = "Downloads";
int fl = 0;
Context c ;
public Downloads(Context context) {
try {
final FTPClient ftp = new FTPClient();
final File dir = new File(Environment.getExternalStorageDirectory()
+ "/Android_guide");

if (!dir.exists()) {
dir.mkdir();
}
FTPFile[] filesList = null;
                        //FTP Server connection
ftp.connect(InetAddress.getByName("FTP file URL"));
//FTP username and password authentication
                        ftp.login("Username", "Password");
ftp.enterLocalPassiveMode();
//To change directory of FTP Server 
                        // ftp.changeWorkingDirectory("/");
filesList = ftp.listFiles("");
ftp.setFileType(FTP.BINARY_FILE_TYPE);
Log.v("Coneection and login", "Successfully");
// -----------------------------
while (fl < filesList.length) {
try {
Log.v("File name", filesList[fl].getName());
boolean status = false;
try {
                          FileOutputStream desFileStream = new FileOutputStream(
dir+ dir.separator+ filesList[fl].getName());

status = ftp.retrieveFile(filesList[fl].getName(),desFileStream);
Log.v("status", "" + status);
desFileStream.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
              e.printStackTrace();
}
fl++;
}
ftp.logout();
ftp.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}

  • Thats it. But dont forget to give permission for WRITE EXTERNAL STORAGE
Add following permission in android menifest file.

android.permission.WRITE_EXTERNAL_STORAGE


To configure your project with FTP, You need to download following libraries.

  1. org.apache.commons.net_2.0.0.v200905272248.jar
  2. commons-net-1.4.1.jar

Download above libraries Here

Monday, December 9, 2013

Seekbar in android

Here is the full tutorial for seekbar in android.It is used to set range of value.You can also set background image of seekbar for some value.

Here is the tutorial for seekbar,It displays the value of seekbar in Edittext and also change the color of seekbar.

Source Code:


  • Create one project and copy below code in activity_main.xml file

activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="center"
    android:padding="20dp" >

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.71"
        android:max="100"
        android:progress="0" />

    <EditText
        android:id="@+id/et"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.21" />

</LinearLayout>


  • Write below code in MainActivity.java file.

MainActivity.java


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class MainActivity extends Activity {

SeekBar sb;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sb = (SeekBar)findViewById(R.id.seek_bar);
et= (EditText)findViewById(R.id.et);
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
et.setText(""+progress);
if(progress>=50 && progress<70){
sb.setBackgroundColor(Color.RED);
}else if(progress>=70){
sb.setBackgroundColor(Color.YELLOW);
}else if(progress<50){
sb.setBackgroundColor(Color.TRANSPARENT);
}
}
});
}
}

  • That's It. Now run the project and see the output.


Sunday, November 24, 2013

Download file in Android application


You can download files in your android application without UI freeze.If your application has download file then you have to use threading or AsyncTask function.Which process in back end and without freeze the UI.

Here is the full tutorial,How to set download file function without freeze the UI.


  • First of all create new project named it 'Download file'.
  • Open activity_main.xml file and add below code in it.

activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button android:id="@+id/btnProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Download File"
        android:layout_marginTop="50dip"/>

</LinearLayout>




  • Now Open MainActivity.java file and add below code.

MainActivity.java


public class MainActivity extends Activity {

Button btnShowProgress;
private ProgressDialog pDialog;
public static final int progress_bar_type = 0; 
private static String file_url = "https://docs.google.com/uc?export=download&id=0B9w-wpPugvRfUUZDdWhtNU5qN1k";

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

btnShowProgress = (Button) findViewById(R.id.btnProgressBar);
btnShowProgress.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
new DownloadFileFromURL().execute(file_url);
}
});
}

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}

class DownloadFileFromURL extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}

@Override
protected String doInBackground(String... f_url) {
int count;
       try {
           URL url = new URL(f_url[0]);
           URLConnection conection = url.openConnection();
           conection.connect();
           // getting file length
           int lenghtOfFile = conection.getContentLength();

           // input stream to read file - with 8k buffer
           InputStream input = new BufferedInputStream(url.openStream(), 8192);
           
           // Output stream to write file
           OutputStream output = new FileOutputStream("/sdcard/downloadedfile.pdf");

           byte data[] = new byte[1024];

           long total = 0;

           while ((count = input.read(data)) != -1) {
               total += count;
               // publishing the progress....
               // After this onProgressUpdate will be called
               publishProgress(""+(int)((total*100)/lenghtOfFile));
               
               // writing data to file
               output.write(data, 0, count);
           }

           // flushing output
           output.flush();
           
           // closing streams
           output.close();
           input.close();
           
       } catch (Exception e) {
        Log.e("Error: ", e.getMessage());
       }
       
       return null;
}
protected void onProgressUpdate(String... progress) {
// setting progress percentage
            pDialog.setProgress(Integer.parseInt(progress[0]));
       }

@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
// Displaying downloaded image into image view
// Reading image path from sdcard
String imagePath = Environment.getExternalStorageDirectory().toString() + "/downloadedfile.pdf";
}

}
}


  • Add Internet and Write Eternal Storage permissions in AndroidMenifest file.

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