Gestion des SMS

  • Réponses :0
Sylvano Assele
  • Posts de Forum 1

21 déc. 2016 à 10:03:36 via site

Bonjour,

j'aimerai savoir comment faire pour analyser une chaîne de caractère pour y retrouver un mot.
Voici le code que j'utilise :

Uri inboxURI = Uri.parse("content://sms/inbox");

        // List required columns
        String[] reqCols = new String[] { "_id", "address", "body" };

        // Get Content Resolver object, which will deal with Content Provider
        ContentResolver cr = getContentResolver();

        // Fetch Inbox SMS Message from Built-in Content Provider
        Cursor c = cr.query(inboxURI, reqCols, "address='AirtelMoney'", null, null);
        if(c.moveToFirst()) {
            int index_Body = c.getColumnIndex("body");
            String index_Body1 = c.getString(c.getColumnIndexOrThrow("body")).toString();
            //_messagesms.setText(index_Body);
            do {
                //String strbody = c.getString(index_Body);
                String strbody = c.getString(c.getColumnIndexOrThrow("body"));
                _messagesms.setText(index_Body1);
                if(strbody.contains("07303303")) {
                // Attached Cursor with adapter and display in listview
                adapter = new SimpleCursorAdapter(this, R.layout.row, c,
                        new String[]{"body", "address"}, new int[]{
                        R.id.lblMsg, R.id.lblNumber});
                lvMsg.setAdapter(adapter);
                }
            } while (c.moveToNext());
        }

Mon objectif etant d'afficher tous les messages contenant "07303303"

Ca fait des heures que je butte dessus.

Cordialement,
Sylvano

Répondre