Friday, 1 June 2012

Implicit intent example


Implicit intent example



intentexampleactivity.java


package a.b;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class IntentexampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ViewContacts();
    }

private void ViewContacts() {
// TODO Auto-generated method stub
try
{
Button b1=(Button)findViewById(R.id.b1);
b1.setOnClickListener(new OnClickListener() {



@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent contacts =new Intent();
contacts.setAction(android.content.Intent.ACTION_VIEW);
contacts.setData(ContactsContract.Contacts.CONTENT_URI);
startActivity(contacts);

}
});
}
catch (ActivityNotFoundException anfe) {
Log.e("view contacts","viewing of contacts failed",anfe);
// TODO: handle exception
}
}
}



main.xml





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<Button android:id="@+id/b1"
android:layout_height="wrap_content"
android:layout_width="228dp"
android:text="view contacts"
android:layout_gravity="center_horizontal">
</Button>
</LinearLayout>



2 comments:

  1. Sir please give Solutions for How to connects two Layouts...
    (How to link existing layout and the new second)?????

    ReplyDelete