This blog is about technology, mainly Linux and Android. Mostly I shall share my own learning experience here. Tips and tricks, tutorials etc. I can't promise to be accurate here and welcomes all suggestions. I am getting these information from people and I am sharing it with you, so feel free to comment and spread this knowledge in rest of the world. Please experiment all advice on test systems, no guarantees :)

Tag: Contacts

In my previous posts I have used reading contacts through API calls, however there is an easy method for doing standard tasks by calling system’s pre installed apps. In this post I am going to cover the details of how we can call the system apps through intents.

We are going to create a spinner control for providing the user some options and hit a submit button.

public boolean onContextItemSelected(MenuItem item) { // Call your function to preform for buttons pressed in a context menu // can use item.getTitle() or similar to find out button pressed // item.getItemID() will return the v.getID() that we passed before super.onContextItemSelected(item);

menu.setHeaderTitle(“Context Menu”); menu.add(0, v.getId(), 0, “Contacts”); } public boolean onContextItemSelected(MenuItem item) { // Call your function to preform for buttons pressed in a context menu // can use item.getTitle() or similar to find out button pressed // item.getItemID() will return the v.getID() that we passed before super.onContextItemSelected(item);

Kindly go through my previous post if you are not familier with above code.

We are here in onCreate method; setting the view by setContentView, getting the intent by getIntent, getting the note by getExtras and getString and assigning to second edit text. We are also registering the first edit text for a context menu.

onClickSend is the method registered for “Send” button. Here is the actual code for sending SMS Here we are creating PendingIntent which are a kind of callback mechanism in which we specifies the action need to be performed at a certain event later in lifecycle of application.

registerReceiver defines the method which needs to be performed in the case of event (SMS sent). It has two parameters one is BroadcastReceiver which actually holds the methods needs to be performed. When the onReceive overridden method is called it raises a Toast ( small info window) based on the return value of getResultCode which tells whether the action was prformed well.

Second parameter is a IntentFilter object.

Here’s the toast🙂

After that SmsManager.getDefault returns a sms manager object, which actually send the sms and also registers the PendingIntents.

Overriding onCreateContextMenu definesthe context menu which we have registered for text1 in onCreate. “Contacts” is the only menu item here.

In onContextItemSelected when we find this selected we start a new activity readAllActivity.