Sunday, May 12, 2013

Send Xml Data From Android to PHP server


package com.example.sendxmltest;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost("http://10.0.2.2/server_log/index.php");

   try {
       StringEntity se = new StringEntity( "<aaaLogin inName=\"admin\" inPassword=\"admin123\"/>", HTTP.UTF_8);
       se.setContentType("text/xml");
       httppost.setEntity(se);

       HttpResponse httpresponse = httpclient.execute(httppost);
       HttpEntity resEntity = httpresponse.getEntity();
       Log.e("test",EntityUtils.toString(resEntity));
       //tvData.setText(EntityUtils.toString(resEntity));

   } catch (ClientProtocolException e) {
       // TODO Auto-generated catch block
    Log.e("test",e.getMessage());
       e.printStackTrace();
   } catch (IOException e) {
       // TODO Auto-generated catch block
    Log.e("test",e.getMessage());
    e.printStackTrace();
   }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


PHP code to receive xml data 

<?php
  /*
   * XML Server.
   */
  // We use php://input to get the raw $_POST results.
  $xml_post = file_get_contents('php://input');
  // If we receive data, save it.
  if ($xml_post) {
    $xml_file = 'received_xml_' . date('Y_m_d-H-i-s') . '.xml';
    $fh       = fopen($xml_file, 'w') or die();
    fwrite($fh, $xml_post);
    fclose($fh);
    // Return, as we don't want to cause a loop by processing the code below.
echo "data xml --".$xml_post;
  }
 // print_r($_SERVER);
  
  return;
?>


Saturday, May 4, 2013

Android CutomArrayAdapter with CheckBox

Contact.java


package com.example.testandroid;

public class Contact {
    public String name;
    public String phone;
    public Boolean selected;
    public Contact()
    {
   
    }
    public Contact(String name,String phone){
    this.name=name;
    this.phone=phone;
    this.selected=false;
    }
}

ContactsAdapter.java


package com.example.testandroid;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class ContactsAdapter extends ArrayAdapter<Contact>{

    Context context;
    int layoutResourceId,temp;  
    ArrayList<Contact> data;
   
    public ContactsAdapter(Context context, int layoutResourceId, ArrayList<Contact> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ContactHolder holder = null;
        Contact contact = data.get(position);
        final int pos=position;
        temp=position;
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
           
            holder = new ContactHolder();
            holder.name = (TextView)row.findViewById(R.id.name);
            holder.phone = (TextView)row.findViewById(R.id.mobile);
            holder.chkBox = (CheckBox)row.findViewById(R.id.chk_sel);
            holder.chkBox.setOnClickListener( new View.OnClickListener() {
                public void onClick(View v) {
                 CheckBox cb = (CheckBox) v ;
                 //Contact contact = (Contact) cb.getTag();
                 Toast.makeText(context,"Clicked on Checkbox: " + data.get(pos).name +" is " + cb.isChecked(),Toast.LENGTH_LONG).show();
                 data.get(pos).selected=cb.isChecked();
                 }
               });
            row.setTag(holder);
        }
        else
        {
            holder = (ContactHolder)row.getTag();
        }
       
       
        holder.name.setText(contact.name);
        holder.phone.setText(contact.phone);
       
        return row;
    }
   
    static class ContactHolder
    {
    TextView name;
        TextView phone;
        CheckBox chkBox;
    }
}

MainActivity.java


package com.example.testandroid;

import java.util.ArrayList;
import java.util.ListIterator;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
    ArrayList<Contact> mContacts;
    ListView listView1;
    ContactsAdapter adapter;
    String mAction;
    ListIterator<Contact> litr ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContacts=new ArrayList<Contact>();

for(int i=0;i<10;i++)
{
Contact c=new Contact("name"+i,"9748544"+i);
mContacts.add(c);
}

adapter = new ContactsAdapter(this,R.layout.container, mContacts);
               
        listView1 = (ListView)findViewById(R.id.lisstview);
     
        listView1.setAdapter(adapter);
}

