0
可以告訴我如何讀取服務短信從網絡提供商接收。我想讀取像平衡enqirey短信,最新的短信從服務提供商得到。閱讀服務在android的短信
可以告訴我如何讀取服務短信從網絡提供商接收。我想讀取像平衡enqirey短信,最新的短信從服務提供商得到。閱讀服務在android的短信
public class main extends Activity {
/** Called when the activity is first created. */
String colName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tView = (TextView)findViewById(R.id.txtView);
ContentResolver cr =getContentResolver();
Uri uri = Uri.parse("content://sms/inbox");
//Uri uri = Uri.parse("content://sms"); -- For all SMS
//Uri uri = Uri.parse("content://sms/sent"); -- For all Sent Items
//If you want to read the Sent SMS then change the URi to /sent.
//In this example we are using Query as we have defined URi as above.
//We have declared all the Column names we need in string array in the second parameter.
//If you dont need all then leave null
//Notice that we did not call managedQuery instead we used Query method of ContentResolver
Cursor messagesCursor = cr.query(uri, new String[] { "_id","address","body","person"}, null,null, null);
colName = "ColumnName" +"\n";
colName = colName + "--------------" + "\n";
for(int loopCounter=0; loopCounter < messagesCursor.getColumnCount() ; loopCounter++)
{
colName = colName + messagesCursor.getColumnName(loopCounter) + "\n";
}
colName = colName + "--------------" + "\n";
if(messagesCursor.getCount() > 0)
{
while(messagesCursor.moveToNext())
{
colName = colName + messagesCursor.getString(messagesCursor.getColumnIndex("body")) + "--";
colName = colName + messagesCursor.getString(messagesCursor.getColumnIndex("address")) + "\n";
}
}
tView.setText(colName);
}
}
試試這個鏈接http://davanum.wordpress.com/2007/12/15/android-listen-for-incoming-sms-messages/ – kannappan