Code show an error when try declare a new Uri
follow code:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, new Uri("content://contacts"));
show an error
"Cannot instantiate the type Uri"
Instead of constructing a Uri, use the static parse method to create it:
Uri.parse("content://contacts");
Although, since you are accessing contacts, you should probably prefer using the static field CONTENT_URI from the Contacts class. See the SDK reference for Contacts.
This would make your code:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
You should use:
Intent pickContactIntent = new Intent( Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI );
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
Related
When i click on the Browse button i have added below code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
It shows FileManager in some devices like Redmi,Asus,Micromax.But it is not showing in Samsung phones,it's not going to file manager
How to get FileManager in Samsung phones to select a file?
try this is working for me
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent , CHOOSE_FILE_REQUESTCODE);
for Samsung Devices
String manufactures = android.os.Build.MANUFACTURER;
if(manufactures.equalsIgnoreCase("samsung")){
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
}
Replace
Intent intent = new Intent(Intent.ACTION_VIEW);
as
Intent intent = new Intent(Intent.GET_CONTENT);
EDIT
#Hanuman i think that single solution that fits all models doesn't exist, all intents with "actions" have to be processed by choosers. If you use >= 4.4 devices, I recommend
Storage Access Framework
I know how to create an intent to let the contacts app display a specific contact:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, mMyLookupKey);
intent.setData(uri);
startActivity(intent);
I also know how to create an intent to ask the contacts app to let me PICK a phone number:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
// Explicitly set the 'type' to 'phone numbers' //
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, REQUEST_PHONENR);
Just now I have been trying to combine these to make it possible to pick a phone number from a specific contact:
Intent intent = new Intent(Intent.ACTION_PICK);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, mMyLookupKey);
intent.setData(uri);
// Explicitly set the 'type' to 'phone numbers'
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, REQUEST_PHONENR);
Does somebody know is this is possible?
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, 0);
SO,how do i do it? I have tried the following
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
context.startActivity(intent);
The above works only with mailto or tel, what about name?
you can also send Person Name using Intents.Insert.NAME with Intent as:
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
// add name here
intent.putExtra(Intents.Insert.NAME, sender_Name_here);
context.startActivity(intent);
I need to show/interact with a new contact before create it, and I need a simple way to add it to the phone contacts.
this is the code I use:
String contactPhone = "33333333";
Uri contactUri = Uri.parse(String.format("tel: %s", contactPhone));
Intent addContactIntent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "FirstName" );
addContactIntent.putExtra(ContactsContract.Intents.Insert.COMPANY,"CompanyName");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,contactPhone);
addContactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL,"contact#email.com");
startActivity(addContactIntent);
and this is the result. The problem is that the Intent show me only the Phone instead all the info added.
ContactsContract.Intents.Insert.ACTION if you want to interact before create it:
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION,ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.NAME, getName());
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, getCompany());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, getEmail());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, getPhone());
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, getAddress());
startActivity(intent);
This works pretty well. I hope this will help you.
This site (http://wiresareobsolete.com/2011/10/simplifying-interaction-with-contacts/) shows and gives examples) that SHOW_OR_CREATE_CONTACT can only trigger off "tel" or "mailto"/email for searches.
I am trying to programatically launch or open the photo gallery after passing a photo name search parameter.
I am new at this. I am thinking maybe intents can be used but not sure so I am wondering if anyone could please point me in the right direction. Preferably with some code examples.
Much thanks.
RE-EDIT
As requested, this is the code I have so far..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// CAMERA_PIC_REQUEST = 2600;
cameraIntent = Intent.createChooser(intent,"Select Picture");
you can try follow code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(photoUri);
context.startActivity(intent);
I think this is what you mean, correct me if I'm wrong:
String nameOfPhotoToBeRetrieved = "myPhoto";
String WHERE = "TITLE ="+nameOfPhotoToBeRetrieved;
Then you can use the following line to deliver a result to your cursor/listener:
CursorLoader(context,content_uri,null,WHERE,null,null).deliverResult(myCursor);