2013-01-21 3 views
1

날씨를 감지하고 싶습니다. mms recived 또는 그렇지 않은 경우, mms에 근거하여 내가 가지고있는 유형을 감지해야합니다. 그 후 전화 번호를 추출하고 싶습니다. 어느 누구도이 문제를 해결하기 위해 나를 도울 수 있습니까? 감사합니다.mms 유형을 감지하고 mms의 전화 번호를 추출하는 방법

+0

코드를 사용해 보셨습니까? 당신이 대답을 얻었습니까? – VendettaDroid

+0

@VendettaDroid 아직 없습니다. – Aamirkhan

답변

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

관련 문제