Last active
February 1, 2016 10:57
-
-
Save ludovicfrin/9fb942a1e9d87bf4e85e to your computer and use it in GitHub Desktop.
Lecture de la liste des SMS sous Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<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