Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lecture de la liste des SMS sous Android
/**
* Activité de lecture des SMS
*
* @author Ludovic FRIN
*/
public class ReadSmsActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader (
this,
Uri.parse("content://sms/"),
null, // Elements à récupérer
null, // Filtre de recherche
null, // Arguments de la recherche
null // Ordonnancement
);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
int totalSMS = cursor.getCount();
if (cursor.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
System.out.println(" Id : " + cursor.getString(cursor.getColumnIndexOrThrow("_id")));
System.out.println(" Thread : " + cursor.getString(cursor.getColumnIndexOrThrow("thread_id")));
System.out.println(" Adresse : " + cursor.getString(cursor.getColumnIndexOrThrow("address")));
System.out.println(" Person : " + cursor.getString(cursor.getColumnIndexOrThrow("person")));
System.out.println(" Contenu : " + cursor.getString(cursor.getColumnIndexOrThrow("body")));
System.out.println(" Lu : " + cursor.getString(cursor.getColumnIndexOrThrow("read")));
System.out.println(" Date : " + cursor.getString(cursor.getColumnIndexOrThrow("date")));
System.out.println(" Type (1=recu, 2=envoyé) : " + cursor.getString(cursor.getColumnIndexOrThrow("type")));
cursor.moveToNext();
}
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
}
}
...
<uses-permission android:name="android.permission.READ_SMS" />
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.