开发者

Selecting multiple contacts in Android

开发者 https://www.devze.com 2023-01-05 08:55 出处:网络
Is there开发者_如何学Python a way similar to ACTION_PICK to select multiple contacts from the address book and then return to previous activity?Not a full answer, but maybe helpful anyway:

Is there开发者_如何学Python a way similar to ACTION_PICK to select multiple contacts from the address book and then return to previous activity?


Not a full answer, but maybe helpful anyway:

// Let user select (multiple) from a list of contacts with email addresses
Intent i = new Intent(Intent.ACTION_GET_CONTENT, Email.CONTENT_URI);
startActivityForResult(Intent.createChooser(i, ""), MY_RESULT_1);

In onActivityResult, you'll apparently just get a Uri (in data.getData()) that represents the entire set of contacts. Great.

On HTC Desire/Froyo, data.getExtras() contain three ArrayLists, one of which seems to hold the Id's of the records the user selected.

Set<String> keys = data.getExtras().keySet();
ArrayList<Integer> ids = null;
for (String s : keys) {
    Object o = data.getExtras().get(s);
    if (o instanceof ArrayList) {
        ArrayList a = (ArrayList) o;
        if (a.size() > 0 && a.get(0) instanceof Integer) {
          ids = a;
        }
    }
}

You can use these to filter the result from querying the data.getData() Uri.

Not pretty, and possibly HTC specific. You mileage may vary.

If someone can point out a smarter way, I'm a happy listener :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号