inbox - Getting null exception when reading Android sent box -



inbox - Getting null exception when reading Android sent box -

i have assynctask read content in conversation box , works

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{ (int = c.getcount(); > 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 = "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"); = "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();} homecoming "executed"; }

but if app writes content://sms/sent above code gives null exception stock messaging app can read well.

this method how update 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 specific cannot address of message in sent items.. below returns null exception.. think there uri.

if (cursor.movetofirst()) number = cursor.getstring(cursor.getcolumnindexorthrow("address")).tostring();

can give me hint why can't read if write/update sent box way?

i've manage prepare problem. method writing sent box using message id there method writing sent box using 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(); (int = c.getcount(); > 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(); homecoming null; }

changed 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()); }

android inbox

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -