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);
startActivity(intent);


Pass value to another activity via Intent putExtra


pass value:


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


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);
intent.setData(Uri.parse("tel:"+phone.getText().toString()));
startActivity(intent);

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));
context.startActivity(intent);

or

String uri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + youraddress + ")";

or

String uri = "http://maps.google.com/maps?q=geo:0,0?q=" + youraddress


Open Google Maps Intent given address string

String uri = "http://maps.google.co.in/maps?q=" + 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[] {"info@semicolondev.com"});
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.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "this is your text to share");
startActivity(Intent.createChooser(intent, "Share with"));


Open Website URL

String url = "http://semicolondev.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);



Written by

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

1 comments:

  1. They also provide great deposit bonuses such as their fantastic dafabet one hundred pc up to as} $1000 on line casino welcome bonus. It is always necessary to check along with your native laws to ensure you|to make sure you} are throughout the legal playing age at on-line playing websites. Best on-line casinothat presents great cellular performance whether by a devoted downloadable app or cellular adapted browser.

    ReplyDelete

 

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

Back To Top