// Initiating Menu XML file (menu.xml)
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }
   
    public void add_edit_dialog(String title,String action){
    mAction=action;
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.add_edit_dialog, null);
        Dialog d= new AlertDialog.Builder(MainActivity.this)
            .setTitle(title)
            .setView(textEntryView)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                String name,phoneno;
                EditText et_name,et_phone;
                et_name=(EditText)textEntryView.findViewById(R.id.name_edit);
                et_phone=(EditText)textEntryView.findViewById(R.id.mobile_edit);
                name=et_name.getText().toString();
                phoneno=et_phone.getText().toString();
                if(mAction.equals("add"))
                {
                Contact c=new Contact(name,phoneno);
                mContacts.add(c);
                listView1.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                }
                else if(mAction.equals("edit"))
                {
                Toast.makeText(getApplicationContext(), "mae="+name, Toast.LENGTH_LONG).show();
                litr = mContacts.listIterator();
                while (litr.hasNext()) {
                Contact element = litr.next();
                         if(element.selected==true)
                      {
                          element.name=name;
                          element.phone=phoneno;
                      }
                Log.e("test","name is "+element.name);
               
                }
                listView1.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                }
                    /* User clicked OK so do some stuff */
                }
            })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked cancel so do some stuff */
                }
            })
            .create();
        d.show();
    }
   
    /**
     * Event Handling for Individual menu item selected
     * Identify single menu item by it's id
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
       
        switch (item.getItemId())
        {
        case R.id.menu_add:
            // Single menu item is selected do something
            // Ex: launching new activity/screen or show alert message
            Toast.makeText(MainActivity.this, "Add is Selected", Toast.LENGTH_SHORT).show();
            add_edit_dialog("Add Contact","add");
            return true;

        case R.id.menu_edit:
            Toast.makeText(MainActivity.this, "Edit is Selected", Toast.LENGTH_SHORT).show();
            add_edit_dialog("Edit Contact","edit");
            return true;

        case R.id.menu_del:
            Toast.makeText(MainActivity.this, "del is Selected", Toast.LENGTH_SHORT).show();
            litr = mContacts.listIterator();
            while (litr.hasNext()) {
           Contact element = litr.next();
           if(element.selected==true)
        {
            litr.remove();
        }
         
            }
            /* for(int i=0;i<mContacts.size();i++)
            {
            if(mContacts.get(i).selected==true)
            {
            mContacts.remove(i);
            }
            }*/
            listView1.setAdapter(adapter);
            adapter.notifyDataSetChanged();
            return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    }  

}


activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/lisstview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />

</RelativeLayout>

add_edit_dialog.xml

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

    <TextView 
        android:id="@+id/name_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:text="Name"
        android:gravity="left"
        android:textAppearance="?android:attr/textAppearanceMedium" />
            
    <EditText
        android:id="@+id/name_edit"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:scrollHorizontally="true"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="fill_horizontal"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/mobile_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:text="Mobile no"
        android:gravity="left"
        android:textAppearance="?android:attr/textAppearanceMedium" />
            
    <EditText
        android:id="@+id/mobile_edit"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:scrollHorizontally="true"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="fill_horizontal"
        android:password="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />
        
</LinearLayout>

container.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:weightSum="4"
    android:layout_height="match_parent">
<LinearLayout
   android:layout_height="wrap_content"
   android:layout_width="0dp"
   android:orientation="vertical"
   android:layout_weight="3">
   <TextView
       android:id="@+id/name"
       android:text="Name"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
   </TextView>
   <TextView
       android:paddingLeft="10dp"
       android:id="@+id/mobile"
       android:text="Mobile"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
   </TextView>
    </LinearLayout>
    <LinearLayout
   android:layout_height="wrap_content"
   android:layout_width="0dp"
   android:gravity="center"
   android:layout_weight="1">
   <CheckBox
        android:id="@+id/chk_sel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
    </LinearLayout>

    

</LinearLayout>


menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_add"
          android:title="Add" />
 
    <item android:id="@+id/menu_del"
          android:title="Delete" />
 
    <item android:id="@+id/menu_edit"
          android:title="Edit" />
   
