btnBrowser = (Button) findViewById(R.id.btnBrowser); btnBrowser.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://google.com.vn")); startActivity(intent); } }); btnSearch = (Button) findViewById(R.id.btnSearch); btnSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, "abc"); startActivity(intent); } }); btnDial = (Button) findViewById(R.id.btnDial); btnDial.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:1234567890")); startActivity(intent); } }); btnShowPicture = (Button) findViewById(R.id.btnShowPicture); btnShowPicture.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); startActivity(intent); } }); btnGoContact = (Button) findViewById(R.id.btnGoContact); btnGoContact.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivity(intent); } }); btnInsertContact = (Button) findViewById(R.id.btnInsertContact); btnInsertContact.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); intent.putExtra(ContactsContract.Intents.Insert.NAME, "Tien"); intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "tienlbhoc@gmail.com"); intent.putExtra(ContactsContract.Intents.Insert.PHONE, "01234567890"); startActivity(intent); } }); btnSendSMS = (Button) findViewById(R.id.btnSendSMS); btnSendSMS.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("sms:")); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("sms_body", "Here you can set the SMS text to be sent"); intent.putExtra("address", "1234567890"); startActivity(intent); } }); btnSendEmail = (Button) findViewById(R.id.btnSendEmail); btnSendEmail.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); intent.putExtra(Intent.EXTRA_EMAIL, "tienlbhoc@gmail.com"); intent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); intent.putExtra(Intent.EXTRA_TEXT, "I'm email body."); startActivity(Intent.createChooser(intent, "Send Email")); } });
Monday, 20 January 2014
Some popular implicit intents in Android
When coding Android, we must do very much with intent (Explicit and implicit) to start activities and applications. Below are some popular implicit intent to start some work like open webbrowser, send mail, sms, open/add contact .... Hoping useful for you.
Labels:
Android,
Open source,
Tip
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment