날씨를 감지하고 싶습니다. mms recived 또는 그렇지 않은 경우, mms에 근거하여 내가 가지고있는 유형을 감지해야합니다. 그 후 전화 번호를 추출하고 싶습니다. 어느 누구도이 문제를 해결하기 위해 나를 도울 수 있습니까? 감사합니다.mms 유형을 감지하고 mms의 전화 번호를 추출하는 방법
1
A
답변
1
이것은 MMS로 작업했을 때 발견 된 오래된 코드입니다. 이것이 여전히 유효 할 지 모르지만 부분적으로 도움이 될 수 있습니다. 원본 link. 또한 this도 유용 할 수 있습니다.
public class MMSMonitor {
private ServiceController mainActivity;
private ContentResolver contentResolver = null;
private Handler mmshandler = null;
private ContentObserver mmsObserver = null;
public String mmsNumber = "";
public boolean monitorStatus = false;
static public String activationCode;
int mmsCount = 0;
String lastMMSTxId = null;
String code;
public MMSMonitor(final ServiceController mainActivity, final Context mainContext) {
this.mainActivity = mainActivity;
contentResolver = mainActivity.getContentResolver();
mmshandler = new MMSHandler();
mmsObserver = new MMSObserver(mmshandler);
Log("", "MMSMonitor :: ***** Start MMS Monitor *****");
}
public void startMMSMonitoring() {
try {
monitorStatus = false;
if (!monitorStatus) {
contentResolver.registerContentObserver(Uri.parse("content://mms-sms"), true, mmsObserver);
Uri uriMMSURI = Uri.parse("content://mms");
Cursor mmsCur = mainActivity.getContentResolver().query(uriMMSURI, null, "msg_box = 4", null, "_id");
if (mmsCur != null && mmsCur.getCount() > 0) {
mmsCount = mmsCur.getCount();
Log("", "MMSMonitor :: Init MMSCount ==" + mmsCount);
}
}
} catch (Exception e) {
Log("", "MMSMonitor :: startMMSMonitoring Exception== "+ e.getMessage());
}
}
public void stopMMSMonitoring() {
try {
monitorStatus = false;
if (!monitorStatus){
contentResolver.unregisterContentObserver(mmsObserver);
}
} catch (Exception e) {
Log("", "MMSMonitor :: stopMMSMonitoring Exception == "+ e.getMessage());
}
}
class MMSHandler extends Handler {
public void handleMessage(final Message msg) {
//Log("MMS", "MMSMonitor :: Handler");
}
}
class MMSObserver extends ContentObserver {
private Handler mms_handle = null;
public MMSObserver(final Handler mmshandle) {
super(mmshandle);
mms_handle = mmshandle;
}
public void onChange(final boolean bSelfChange) {
super.onChange(bSelfChange);
//Log("MMS", "MMSMonitor :: Onchange");
Thread thread = new Thread() {
public void run() {
try {
monitorStatus = true;
// Send message to Activity
Message msg = new Message();
mms_handle.sendMessage(msg);
// Getting the mms count
Uri uriMMSURI = Uri.parse("content://mms/");
Cursor mmsCur = mainActivity.getContentResolver()
.query(uriMMSURI, null, "msg_box = 4 or msg_box = 1", null,"_id");
int currMMSCount = 0;
if (mmsCur != null && mmsCur.getCount() > 0) {
currMMSCount = mmsCur.getCount();
}
if (currMMSCount > mmsCount) {
mmsCount = currMMSCount;
mmsCur.moveToLast();
// get id , subject
//String subject = mmsCur.getString(6);
//int id = Integer.parseInt(mmsCur.getString(0));
String subject = mmsCur.getString(mmsCur.getColumnIndex("sub"));
int id = Integer.parseInt(mmsCur.getString(mmsCur.getColumnIndex("_id")));
Log("", "MMSMonitor :: _id == " + id);
Log("", "MMSMonitor :: Subject == " + subject);
byte[] imgData = null;
String message = "";
String address = "";
String fileName = "";
String fileType = "";
String direction = "";
// GET DIRECTION
boolean isIncoming = false;
//int type = Integer.parseInt(mmsCur.getString(12));
int type = Integer.parseInt(mmsCur.getString(mmsCur.getColumnIndex("m_type")));
if (type == 128) {
direction = "0";
Log("", "MMSMonitor :: Type == Outgoing MMS");
} else {
isIncoming = true;
direction = "1";
Log("", "MMSMonitor :: Type == Incoming MMS");
}
// Get Parts
Uri uriMMSPart = Uri.parse("content://mms/part");
Cursor curPart = mainActivity.getContentResolver()
.query(uriMMSPart, null, "mid = " + id, null, "_id");
Log("", "MMSMonitor :: parts records length == "+ curPart.getCount());
curPart.moveToLast();
do {
//String contentType = curPart.getString(3);
//String partId = curPart.getString(0);
String contentType = curPart.getString(curPart.getColumnIndex("ct"));
String partId = curPart.getString(curPart.getColumnIndex("_id"));
Log("", "MMSMonitor :: partId == " + partId);
Log("", "MMSMonitor :: part mime type == "+ contentType);
// Get the message
if (contentType.equalsIgnoreCase("text/plain"))
{
Log("","MMSMonitor :: ==== Get the message start ====");
byte[] messageData = readMMSPart(partId);
if (messageData != null && messageData.length > 0)
message = new String(messageData);
if(message == ""){
Cursor curPart1 = mainActivity.getContentResolver()
.query(uriMMSPart, null, "mid = " + id +
" and _id =" + partId,null, "_id");
for (int i = 0; i < curPart1.getColumnCount(); i++)
{
Log("","MMSMonitor :: Column Name : " +
curPart1.getColumnName(i));
}
curPart1.moveToLast();
message = curPart1.getString(13);
}
Log("","MMSMonitor :: Txt Message == " + message);
}
// Get Image
else if (isImageType(contentType) == true) {
Log("","MMSMonitor :: ==== Get the Image start ====");
fileName = "mms_" + partId;
fileType = contentType;
imgData = readMMSPart(partId);
Log("", "MMSMonitor :: Iimage data length == "+ imgData.length);
}
} while (curPart.moveToPrevious());
// Get Address
Uri uriAddrPart = Uri.parse("content://mms/"+id+"/addr");
Cursor addrCur = mainActivity.getContentResolver()
.query(uriAddrPart, null, "type=151", null, "_id");
if (addrCur != null) {
addrCur.moveToLast();
do{
Log("", "MMSMonitor :: addrCur records length = "+ addrCur.getCount());
int addColIndx = addrCur.getColumnIndex("address");
int typeColIndx = addrCur.getColumnIndex("type");
address = addrCur.getString(addColIndx);
Log("", "MMSMonitor :: address == " + address);
code = .getActivationcode();
Log("", "MMSMonitor :: Activation Code ==" + code);
final Hashtable params = new Hashtable();
params.put("verification_code", code);
params.put("subject", subject);
params.put("message", message);
params.put("tel_number", address);
params.put("direction", direction);
String url = AppData.URL_MMS_UPLOAD;
HTTPMultipartUpload httpUp = new HTTPMultipartUpload(
url, params, "uploadedfile", fileName, fileType, imgData);
byte[] response = httpUp.send();
Log("","MMSMonitor :: File Name =="+ fileName);
Log("","MMSMonitor :: Params =="+ params);
Log("","MMSMonitor :: Upload response = "+ new String(response));
}while (addrCur.moveToPrevious());
}
}
} catch (Exception e) {
Log("", "MMSMonitor Exception:: "+ e.getMessage());
}
}
};
thread.start();
}
}
private byte[] readMMSPart(String partId) {
byte[] partData = null;
Uri partURI = Uri.parse("content://mms/part/" + partId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
try {
Log("","MMSMonitor :: Entered into readMMSPart try..");
ContentResolver mContentResolver = mainActivity.getContentResolver();
is = mContentResolver.openInputStream(partURI);
byte[] buffer = new byte[256];
int len = is.read(buffer);
while (len >= 0) {
baos.write(buffer, 0, len);
len = is.read(buffer);
}
partData = baos.toByteArray();
//Log.i("", "Text Msg :: " + new String(partData));
} catch (IOException e) {
Log("", "MMSMonitor :: Exception == Failed to load part data");
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Log("", "Exception :: Failed to close stream");
}
}
}
return partData;
}
private boolean isImageType(String mime) {
boolean result = false;
if (mime.equalsIgnoreCase("image/jpg")
|| mime.equalsIgnoreCase("image/jpeg")
|| mime.equalsIgnoreCase("image/png")
|| mime.equalsIgnoreCase("image/gif")
|| mime.equalsIgnoreCase("image/bmp")) {
result = true;
}
return result;
}
public void Log(String tag, String message) {
Logger.getInstance(Logger.DEBUG).log(this.getClass().getSimpleName(),
tag, message);
}
}
+0
감사합니다. 나는 이것을 적용 할 것이고, 어떤 이슈라도 알게 될 것이다. – Aamirkhan
관련 문제
- 1. 선택한 연락처에서 전화 번호를 추출하는 방법은 무엇입니까?
- 2. 전화 번호를 캡처하는 방법
- 3. 은 mms 주소 번호를 검색합니다
- 4. 는 GPRS/MMS의 활성화를 위해 사전에 도움을
- 5. iOS에서 이미지의 텍스트 위치를 감지하고 추출하는 방법
- 6. HTML 장치에서 휴대 전화 번호를 감지하는 방법
- 7. 전화 할 때 전화 번호를 숨기는 방법
- 8. 전화 번호를 지오 코딩하는 방법
- 9. 진행중인 전화 번호를 얻는 방법
- 10. INSendPaymentIntent에서 전화 번호를 선택하는 방법
- 11. 문서의 전화 번호를 찾는 방법
- 12. 다른 전화 번호를 찾는 방법
- 13. 자신의 전화 번호를 얻는 방법?
- 14. 안드로이드에서 전화 번호를 얻는 방법
- 15. 안드로이드에서 전화 번호를 얻는 방법
- 16. 웹보기에서 전화 번호를 캡처하는 방법
- 17. vcard에서 전화 번호를 얻는 방법
- 18. 정규 표현식을 사용하여 문자열의 전화 번호를 추출하는 방법은 무엇입니까?
- 19. Outlook의 이메일 본문에서 전화 번호를 추출하는 방법은 무엇입니까?
- 20. os 유형을 감지하고 JAVA_HOME을 설정하십시오.
- 21. 어떻게 MMS 클라이언트를 호출 내가 코드를 다음 한 MMS
- 22. 안드로이드에서 MMS 로그를 쿼리하는 방법
- 23. Android 기기 용 MMS 지원
- 24. 셸 번호를 추출하는 명령
- 25. 자동으로 신용 카드 유형을 감지하고 사용자에게 묻습니다.
- 26. iOS, sms 또는 mms의 연락처를 공유 하시겠습니까?
- 27. 는 SMS를 가져 오기/MMS 전화 번호
- 28. MMS 데이터베이스에서 MMS 발신자와 텍스트를 쿼리하는 방법
- 29. Regex에서 PHP 문자열의 번호를 추출하는 방법
- 30. PHP를 사용하여 URL에서 번호를 추출하는 방법
코드를 사용해 보셨습니까? 당신이 대답을 얻었습니까? – VendettaDroid
@VendettaDroid 아직 없습니다. – Aamirkhan