Monday, July 27, 2015

Most Used Intents in Android

5:41 PM

These intents are called Explicit Intents in Android, because you make a call that indicates exactly which activity class to work with. Remember these as Explicit Activity Calls.

Launch Another Activity

 Intent intent = new Intent(getApplicationContext(), NextActivity.class);

Pass value to another activity via Intent putExtra

pass value:

Intent intent = new Intent(getApplicationContext(), NextActivity.class);
intent.putExtra("user_id", 10);

receive value onCreate of NextActivity:

String user_id = "";
Bundle extras = getIntent().getExtras();

if(extras != null) {
    user_id = extras.getString("user_id", null);

Open Dialer with Phone Intent

Intent intent = new Intent(Intent.ACTION_DIAL);

Open Google Maps Intent from address:

 String address = tvaddress.getText().toString(); // Get addressaddress = address.replace(" ", "+");
Intent geoIntent = new Intent (android.content.Intent.ACTION_VIEW, Uri.parse ("geo:0,0?q=" + address)); // Prepare intentstartActivity(geoIntent); // Initiate lookup

Open Google Maps Intent from lat long

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", lat, lng);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));


String uri = "" + lat + "," + lng + " (" + youraddress + ")";


String uri = ",0?q=" + youraddress

Open Google Maps Intent given address string

String uri = "" + youraddress;

Open Email Programs, Specify email address and / or subejct:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle thisemailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback to Semicolon Developers");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Hey,\n\n");
startActivity(Intent.createChooser(emailIntent, "Send Feedback..."));

Share Dialog Intent:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "this is your text to share");
startActivity(Intent.createChooser(intent, "Share with"));

Open Website URL

String url = "";
Intent i = new Intent(Intent.ACTION_VIEW);

Written by

We are passionate programmers. Enjoying the rich platforms of Semicolon Family of Programming languages we are proud to call ourselves Semicolon Developers.


Post a Comment


© 2013 Echo "Semicolon Developers"; Kathmandu. All rights resevered @ Semicolon Developers Network Pvt. Ltd.. Designed by Templateism

Back To Top