Android important code for Application developement
Important implicit intent
1.Open Url
Intent in=new Intent(Intent.ACTION_VIEW,
Uri.parse("https://deepsingh44.blogspot.com/"));
startActivity(in);
2.Open camera
Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(openCamera, CAMERA_PIC_REQUEST);
3.Open gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select image to upload "),CHOOSE_FILE);
4.Dial phone no
Intent in = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "Phone_Number"));
startActivity(in);
5.Call
Intent in = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Phone_Number"));
startActivity(in);
uses-permission ---android:name="android.permission.CALL_PHONE"
6.Send email
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto: xyz@gmail.com"));
startActivity(Intent.createChooser(email, "Send Enquiry.."));
7.Share Content
Intent si = new Intent(android.content.Intent.ACTION_SEND);
si.setType("text/plain");
String body = "Something wants to share...";
si.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subuject ");
si.putExtra(android.content.Intent.EXTRA_TEXT, body);
8.Send sms
Intent sms = new Intent(android.content.Intent.ACTION_VIEW);
sms.setType("vnd.android-dir/mms-sms");
sms.putExtra("address","receiver phoneNumber here");
sms.putExtra("sms_body","Message Here...");
startActivity(sms);
9.Select all audio files
Intent intent;
intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("audio/mpeg");
startActivityForResult(Intent.createChooser(intent, getString(R.string.select_audio_file_title)), REQ_CODE_PICK_SOUNDFILE);
9.For pdf
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
intent.addCategory(Intent.CATEGORY_DEFAULT);
return intent;
How we can handle Uri
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE_PICK_SOUNDFILE && resultCode == Activity.RESULT_OK){
if ((data != null) && (data.getData() != null)){
Uri audioFileUri = data.getData();
// Now you can use that Uri to get the file path, or upload it, ...
}
}
}
Post a Comment