Thursday, 14 March 2013

How to Read PDF files in Android?

Read PDF Files from Sdcard in Android

First Create one Android Project in Eclipse after that download PDFViewer.jar file from Internet and then add into project's build path.

After Create one Activity in this Project, Name is

public class Second extends PdfViewerActivity {
    public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    public int getPreviousPageImageResource() {
    return R.drawable.left_arrow;
    public int getNextPageImageResource() {
    return R.drawable.right_arrow;
    public int getZoomInImageResource() {
    return R.drawable.zoom_in;
    public int getZoomOutImageResource() {
    return R.drawable.zoom_out;
    public int getPdfPasswordLayoutResource() {
    return R.layout.pdf_file_password;
    public int getPdfPageNumberResource() {
    return R.layout.dialog_pagenumber;
    public int getPdfPasswordEditField() {
    public int getPdfPasswordOkButton() {
    public int getPdfPasswordExitButton() {
    public int getPdfPageNumberEditField() {

After that Add below code into your project's main activity and change extends Activity to ListActivity in your java file.

public class First extends ListActivity {
    String[] pdflist;
    File[] imagelist;
    public void onCreate(Bundle savedInstanceState) {
    File images = Environment.getExternalStorageDirectory();
    imagelist = images.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
    return ((name.endsWith(".pdf")));
    pdflist = new String[imagelist.length];
    for (int i = 0; i < imagelist.length; i++) {
    pdflist[i] = imagelist[i].getName();
    this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pdflist));
    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String path = imagelist[(int) id].getAbsolutePath();
    private void openPdfIntent(String path) {
    try {
    final Intent intent = new Intent(First.this, Second.class);
    intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
    } catch (Exception e) {

And Don't Forget to Add Second Activity in Android Manifest file.

Enjoy :--)

Monday, 7 January 2013

Custom Toast in Android

First Create New Android Project and after that add below xml file in res/layout folder and add below code into your file.


<LinearLayout xmlns:android=""
    android:background="#ffffff" >
    <ImageView android:id="@+id/image"
        android:layout_marginRight="10dp" />

    <TextView android:id="@+id/text"
        android:textColor="#FFF" />

Add below code into your file

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(;
ImageView image = (ImageView) layout.findViewById(;
TextView text = (TextView) layout.findViewById(;
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);

Enjoy  :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.

How To Send Email In Android

Write below code into your activity file for send Email from Android Application.

Java Code:-

Intent mAndroidEmailIntent = new Intent (android.content.Intent.ACTION_SEND);
String aEmailList[] = { "","" };
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_EMAIL, aEmailList);
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
mAndroidEmailIntent.setType ("plain/text");
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_TEXT, "Email From My Android App");
startActivity (mAndroidEmailIntent);

Enjoy :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.