public Cursor getsomething()
{
this.open();
Cursor c = database.rawQuery("SELECT content_id FROM " +
DatabaseHandler.Table_Name2 +
" where playlist_id==100813", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String path = c.getString(c.getColumnIndex("content_id"));
MainActivity.t1.append("\n");
MainActivity.t1.append(path);
}while (c.moveToNext());
}
}
this.close();
return null;
}
I am using the above code to get the values but it is showing all the values from he content_id column. What am I doing wrong?
this.open();
ContentValues values2 = new ContentValues();
String csvFilename = "/mnt/sdcard/playlist.csv";
CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
String Rowst[] = null;
while((Rowst = csvReader.readNext()) != null) {
st1 = Rowst[0];
st2= Rowst[1];
st3= Rowst[2];
st4= Rowst[3];
st5= Rowst[4];
st6 = Rowst[5];
st7 = Rowst[6];
st8 = Rowst[7];
st9 = Rowst[8];
st10 = Rowst[9];
st11 = Rowst[10];
st12 = Rowst[11];
st13 = Rowst[12];
st14 = Rowst[13];
st15 = Rowst[14];
st16 = Rowst[15];
st17 = Rowst[16];
st18 = Rowst[17];
st19 = Rowst[18];
values2.put(DatabaseHandler.play1,st1);
values2.put(DatabaseHandler.play2,st2);
values2.put(DatabaseHandler.play3,st3);
values2.put(DatabaseHandler.play4,st4);
values2.put(DatabaseHandler.play5,st5);
values2.put(DatabaseHandler.play6,st6);
values2.put(DatabaseHandler.play7,st7);
values2.put(DatabaseHandler.play8,st8);
values2.put(DatabaseHandler.play9,st9);
values2.put(DatabaseHandler.play10,st10);
values2.put(DatabaseHandler.play11,st11);
values2.put(DatabaseHandler.play12,st12);
values2.put(DatabaseHandler.play13,st13);
values2.put(DatabaseHandler.play14,st14);
values2.put(DatabaseHandler.play15,st15);
values2.put(DatabaseHandler.play16,st16);
values2.put(DatabaseHandler.play17,st17);
values2.put(DatabaseHandler.play18,st18);
values2.put(DatabaseHandler.play19,st19);
database.insert(DatabaseHandler.Table_Name2, null, values2);
}
csvReader.close();
this.close();
this is my code to insert data in the this table,i am trying to read a csvfile on the sdcard and entering its data into table am i doing something wrong i have posted this also if it helps
public Cursor getsomething()
{
this.open();
Cursor c = db.query(DatabaseHandler.Table_Name2, null, "playlist_id=100813", null, null, null, null);
if (c.getCount() > 0)
{
if (c.moveToFirst())
{
do {
String path = c.getString(c.getColumnIndex("content_id"));
MainActivity.t1.append("\n");
MainActivity.t1.append(path);
}while (c.moveToNext());
}
}
this.close();
return null;
}
Related
I have the query below:
public List<ListCoursesFilterModel> getListSubject(List<String> lstLang) {
StringBuilder langs = new StringBuilder();
StringBuilder questionMark = new StringBuilder();
for (int i = 0; i < lstLang.size(); i++) {
langs.append(",").append(lstLang.get(i).toLowerCase());
questionMark.append(",?");
}
String res = langs.substring(1, langs.length());
String qs = questionMark.substring(1, questionMark.length());
List<ListCoursesFilterModel> list = new ArrayList<>();
SQLiteDatabase db = databaseHelper.getWritableDatabase();
Cursor cursor = db.query(
false,
"ShortMajorTBL",
null,
"langId IN(" + qs + ") AND identifier =?",
new String[]{res, "S300"},
null,
null,
null,
null
);
try {
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
ListCoursesFilterModel listCoursesFilterModel = new ListCoursesFilterModel();
listCoursesFilterModel.setSubject(cursor.getString(cursor.getColumnIndex("subject")));
listCoursesFilterModel.setLangId(cursor.getString(cursor.getColumnIndex("langId")));
listCoursesFilterModel.setIsSelected(cursor.getString(cursor.getColumnIndex("isSelected")));
listCoursesFilterModel.setIdentifier(cursor.getString(cursor.getColumnIndex("identifier")));
listCoursesFilterModel.setTitle(cursor.getString(cursor.getColumnIndex("title")));
listCoursesFilterModel.setCount(cursor.getInt(cursor.getColumnIndex("count")));
list.add(listCoursesFilterModel);
} while (cursor.moveToNext());
}
return list;
}
} catch (Exception ex) {
Throwable t = new Throwable(ex).fillInStackTrace();
FirebaseCrash.report(t);
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
lstLang when I have one value - for example en - it works and get results, but when I have multiple values - for example en,fr,ar - it doesn't show any result.
each of your values in the IN clause is a string.
Therefore, it has to singularily be escaped.
I.e.: 'en', 'fr', 'ar'.
So, have something like
...
qs = `'en', 'fr', 'ar'`; // somehow buid this dynamically
...
"langId IN(" + qs + ") AND identifier =?",
...
I want to retrieve minimum balance from table using where condition on button click.Following is my code it's not working plz give me solution.Thanks in advance..
smname = spn_mname.getSelectedItem().toString().trim();
yname = spn_yname.getSelectedItem().toString().trim();
scno = spn_count.getSelectedItem().toString().trim();
String dbsyname = null, dbsmname = null, dbsycolor = null, dbscount = null, dbsrqty = null, dbsdqty = null, dbsbaln = null;
DataBaseHelper dbh = new DataBaseHelper(StockActivity.this);
SQLiteDatabase db = dbh.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT MIN(Balance) FROM stocktable",null);
if (cursor.moveToFirst()) {
do {
dbsmname = cursor.getString(cursor.getColumnIndex("Millname"));
dbsyname = cursor.getString(cursor.getColumnIndex("Yarnname"));
dbscount = cursor.getString(cursor.getColumnIndex("Counttno"));
if (dbsmname.equals(smname)
&& bsyname.equals(syname)
&& dbscount.equals(scno)) {
dbsbaln = cursor.getString(cursor.getColumnIndex("Balance"));
}
} while (cursor.moveToNext());
edtrqty.setText(dbsbaln);
}
you have only selected MIN(Balance) only in your query and trying to access Millname,Counttno and other value on cursor it will throw the exception.
Try Below Solution
Cursor cursor = db.rawQuery("SELECT MIN(Balance) balance as FROM stocktable
where Millname=? AND bsyname=? AND dbscount=?",new String[]{smname,syname,scno});
if (cursor.moveToFirst()) {
do {
dbsbaln = cursor.getString(cursor.getColumnIndex("balance"));
}
} while (cursor.moveToNext());
edtrqty.setText(dbsbaln);
Following code works perfectly...
Cursor cursor = db.rawQuery("SELECT MIN(Balance) AS balance FROM " + DataBaseHelper.stocktable + " WHERE Millname = ? AND Yarnname = ? AND Counttno = ? ", new String[] { smname, syname, scno });
if (cursor.moveToFirst()) {
do {
dbsbaln = cursor.getString(cursor
.getColumnIndex("balance"));
} while (cursor.moveToNext());
edtrqty.setText(dbsbaln);
}
public List<MedicalCase> getPersonalCase(int personid) {
Cursor c = null;
MedicalCase mMedicalCase = new MedicalCase();
List<MedicalCase> myList = new ArrayList<MedicalCase>();
try {
synchronized (DBLOCK) {
SQLiteDatabase db = this.getReadableDatabase();
String str_personid = String.valueOf(personid);
c = db.query(true, TABLE_Case, new String[]{MedicalCase_CaseId, MedicalCase_CaseCoverImageFileName,
MedicalCase_CaseColor, MedicalCase_CaseName,
MedicalCase_StartDate, MedicalCase_EndDate},
Person_PersonId + " = ?", new String[]{str_personid}, null, null, null, null);
if (c != null && c.moveToFirst()) {
do {
mMedicalCase.setCaseId(c.getColumnIndex(MedicalCase_CaseId));
mMedicalCase.setCaseCoverImageFileName(c.getString(c.getColumnIndex(MedicalCase_CaseCoverImageFileName)));
mMedicalCase.setCaseColor(c.getString(c.getColumnIndex(MedicalCase_CaseColor)));
mMedicalCase.setCaseName(c.getString(c.getColumnIndex(MedicalCase_CaseName)));
mMedicalCase.setStartDate(c.getLong(c.getColumnIndex(MedicalCase_StartDate)));
mMedicalCase.setEndDate(c.getLong(c.getColumnIndex(MedicalCase_EndDate)));
myList.add(mMedicalCase);
} while (c.moveToNext());
}
}
c.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return myList;
}
This is my code ,when Perform to this.getReadableDatabase,skip the following code and throws Exception,but not go to String str_personid = String.valueOf(personid);
I think that it is maybe the SQLiteDatabase db = this.getReadableDatabase() is NullPointer,but i dont sure if it is wrong.
I have an assynctask that will read all the content in the conversation box and it works well
protected String doInBackground(String... params) {
Uri inboxURI = Uri.parse("content://sms/conversations");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(inboxURI, null, null, null, null);
c.moveToLast();
al = new ArrayList<MessageInfo>();
try{
for (int i = c.getCount(); i > 0; i--) {
MessageInfo mMessageInfo = new MessageInfo();
mMessageInfo.MessageText = c.getString(c.getColumnIndexOrThrow("snippet"));
mMessageInfo.ThreadId = c.getInt(c.getColumnIndex("thread_id"));
Uri uri = Uri.parse("content://sms/inbox");
String where = "thread_id=" + mMessageInfo.ThreadId;
Cursor Cursor = getContentResolver().query(uri, null, where,null, null);
startManagingCursor(Cursor);
//Cursor.moveToFirst();
String number = "";
String name = "";
if (Cursor.moveToFirst()) {
number = Cursor.getString(Cursor.getColumnIndexOrThrow("address")).toString();
name = GetNameAndNumber(Cursor, number, MessageBox.this);
Log.i("checkPoint","checkPoint-1 "+name);
}
else {
uri = Uri.parse("content://sms/sent");
where = "thread_id=" + mMessageInfo.ThreadId;
Cursor = GetCursor(uri, where, MessageBox.this);
if (Cursor.moveToFirst()) {
number = Cursor.getString(Cursor.getColumnIndexOrThrow("address")).toString();
name = GetNameAndNumber(Cursor, number, MessageBox.this);
Log.i("checkPoint","checkPoint-2 "+name);
}Cursor.close();
}
if (name.length() > 0) {
mMessageInfo.Name = name;
} else {
mMessageInfo.Name = number;
}
mMessageInfo.Number = number;
Log.i("name",name);
Log.i("number",number);
Log.i("mMessageInfo.ThreadId ",""+mMessageInfo.ThreadId );
al.add(mMessageInfo);
c.moveToPrevious();
}c.close();
}catch(Exception x){x.printStackTrace();}
return "Executed";
}
But if my app writes to content://sms/sent the above code gives null exception but the stock messaging app can read it well.
This is the method how I update my sent items
void sentBox(){
ContentValues values = new ContentValues();
values.put("address", number);
values.put("body", msgBox.getText().toString());
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
finish();
}
To be specific I cannot get the address of the message in the sent items.. below returns null exception.. I think there is something to do with my URI.
if (Cursor.moveToFirst())
number = Cursor.getString(Cursor.getColumnIndexOrThrow("address")).toString();
Can someone give me hint why it can't read if I write/update my sent box that way?
I've Manage to fix the problem. It was another method which is writing to sent box using the message ID where there is another method writing to sent box using the address..
protected String doInBackground(String... params) {
al = new ArrayList<MessageInfo>();
String number = "";
String name = "";
Uri conversationURI = Uri.parse("content://sms/conversations");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(conversationURI, null, null, null, null);
c.moveToLast();
for (int i = c.getCount(); i > 0; i--) {
MessageInfo mMessageInfo = new MessageInfo();
mMessageInfo.MessageText = c.getString(c.getColumnIndexOrThrow("snippet"));
mMessageInfo.ThreadId = c.getInt(c.getColumnIndex("thread_id"));
try{
Uri message = Uri.parse("content://sms/inbox");
ContentResolver cr_ = getContentResolver();
String where_ = "thread_id=" + mMessageInfo.ThreadId;
Cursor c_ = cr_.query(message, null, where_, null, null);
startManagingCursor(c_);
if (c_.moveToFirst() && c_ != null) {
number = c_.getString(c_.getColumnIndexOrThrow("address"));
name = GetNameAndNumber(c_, number, MessageBox.this);
}else{
Uri _message_ = Uri.parse("content://sms/sent");
ContentResolver _cr_ = getContentResolver();
String _where_ = "thread_id=" + mMessageInfo.ThreadId;
Cursor _c_ = _cr_.query(_message_, null, _where_, null, null);
if (_c_.moveToFirst() && _c_ != null) {
number = _c_.getString(_c_.getColumnIndexOrThrow("address"));
name = GetNameAndNumber(_c_, reformatNumber(number), MessageBox.this);
}
}
}catch(Exception x){x.printStackTrace();}
if (name.length() > 0) {
mMessageInfo.Name = name;
} else {
mMessageInfo.Name = number;
}
mMessageInfo.Number = number;
al.add(mMessageInfo);
c.moveToPrevious();
}c.close();
return null;
}
Changed this FROM:
void sentBox(){
ContentValues values = new ContentValues();
values.put("thread_id", getIntent().getExtras().getInt("ID"));
values.put("body", mMessageEditText.getText().toString());
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
TO:
void sentBox(){
ContentValues values = new ContentValues();
values.put("address", getIntent().getExtras().getString("number"));
values.put("body", mMessageEditText.getText().toString());
}
EDIT:A list of what I consider important contact details:
1.NAME
2.PHONE NUMBER
3.EMAIL ADDRESS
4.WEBSITE
5.PHYSICAL ADDRESS
I would prefer to do this using a pre-fetched contactId...using only one cursor to get all of the data specified.I,preferably would like to find the right query to do this:
I would like to get all of the important details of a Contact at once,I am using the following code to do this:
public void getAllDataByContactId(int contactId)
{
Log.d(TAG, "Seriously scared it might not work");
String phoneNo="Phone disconnected";
String email="Email could not be delivered";
String website="Website 404";
String address="Number 13,Dark Street,Area 51,Bermuda Trianlge";
String name="Clint Eastwood";
int hasPhoneNumber;
String selection=ContactsContract.Data.CONTACT_ID+"=?";
String[] selectionArgs={String.valueOf(contactId)};
Cursor c=context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null,selection, selectionArgs,ContactsContract.Data.TIMES_CONTACTED);
if(c!=null && c.getCount()>0)
{
while(c.moveToNext())
{
phoneNo=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d(TAG, "Phone number: "+phoneNo);
email=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
Log.d(TAG, "Email: "+email);
website=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL));
Log.d(TAG, "Website :"+website);
address=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));
name=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
Log.d(TAG, "Name :"+name);
}
}
}
However,although this does not throw an error it shows many rows consisting of an empty string interspresed with the actual values.How do I write a query that cuts out the noise?
I have tried this and this gets me all the values:
String selection=ContactsContract.Data.CONTACT_ID+"=? AND "+ContactsContract.Data.MIMETYPE+"=? OR "+ContactsContract.Data.MIMETYPE+"=? OR "+ContactsContract.Data.MIMETYPE+"=? OR "+ContactsContract.Data.MIMETYPE+"=? OR "+ContactsContract.Data.MIMETYPE+"=?";
String[] selectionArgs={String.valueOf(contactId),ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
Too late to answer, but maybe it can help someone in the future.
My solution for this question with only one while cycle and query:
private void fetchContacts(ContentResolver contentResolver) {
if (contentResolver == null) return;
Cursor cursor = contentResolver.query(ContactsContract.Data.CONTENT_URI,
null, null, null, null);
if (cursor == null || cursor.getCount() <= 0) {
return;
}
String prevId = "";
String contactId = "";
PersonContact personContact = null;
while (cursor.moveToNext()) {
String company = "";
String columnName = cursor.getString(cursor.getColumnIndex("mimetype"));
if (columnName.equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)) {
company = cursor.getString(cursor.getColumnIndex("data1"));
}
String email = "";
if (columnName.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
email = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
String phone = "";
if (columnName.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
phone = cursor.getString(cursor.getColumnIndex("data1"));
}
String first = "";
String last = "";
if (columnName.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)) {
first = cursor.getString(cursor.getColumnIndex("data2"));
last = cursor.getString(cursor.getColumnIndex("data3"));
}
if (!prevId.equals(contactId)) {
if (!TextUtils.isEmpty(prevId)) {
addFilteredList(personContact);
allContacts.put(prevId, personContact);
}
prevId = contactId;
personContact = new PersonContact();
} else {
if (personContact != null) {
personContact.id = prevId;
if (TextUtils.isEmpty(personContact.company)) personContact.company = company;
if (TextUtils.isEmpty(personContact.firstName)) personContact.firstName = first;
if (TextUtils.isEmpty(personContact.lastName)) personContact.lastName = last;
if (!TextUtils.isEmpty(email) && personContact.emails.size() == 0) {
personContact.emails.add(email);
}
if (!TextUtils.isEmpty(phone) && personContact.phoneNumbers.size() == 0) {
personContact.phoneNumbers.add(phone);
}
}
}
contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
}
cursor.close();
}
As you can see, I used the prevId field, because cursor.moveToNext performs several times for one contact (once for first and last names, one for phone, etc.). After each iteration, I check the previous contact identifier with the current identifier and, if it is false, I update the fields in the personContact model.
May not be the best solution. But this is how I achieved it.
ArrayList<String> fnameList = new ArrayList<>();
ArrayList<String> lnameList = new ArrayList<>();
ArrayList<String> mnumList = new ArrayList<>();
ArrayList<String> hnumList = new ArrayList<>();
ArrayList<String> wnumList = new ArrayList<>();
ArrayList<String> mailList = new ArrayList<>();
final DynamoDBMapper dynamoDBMapper = AWSMobileClient.defaultMobileClient().getDynamoDBMapper();
final ContactsDO firstItem = new ContactsDO(); // Initialize the Notes Object
firstItem.setUserId(AWSMobileClient.defaultMobileClient().getIdentityManager().getCachedUserID());
String email = null;
Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
String _ID = ContactsContract.Contacts._ID;
String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER;
Uri EmailCONTENT_URI = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
String EmailCONTACT_ID = ContactsContract.CommonDataKinds.Email.CONTACT_ID;
String DATA = ContactsContract.CommonDataKinds.Email.DATA;
StringBuffer output = new StringBuffer();
ContentResolver contentResolver = this.getContentResolver();
Cursor cursor = contentResolver.query(CONTENT_URI, null, null, null, null);
// Loop for every contact in the phone
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER)));
if (hasPhoneNumber > 0) {
String contact_id = cursor.getString(cursor.getColumnIndex(_ID));
// Query and loop for every phone number of the contact
Cursor pCur = contentResolver.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{contact_id}, ContactsContract.CommonDataKinds.Phone.NUMBER);
int flag = 0;
assert pCur != null;
while (pCur.moveToNext()) {
String mobileNum = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
if (flag == 0) {
if(mobileNum!=null){
mnumList.add(mobileNum);}
} else if (flag == 1) {
if(mobileNum!=null){
hnumList.add(mobileNum);}
} else if (flag == 2) {
if(mobileNum!=null){
wnumList.add(mobileNum);}
}
flag++;
}
if(flag==1){
hnumList.add("");
wnumList.add("");
Log.e("Set","Both added");
}
if(flag==2){
wnumList.add("");
Log.e("Set","W added");
}
pCur.close();
}
}
}
cursor.close();
String MIME = ContactsContract.Data.MIMETYPE + "=?";
String[] params = new String[]{ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
final Cursor nameCur = contentResolver.query(
ContactsContract.Data.CONTENT_URI,
null,
MIME,
params,
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
assert nameCur != null;
int i = 0;
while (nameCur.moveToNext()){
String fname = "";
String lname = "";
fname = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
lname = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
Log.e("In While","All the time");
if(fname!=null){
fnameList.add(fname);
Log.e("Put","Value Fname "+fname);}
if(lname!=null) {
lnameList.add(lname);
Log.e("Put","Value Lname "+lname);
}
if(fname==null){
fnameList.add(" ");
}
if(lname==null){
lnameList.add(" ");
}
i++;
}
nameCur.close();
Cursor cursorB = contentResolver.query(CONTENT_URI, null, null, null, null);
// Loop for every contact in the phone
if (cursorB.getCount() > 0) {
while (cursorB.moveToNext()) {
// Query and loop for every email of the contact
String[] paramEmail = new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_TYPE};
Cursor emailCursor = contentResolver.query(EmailCONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", paramEmail, ContactsContract.CommonDataKinds.Email.DISPLAY_NAME);
int j=0;
while (emailCursor.moveToNext()) {
email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
mailList.add(email);
Log.e("Email",email);
j++;
}
if(j==0){
mailList.add("");
Log.e("Email","Dummy Added");
}
emailCursor.close();
output.append("\n");
}
}cursorB.close();
Cursor cursorD = contentResolver.query(CONTENT_URI, null, null, null, null);
// Loop for every contact in the phone
if (cursorD.getCount() > 0) {
while (cursorD.moveToNext()) {
String contact_id = cursorD.getString(cursorD.getColumnIndex(_ID));
//for url
String newNoteUrl = "";
String whereName3 = ContactsContract.Data.MIMETYPE + " = ?";
String[] whereNameParams3 = new String[]{ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
ContentResolver contentResolverUrl = this.getContentResolver();
try {
Cursor cursorUrl = contentResolverUrl.query(ContactsContract.Data.CONTENT_URI, null, whereName3, new String[]{contact_id}, ContactsContract.CommonDataKinds.Website.URL);
while (cursorUrl.moveToNext()) {
newNoteUrl = cursorUrl.getString(cursorUrl.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL));
Log.e("URL",newNoteUrl);
}
Log.e("URL","Not Getting");
output.append("\nurl " + newNoteUrl);
firstItem.setUrl(newNoteUrl);
cursorUrl.close();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}cursorD.close();
Log.e("#######","##########################");
for(int m=0;m<fnameList.size();m++){
Log.e("Contact Val ",fnameList.get(m)+" , "+lnameList.get(m)+" , "+mnumList.get(m)+" , "+hnumList.get(m)+" , "+wnumList.get(m)+" , "+mailList.get(m));
ContactsDO item = new ContactsDO();
item.setUserId(AWSMobileClient.defaultMobileClient().getIdentityManager().getCachedUserID());
item.setFirstName(fnameList.get(m));
item.setLastName(lnameList.get(m));
item.setMobileNumber(mnumList.get(m));
item.setHomeNumber(hnumList.get(m));
item.setWorkNumber(wnumList.get(m));
item.setEmail(mailList.get(m));
try {
//saving to the database
dynamoDBMapper.save(item);
} catch (final AmazonClientException ex) {
Log.e(TAG, "Failed saving item : " + ex.getMessage(), ex);
}
}