I'd like to set up something to launch the built-in contact picker, and let a user choose an email, phone number, etc, then get said address/phone number back in my activity.
Am I correct in assuming that this isn't possible with android? It seems like you have to at least build a dialog yourself to choose in the case where a contact has multiple phone numbers/emails.
Even before that though, there doesn't seem to be a way to choose both phone numbers and emails simultaneously.
Is something like https://github.com/codinguser/android_contact_picker or rolling your own UI the only way to go?
Its perfectly possible and straight forward with android. You don't need to create any dialog box or anything for it. Just lauch the built in contact picker Activity via an Intent.
It you have to launch the intent from some event handler
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
You should also have to implement
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
to receive URI of the contact user picked.
Thousands of tutorials are available on INTERNET on how to do it. Google is your friend.
Here is one http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/
Related
I'm trying to open a pdf file from my app , on my device currently installed 3 3rd party apps to open pdf file. when the system asks me on witch of them to open the pdf, how can i know if the user selects one and presses "ok" or "decline"? my actions defined by if he accepts or declines
This is in my class :
String path="...../file.pdf";
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "application/pdf");
startActivityForResult(intent, 225);
And then in the activity :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == 225) {
// Make sure the request was successful if (resultCode == RESULT_OK)
} else {
}
}
screen shot for example
You can find all of the apps on the device that can service your Intent using the following code:
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
You can use the information from this to query the packages and learn their display name and icons (SO has plenty of answers how to do that).
You can create your own Dialog from within your app that looks identical to the system dialog. In this way you'll be able to track hits and pass the intent to the selected package directly.
Good luck!
how can i know if the user selects one and presses "ok" or "decline"?
You can't. ACTION_VIEW that is used to open a pdf in an external app does not give back any information. You can use startActivityForResult() but it will not have any effect because a result will not be set. Also see ACTION_VIEW documentation.
You should redesign your concept/logic so that it does not depend on this information.
I am looking for a light easy way, to pick an image from a gallery, and pass to another intent/activity the image selected.
This is what I have but I know it is wrong, I was just looking for some quick insight.
I know this opens up an image to be selected, but once it's selected, nothing happens, it does not load my intent. I am aware, from my belief once the image is selected it is just not dong anything and is returning true or w.e. when chosen and not providing anything, to which I ask if I need some more methods to be called that I haven't included? thank you.
Code:
item.getTitle().equals("Upload")) {
// TODO might want to pass parameter of what fragment is loaded.
// Switch to upload activity to allow for uploading of images.
Intent uploadIntent = new Intent(this, UploadActivity.class);
uploadIntent.setType("image/*");
uploadIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(uploadIntent, "Select Picture"),
PICK_IMAGE);
//startActivity(uploadIntent);
}
I'm not sure I fully understand your requirements but if you're ok with launching the default system image gallery, then the following post may help you:
How to pick an image from gallery (SD Card) for my app?
The general idea is to request a new Activity handle an Intent requesting a result (startActivityForResult()). If an Activity is setup to receive the intent (ACTION_GET_CONTENT) then it will launch and handle your request. Once the request is complete, the Activity will return a result which your Activity will recieve in it's method
onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent);
im trying to take a picture inside an android app, and im trying to use the android devloper tutorial:
http://developer.android.com/training/camera/photobasics.html
they bring the following code:
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
}
i can't understand what is this action code and what it should be for taking pictures
thanks!
Per Getting a Result from an Activity, the second parameter to startActivityForResult is used to distinguish between multiple different requests (say, if you got results from both the camera and the gallery you'd want to know where the result is from).
That same actionCode is then returned as the requestCode in onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
The point is that it doesn't matter exactly what the number is (0, 1, 100, 5439, whatever), only that it is unique within your Activity. Therefore if you are only calling startActivityForResult in one place for one result, any number will do (as there is nothing to conflict with)
Intents are designed to allow your application to interact with others. In this case, your application will bring up the camera app, and the result will be sent back into your app.
A great place to get started with understanding this is, is the Android training "Interacting with Other Apps".
I'm invoking android native calculator from my app, how do i get result data from it.. means i started native calender like this, after finishing calculation i press back onActivityResult is executed and data returned is null, how to get calculated data.. Help me
Intent i = new Intent();
i.setClassName("com.android.calculator2",
"com.android.calculator2.Calculator");
startActivityForResult(i, 1);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1){
Log.i("CALCULATOR", "Result Data is"+ data);
}
}
After some testing, I'm starting to think that you can't really get something back from the calculator. Calling something with startActivityForResult doesn't mean it's going to return something other than null and since there's no way of getting out of the calculator other than pressing the back key, I think this is one of those cases.
The native calculator doesn't seem to be calling setResult(RESULT_SUCESS,intent_with_data) which is the step needed to be able to retrieve this result. Easiest thing I can think of, since you're wanting to do some calculation is to implement your own calculator class and call that one instead of the native one.
Calculators are easy to make and you have a zillion examples on the net. Just make sure you have an OK button that calls setResult(RESULT_SUCESS, intent_with_data) after you put extras to the intent with the result.
Warning
Be aware that you're hardcoding a class name instead of calling an intent by specifying an action and URI. This may call the original calculator on the emulator and standard versions of Android, but manufacturers change those kinds of things and since no one is supposed to be calling them like you intend to with your intent, you may end up crashing the app.
My application wants a functionality of picking a contact from the
phone contact, I have achieved this using the following intent
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, 001);
How do i start pick contact activity with an option to create a new contact from the pick list, similar to the one which is available in inbuilt Launcher appliation.
Perhaps passing in one of the extras listed in Contacts.Intents.UI. I'm mostly looking at LIST_ALL_CONTACTS_ACTION and LIST_DEFAULT.