I would like to reuse the native Contact Picker of a User's device by doing the following:
public void doLaunchContactPicker(View view) {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
// Made up code that I am sure doesn't exist
contactPickerIntent.putExtra("MyRemote3rdPartyContactList", remoteContacts)
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
However, instead of looking at their contacts that are on the device, I would like to re-configure the Contact UI to point at a Custom Contact Provider that I populate via webservice call in my app.
How would I go about doing this if it is possible?
Technically not possible: the default Contact picker doesn't have any code to let you feed it a different data source.
If you really want you can pop open the source and poke at it: maybe you can reuse it for your purposes.
Related
My app shares a specific URL to open in other apps, but I want to use a custom URL depending on what app the user is sharing it with. For example, with Gmail I want to use myurl.com?src=gmail, and with FB I want to use myurl.com?src=fb etc.
This normally would have worked with this famous method: https://stackoverflow.com/a/18068122/3015986.
However, in Android 10, that solution no longer works anymore: https://medium.com/#AndroidDeveloperLB/this-wont-work-anymore-on-android-q-1702c19eb7bb
So, what other options are there?
Well there are always options. In this particular case(with the given conditions regarding URL query parameter) I would suggest to create separate sharing method for each platform you want to share your content with rather than use the Android default sharing method.
For example here is a custom sharing for Facebook, etc. The method is quite time consuming though.
But there is a better option to handle such cases. It is a relatively new method to get info about which app was chosen. It is easy. Basically you will need to:
Create a PendingIntent for a BroadcastReceiver and supply its IntentSender in Intent.createChooser() like this:
Intent share = new Intent(ACTION_SEND);
...
PendingIntent pi = PendingIntent.getBroadcast(myContext, requestCode,
new Intent(myContext, MyBroadcastReceiver.class),
FLAG_UPDATE_CURRENT);
share = Intent.createChooser(share, null, pi.getIntentSender());
Receive the callback in MyBroadcastReceiver and look in Intent.EXTRA_CHOSEN_COMPONENT like this:
#Override public void onReceive(Context context, Intent intent) {
...
ComponentName clickedComponent = intent.getParcelableExtra(EXTRA_CHOSEN_COMPONENT);
}
More info here
Though you cannot change your URL for each specific case because the sharing event has already occurred, you can implement separate API call or URL link using which you can gather analytics data, change the outcome of the URL click you sent(if you control the backend, of course) or just show a customized message to the user of your app.
Keep in mind, that for some usecases of this method, URL you share should be unique per user(for ex. to change the outcome of the URL click etc).
Hope it helps.
I have been able to open audio file picker like whatsapp using following code.
Intent intent = new Intent(Intent.ACTION_PICK,
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
return intent;
However, I want to open the file picker in the same as it is shown in whatsapp. I am using the following code and other similar codes. However, I am not able to show document picker exact like whatsapp. The following code opens the document picker and it shows explorer and take me to Recent folder as starting point.
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
intent.setType("application/*");
// Only return URIs that can be opened with ContentResolver
intent.addCategory(Intent.CATEGORY_OPENABLE);
It shows differently on different devices as well. I want to make it consistent.
Apologies for giving answer late. I don't know this is exact answer you are looking for. But i implemented image and document picker with below code.
https://github.com/DroidNinja/Android-FilePicker
I want is to hide all contacts without phone numbers in phonebook from my application..
Just like phonebook do, When you go to phonebook -> settings there is a checkbox which states that "Contacts with phone number only" I want to implement this feature in my app
I need a method (code) to navigate users to
phonebook -> settings (activity) (System app)
from my application activity.
or worse case hide all contacts without phone number through database. So that phonebook can filter out.
Currently i found
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 123);
Above code opens phone book but i want to open phone book -> settings page.
In sum i want to make phonebook contents "contacts with phone numbers" from my application
I need a method (code) to navigate users to phonebook -> settings (activity) (System app)
There are hundreds, perhaps thousands, of Android phones. None will necessarily be the same with respect to their "phonebook" app. None of those "phonebook" apps necessarily have the feature you seek -- some may, some many not. And, most likely, none have a documented and supported Intent structure for getting to a screen within the app to control the setting that they may or may not have.
I want is to hide all contacts without phone numbers in phonebook from my application
Then you will need to not use the "phonebook" app, but instead display contacts yourself, via the READ_CONTACTS permission and the ContactsContract ContentProvider.
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
Well, I have sucessfully developed a Contacts application for Android as my major project. I believe this is quite simple. Here is code how I did it.
Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1",
null,
ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
mAdapter = new MyAdapter(this,
R.layout.single_cell,
c,
new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
new int[]{R.id.disp_name},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
listview.setAdapter(mAdapter);
And, in MyAdapter, I have extended SimpleCursorAdapter and over rided bindView() to take advantage of efficiency of SimpleCursorAdapter. However, you need a permission to read contacts. In your android-manifest file. Please mention,
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Hope, it helps.
I'm a new android developer, and I try to create an app for using bar code. I try ZXing, it is very easy. But now I need get information about product by bar code. How can I do that?
You'll need to use some kind of web service to look up the product information associated with an UPC/EAN code using for example an AsyncTask. A quick Google search turned up the Internet UPC Database.
Here's a sample record of what data they provide: http://www.upcdatabase.com/item/0081697521221
Please carefully read their ToS: http://www.upcdatabase.com/docs/terms.asp
To use one dimensional barcodes use PRODUCT_MODE.
If you want to be able to scan them all don't set anything in extras scan_mode.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
//intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
Bar code gives you nothing but a number (product number). You need to have a web service where you can send this number to get more details.
you have to call the barcode reader by intent, then the user scans the barcode(if they have the barcode reader installed), and the barcode reader sends the data to your app
here's the code on how to do it.
http://code.google.com/p/zxing/wiki/ScanningViaIntent
as you can see in public void onActivityResult
these are the data returned by the scanner
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
The contacts on the android phone come with settings like "Filter Contacts" that lets the user set things like "Show only contacts that have phone numbers" and "Only show contacts that are online", and which sets of contacts to display (eg, phone only, phone and google etc.).
When doing this
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
is there any way to get those filters applied to the contacts list? By default it seems to return everything. If you can't, is there some way to access those settings to see what they are, so I can build my own contacts picker list to match how the phone user has set their default? This only needs to work for Android 2 up.
(The ideal option would be a way to invoke the contact picker that lets the user also set the filters from in there.)
I think if you pass a URI to the intent like the one shown here, you should be able to apply your filter. So you'd do something like this:
Intent intent = new Intent(Intent.ACTION_PICK, PhoneLookup.CONTENT_FILTER_URI);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);