Start Google Hangout from Intent in New Hangouts Android app

后端 未结 5 700
终归单人心
终归单人心 2020-11-30 06:03

There are previous discussions here regarding starting a Google Hangout from an intent on Android: start google hangouts in android

How can I start a Google Hangout

5条回答
  •  我在风中等你
    2020-11-30 06:43

    Simple solution is, Query ContactContract.Data for the _id and MIME type.

    ContentResolver resolver = context.getContentResolver();  
    cursor = resolver.query(
                ContactsContract.Data.CONTENT_URI,
                null, null, null,
                ContactsContract.Contacts.DISPLAY_NAME);
    
    //Now read data from cursor like 
    
    while (cursor.moveToNext()) {
          long _id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID));
          String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
          String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
    
          Log.d("Data", _id+ " "+ displayName + " " + mimeType );
    
    }
    

    The output will be like the following

    12561 Allen vnd.android.cursor.item/vnd.googleplus.profile.comm

    12562 Allen vnd.android.cursor.item/vnd.googleplus.profile.comm

    12564 Allen vnd.android.cursor.item/vnd.googleplus.profile

    Now save in DB or somewhere else only those _Ids whose MIME type is vnd.android.cursor.item/vnd.googleplus.profile.comm

    And then you initiate hangout call/message with those contacts like this way

    Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
    
    // the _ids you save goes here at the end of /data/12562     
         intent.setDataAndType(Uri.parse("content://com.android.contacts/data/_id"),
                        "vnd.android.cursor.item/vnd.googleplus.profile.comm");
                intent.setPackage("com.google.android.talk");
    
    startActivity(intent);
    

    For the above code to work you must have to check "Keep contacts up to date" in the Google+ App > Settings> Contacts.

提交回复
热议问题