Это мой код Android для чтения всех SMS с телефона и помещения каждого SMS в JSONObject
.После этого я помещаю JSONObject
в файл JSON.Когда я запускаю свой код, я читаю только одно SMS.Как вы можете помочь мне прочитать все SMS?
public void RecupSms() {
JSONObject objSms = new JSONObject();
try {
FileOutputStream out = this.openFileOutput(nomDufichierSms, MODE_PRIVATE);
Map<String, String> sms = new HashMap<String, String>();
//ContentResolver contentResolver1 = getContentResolver();
cursor3 = getContentResolver().query(SMS_URI_OUTBOX, null, null, null, null);
totalSms = cursor3.getColumnCount();
if (cursor3.moveToFirst()) {
// for(int i =0; i < totalSms; i++)
do {
address = cursor3.getString(cursor3.getColumnIndex("address"));
body = cursor3.getString(cursor3.getColumnIndexOrThrow("body"));
//building.append("numero").append(address).append("message").append(body);
objSms.put("numero", address);
objSms.put("message", body);
//objSms.put("details sms", sms);
} while (cursor3 != null && cursor3.moveToNext());
infosSms = objSms.toString();
out.write(infosSms.getBytes());
} else{
Toast.makeText(this, "0 sms", Toast.LENGTH_SHORT).show();
}
cursor3.close();
out.close();
Toast.makeText(this, "File saved!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "Error:" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
try {
// Open stream to read file.
FileInputStream in = this.openFileInput(nomDufichierSms);
BufferedReader br= new BufferedReader(new InputStreamReader(in));
StringBuilder sb= new StringBuilder();
String s= null;
while((s= br.readLine())!= null) {
sb.append(s).append("\n");
}
detaile.setText(sb.toString());
} catch (Exception e) {
Toast.makeText(this,"Error:"+ e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
В результате этого кода мне дается всего одно SMS, я не знаю, почему