</menu>







Friday, March 29, 2013

XmlPullParsers sample Code

Book.java


package com.eaxmple.xmlpullparser.classess;

public class Book {
public String bookId;
public String author;
public String title;
public String genre;
public String publish_date;
public String desc;
public double price;
}


BookParser.java


package com.eaxmple.xmlpullparser.parsers;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.Context;
import android.util.Log;

import com.eaxmple.xmlpullparser.classess.Book;

public class BookParser {
List<Book> mBooksList;
String mXmlFilePath;
Context mContext;
XmlPullParser xpp;
Book tempBook;

public BookParser(Context context,String filePath){
mBooksList=new ArrayList<Book>();
mContext=context;
mXmlFilePath=filePath;
}

public List<Book> parse() throws Exception{
InputStream istr = mContext.getAssets().open(mXmlFilePath);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
xpp = factory.newPullParser();
xpp.setInput(istr, "UTF-8");
int eventType = xpp.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT)
        {
          if(eventType == XmlPullParser.START_TAG)
        {
         
           String startTag=xpp.getName();
        if(startTag.equals("book"))
        {
        tempBook=new Book();
        Map<String,String> attributes = getAttributes(xpp);
        tempBook.bookId=attributes.get("id");
        }
        else if(startTag.equals("author"))
        {
        tempBook.author=xpp.nextText();
        }
        else if(startTag.equals("title"))
        {
        tempBook.title=xpp.nextText();
        }
        else if(startTag.equals("genre"))
        {
        tempBook.genre=xpp.nextText();
        }
        else if(startTag.equals("price"))
        {
        tempBook.price=Double.parseDouble(xpp.nextText());
        }
        else if(startTag.equals("publish_date"))
        {
        tempBook.publish_date=xpp.nextText();
        }
        else if(startTag.equals("description"))
        {
        tempBook.desc=xpp.nextText();
        }
        }
        else if(eventType == XmlPullParser.END_TAG)
        {
        String endTag=xpp.getName();
        System.out.println("End Tag "+endTag);
        if(endTag.equals("book"))
        {
        mBooksList.add(tempBook);
        }
        }
        eventType = xpp.next();
        }
       return mBooksList;
}

private Map<String,String>  getAttributes(XmlPullParser parser) throws Exception {
   Map<String,String> attrs=null;
   int acount=parser.getAttributeCount();
   if(acount != -1) {
       attrs = new HashMap<String,String>(acount);
       for(int x=0;x<acount;x++) {
           attrs.put(parser.getAttributeName(x), parser.getAttributeValue(x));
       }
   }
   else {
       throw new Exception("Required entity attributes missing");
   }
   return attrs;
}

}

MainActivity.java

package com.example.xmlpullparser;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.eaxmple.xmlpullparser.classess.Book;
import com.eaxmple.xmlpullparser.parsers.BookParser;

