We are able to successfully read contacts with permissions and put them into a json object, but are unable to pass it through the webview effectively. We tried registering a cookie session with json object as its value. But it only passes through the webview on opening and closing the app second time.
Here is the code we are using to read contacts.
public void addContacts(){
//to store name-number pair
JSONObject obj = new JSONObject();
try {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while (phones.moveToNext()) {
String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
obj.put(name, phoneNumber);
//contacts.add(obj);
cookieManager.setCookie(ASWV_URL, "contacts="+obj);
//Log.d("COOKIES: ", cookieManager.getCookie(ASWV_URL));
//Log.e("Contact list with name & numbers", " "+contacts);
}
phones.close();
}
catch (Exception e){
//e.printStackTrace();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setCookie(ASWV_URL, "contacts="+e);
}
}
The "contact" cookies do get registered but only after closing the app and reopening it. Is there anyway we can solve this in better way.