보낸 사람이 보낸 메시지에 액세스 할 수있는 방법이 있습니까? 안드로이드에서 smsmanager를 사용하여 특정 번호로 메시지를 보냈습니다. 이제는 수신자가 메시지를 수신하고 어떤 메시지를 받았는지 확인하는 방법을 만들 것입니다.SMS 보낸 메시지에 액세스
1
A
답변
2
SMS 유형은 조건
MESSAGE_TYPE_ALL = 0;
MESSAGE_TYPE_INBOX = 1;
MESSAGE_TYPE_SENT = 2;
MESSAGE_TYPE_DRAFT = 3;
MESSAGE_TYPE_OUTBOX = 4;
MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages
MESSAGE_TYPE_QUEUED = 6; // for messages to send later
사용 MESSAGE_TYPE_SENT=2
상수
그래서 다음 코드를 사용합니다
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
new String[] { "_id", "thread_id", "address", "person", "date",
"body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
Log.e("Count",count);
while (cursor1.moveToNext()){
String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
if(type.equals("2")) // 2 for Sent Sms
{
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
}
}
}
당신은 또한 당신의 AndroidManifest.xml
1
콘텐츠 관찰자를 등록하십시오.
SMSObserver smsSentObserver = new SMSObserver(new Handler());
getContentResolver().registerContentObserver(Uri.parse("content://sms/out"), true, smsSentObserver);
public class SMSObserver extends ContentObserver
{
public SMSObserver(Handler handler) {
super(handler);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
querySMS();
}
}
protected void querySMS() {
Uri uriSMS = Uri.parse("content://sms/out");
Cursor cur = getContentResolver().query(uriSMS, null, null, null, null);
cur.moveToNext(); // this will make it point to the first record, which is the last SMS sent
String body = cur.getString(cur.getColumnIndex("body")); //content of sms
String add = cur.getString(cur.getColumnIndex("address")); //phone num
String time = cur.getString(cur.getColumnIndex("date")); //date
String protocol = cur.getString(cur.getColumnIndex("protocol")); //protocol
int type = Integer.parseInt(cur.getString(cur.getColumnIndex("type")));
}
+0
Tarun에게 감사드립니다. :) 코드를 연구 한 후에 나중에 업데이트하겠습니다. – RonPelayo
0
이것은 비슷한 기능을 위해 사용하는 코드입니다. 도움이되기를 바랍니다.
public class OutgoingSms {
SmsManager sms = SmsManager.getDefault();
ContentResolver contentResolver;
ContentObserver contentObserver;
String senderNum;
String message;
String type;
String smsContent;
contentResolver.registerContentObserver(Uri.parse("content://sms"), true, contentObserver);
contentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Uri smsURI = Uri.parse("content://sms/sent");
String[] strings = {"address", "body"};
Cursor c = getContentResolver().query(smsURI, null, null, null, null);
c.moveToNext();
senderNum = c.getString(c.getColumnIndex("address"));
message = c.getString(c.getColumnIndex("body"));
type = c.getString(c.getColumnIndex("type"));
if (type.equals("2"))
{
smsContent = "send sms to " + senderNum + " content is " + message1;
sms.sendTextMessage("+123456789", null, smsContent, null, null);
}
}
}
};
관련 문제
- 1. SMS 콘텐츠 액세스 iPhone
- 2. 들어오는 SMS 메시지에 응답
- 3. 페이지로 보낸 메시지에 회신하기
- 4. 보낸 SMS 가져 오기
- 5. 대체 SMS 보낸 사람
- 6. MFMessageComposeViewController sms 보낸 대리인
- 7. SMS/MMS 메시지에 사진 첨부
- 8. 보낸 메시지에 대한 eunit 테스트
- 9. 안드로이드에서 보낸 SMS 수의 유지 카운트
- 10. 여러 개의 보낸 메시지에 대한 BroadCastReceiver?
- 11. 보낸 SMS 메시지 수신자가 있습니까?
- 12. 특정 포트로 보낸 sms 수신
- 13. xamarin monotouch 아이폰에서 보낸 SMS 읽기?
- 14. SMS 메시지에 링크를 보내는 방법은 무엇입니까?
- 15. Gmail 이메일 메시지에 대한 SMS 알림
- 16. SMS 메시지에 특수 문자를 포함시키는 방법은 무엇입니까?
- 17. 안드로이드에서 SMS 메시지에 사용되는 데이터 구조
- 18. SMS 서비스 모뎀에서 보낸 SMS에 응답 하시겠습니까?
- 19. ActionMailer가 보낸 메시지에 대해 messageid를 가져옵니다.
- 20. SMS를 보내지 만 보낸 메시지에 표시하지 않습니다.
- 21. SMS 송수신 및 SMS 패널 개발
- 22. 보낸/전달 된 SMS : 브로드 캐스트가 속한 SMS를 어떻게 식별합니까?
- 23. sms 액세스 프로젝트
- 24. iPhone SMS 파일에 액세스
- 25. SMS 설정 액세스
- 26. 보낸 SMS 상태를 모니터링하는 방법은 무엇입니까?
- 27. 보낸 SMS 메시지를받은 편지함에 저장할지 여부를 선택하십시오.
- 28. Java의 SMS-Gateway에서 보낸 SMS를 수신하지 못합니까?
- 29. Android 에뮬레이터 : 포트에서 에뮬레이터에서 보낸 SMS 수신
- 30. 기본 앱 스레드에서 보낸 SMS 업데이트
덕분에 그 tarsem에 대한 :) 내가 코드 공부했습니다 나중에 후를 업데이트 할 수 있습니다 – RonPelayo
아, 나는 ...이 적용 내가 수신자의받은 편지함을 의미 보낸 메시지를 의미하지 않았다 잊었 그? 죄송합니다 – RonPelayo
@RonPelayo 예 (type.equals ("1")) –