public class MainActivity extends Activity {
ArrayList<Book> books;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BookParser bookParser=new BookParser(this,"xml/books.xml");
try {
books=(ArrayList<Book>) bookParser.parse();
System.out.println(books.size());
Toast.makeText(getApplicationContext(), "count is"+books.size(), Toast.LENGTH_LONG).show();
for(int i=0;i<books.size()-1;i++)
{
Log.e("xmlPullparser","book id="+books.get(i).bookId+" book name="+books.get(i).title);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

Assest/xml/books.xml

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious 
      agent known only as Oberon helps to create a new life 
      for the inhabitants of London. Sequel to Maeve 
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters, 
      battle one another for control of England. Sequel to 
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology 
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in 
      detail, with attention to XML DOM interfaces, XSLT processing, 
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
   </book>
</catalog>

Monday, August 13, 2012

Android Google Map Integration

Below are the steps for Integrating google map into your android application

1.Getting the Google Api(Libraries)

In Eclipse Goto Window->Android SDK Manager , then select Google Api's(if not installed) then select Install packeges . 
This will give you the jar files required to integrate Google map

2.Obtaining a Maps API Key


Beginning with the Android SDK release v1.0, you need to apply for a free Google Maps API key before you can integrate Google Maps into your Android application. To apply for a key, you need to follow the series of steps outlined below. You can also refer to Google's detailed documentation on the process at http://code.google.com/android/toolbox/apis/mapkey.html
First, if you are testing the application on the Android emulator, locate the SDK debug certificate located in the default folder of "C:\Documents and Settings\<username>\Local Settings\Application Data\Android". The filename of the debug keystore is debug.keystore. For deploying to a real Android device, substitute the debug.keystore file with your own keystore file. In a future article I will discuss how you can generate your own keystore file.
For simplicity, copy this file (debug.keystore) to a folder in C:\ (for example, create a folder called "C:\Android").
Using the debug keystore, you need to extract its MD5 fingerprint using the Keytool.exe application included with your JDK installation. This fingerprint is needed to apply for the free Google Maps key. You can usually find the Keytool.exefrom the "C:\Program Files\Java\<JDK_version_number>\bin" folder.
Issue the following command to extract the MD5 fingerprint.
keytool.exe -list -alias androiddebugkey -keystore "C:\android\debug.keystore" -storepass android -keypass android

3.Include jar Files into your Project for maps

      Right click on your project and go to build path and then add external archives.
      Locate your sdk.  
      android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps

4.Displaying the Map
Below are the code for integrating Google Map into android app

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="net.learn2develop.GoogleMaps"
      android:versionCode="1"
      android:versionName="1.0.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
 
    <uses-library android:name="com.google.android.maps" />  
 
        <activity android:name=".MapsActivity"
                  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>
 
    <uses-permission android:name="android.permission.INTERNET" />
 
</manifest>
</xml>


Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
 
    <com.google.android.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0l4sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ"
        />
 
</RelativeLayout>

MapsActivityDemo.java (your Activity class)
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
 
public class MapsActivityDemo extends MapActivity 
{    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
 
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

Thursday, April 19, 2012

Sending SMS programatically

There are two ways to send sms in android

1.Using smsManager
2.Using Intent

1.Using smsManager
private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
 new Intent(this, SMS.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    } 
 Add this permission in manifest file 
<uses-permission android:name="android.permission.SEND_SMS">
 
2.Using Intent 
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
       sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
       sendIntent.setType("vnd.android-dir/mms-sms");
       startActivity(sendIntent); 
 
 
You can get more details from the following site
http://mobiforge.com/developing/story/sms-messaging-android
   
 

Tuesday, April 17, 2012

Content Provider and Content Resolver

A ContentProvider is a generic mechanism for an application to provide
access to data. This is done by subclassing ContentProvider,
implementing certain methods, and publishing information in the manifest.

To access data provided by ContentProvider(s), you use ContentResolver.
There is no need to subclass.

http://developer.android.com/guide/topics/providers/content-providers...

This mechanism is used in certain Google applications.

Some of those, but not all, are considered to be part of the SDK, and
can be used by other applications as well:

http://developer.android.com/reference/android/provider/package-summa...

Some others are internal, and should not be used by other applications.

These internal providers can change at any time: with a new Android
release, a new version of a Google application, or even when Android is
customized by a device manufacturer.

These include Calendar and GMail, and perhaps more. It's not a good idea
to use them in your application.

If you do, and make it work somehow, be aware that your code can break
at any time.

Friday, April 13, 2012

Calling finish() on an Android activity doesn't actually finish

You should put a return statement after that finish, because the method that called finish will be executed completely otherwise.
 
The method that called finish() will run to completion. The finish() operation will not even begin until you return control to Android.

suppose you have a method xyz like below

xyz()
{
statment1
statement2
.
.
finish();
statement6
statement7
}

Then the finish() function will be called after statement7 is executed and the control has returned to android.

So , if you want your app to finish() immediately then put a return statement after finish(), Like below
xyz()
{
statment1
statement2
.
.
finish();
return;
statement6
statement7

}

Statement6 and statement7 will not be executed any more