SMS Sender's Name Shows as labuser in Default SMS App
I installed the following code on my Android 2.2 phone and the sender's name shows as labuser for some messages when it is actually something else :-
public class SMSReaderActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView myListView = (ListView) findViewById(R.id.myListView);
final ArrayList<String> smses = new ArrayList<String>();
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, smses);
myListView.setAdapter(aa);
Context context = getApplicationContext();
Cursor cursor = context.getContentResolver().query(
Uri.parse("content://sms/inbox"),
new String[] { "address", "person", "date", "body" }, null,
null, "date desc");
cursor.moveToFirst();
int count = cursor.getCount();
for (int j = 0; j < count; j++) {
String msg = cursor.getString(0) + ", " + cursor.getString(1)
+ ", " + cursor.getLong(2) + ", " + cursor.getString(3);
Log.w("SMS", "Read SMS:" + msg);
if (cursor.getString(3).indexOf("rbs") >= 0) {
smses.add(msg);
Log.w("SMS", "Added");
}
cursor.moveToNext();
}
cursor.close();开发者_JS百科
aa.notifyDataSetChanged();
}
labuser is not an a/c on my development machine and this happens with only matching smses. I cannot figure out the source of this.
Thanks Himanshu
Giving it the READ_CONTACTS permission fixed it. That my app, reading SMS's without appropriate permissions, could screw up the default one was strange.
精彩评论