2013-04-17 12 views
13

MMSの画像コンテンツをMMS URLからダウンロードしようとしていますが、無効なMSISDNという番号の403(禁止)サーバー応答が返されます。私は参照のために私のコードを貼り付けました。前もって感謝します!android mms mmsコンテンツからmms URLをダウンロード

private static boolean downloadThroughGateway(Context context, String host, 
      String port, String urlMms) throws Exception { 
     URL url = new URL(urlMms); 

     // Set-up proxy 
     if (host != null && port != null && host.equals("") && !port.equals("")) { 
      Log.d(TAG, "[MMS Receiver] Setting up proxy (" + host + ":" + port 
        + ")"); 
      Properties systemProperties = System.getProperties(); 
      systemProperties.setProperty("http.proxyHost", host); 
      systemProperties.setProperty("http.proxyPort", port); 
      systemProperties.setProperty("http.keepAlive", "false"); 
     } 

     // Open connection 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 

     // Disable cache 
     connection.setUseCaches(false); 

     // Set the timeouts 
     connection.setConnectTimeout(TIMEOUT); 
     connection.setReadTimeout(TIMEOUT); 

     // Connect to the MMSC 
     Log.d(TAG, "[MMS Receiver] Connecting to MMS Url " + urlMms); 
     connection.connect(); 

     try { 
      Log.d(TAG, 
        "[MMS Receiver] Response code is " 
          + connection.getResponseCode()); 

      if (connection.getContentLength() >= 0) { 
       Log.d(TAG, "[MMS Receiver] Download MMS data (Size: " 
         + connection.getContentLength() + ")"); 
       byte[] responseArray = new byte[connection.getContentLength()]; 
       DataInputStream i = new DataInputStream(
         connection.getInputStream()); 
       int b = 0; 
       int index = 0; 
       while ((b = i.read()) != -1) { 
        responseArray[index] = (byte) b; 
        index++; 
       } 
       i.close(); 

       // Parse the response 
       MmsDecoder parser = new MmsDecoder(responseArray); 
       parser.parse(); 

       byte[][] imageBytes = new byte[parser.getParts().size()][]; 
       for (int j = 0; j < parser.getParts().size(); j++) { 
        imageBytes[j] = parser.getParts().get(j).getContent(); 
       } 

       // Insert into db 
       // Uri msgUri = MmsHelper.insert(context, parser.getFrom(), 
       // parser.getSubject(), imageBytes); 
       // ContentValues updateValues = new ContentValues(); 
       // updateValues.put("read", 0); 
       // context.getContentResolver().update(msgUri, updateValues, 
       // null, 
       // null); 

       // Close the connection 
       Log.d(TAG, "[MMS Receiver] Disconnecting ..."); 
       connection.disconnect(); 

       System.gc(); 

       // Callback 
       // if (bi != null) 
       // bi.onReceiveMms(context, msgUri); 

       return true; 
      } 

      // Close the connection 
      Log.d(TAG, "[MMS Receiver] Disconnecting ..."); 
      connection.disconnect(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return false; 
    } 
+0

ユーザーアクセス資格情報はどうですか?正しい資格情報がデータサービスアクセス用に設定されているかどうかを確認しましたか。 WireSharkなどの(ネットワークプロトコルアナライザ)ツールを使用して、MMS送信要求(HTTP PDU)とリモートMMSCからの対応する応答を解読しようとしましたか?リモートMMSC URLなどの接続に関する詳細を提供することなく、ログイン資格情報の再現が困難で、問題の修正を提供します。 – Sriram

+0

資格情報を渡す方法と、提供する必要がある資格情報についての情報もありませんでしたか? –

+1

まず、ブラウザでgoogle.comにアクセスして起動できることを確認してください。次に、(On android 2.0の)設定 - >モバイルネットワーク - >アクセスポイント名 - >ネットワークプロバイダの名前にナビゲートして、MMS固有の設定に移動できます。ここでは、1)MMSC 2)MMSプロキシ3)MMSポート4)ユーザー名5)パスワードなどのタブがあります。 – Sriram

答えて

3

は今、私は解決策を見つけることができるが、私はいつかダウンロードコードが動作していないことが判明しかし、あなたがもう一度しようとすると、それは私が最初のサーバーへの接続を確立を欠けていたものが動作します。私は接続メソッドの下にこの呼び出しの後で、この質問のコードに言及しているメソッド名downloadThroughGateway(パラメータ)を記述しています。

private void startConnectivity() throws Exception { 
     ConnectivityManager mConnMgr = (ConnectivityManager) context 
       .getSystemService(Context.CONNECTIVITY_SERVICE); 
     if (!mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS) 
       .isAvailable()) { 
      throw new Exception("Not available yet"); 
     } 
     int count = 0; 
     int result = beginMmsConnectivity(mConnMgr); 
     if (result != PhoneEx.APN_ALREADY_ACTIVE) { 
      NetworkInfo info = mConnMgr 
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS); 
      while (!info.isConnected()) { 
       Thread.sleep(1500); 
       info = mConnMgr 
         .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS); 
       Log.d(">>>", "Waiting for CONNECTED: state=" + info.getState()); 
       if (count++ > 5) 
        throw new Exception("Failed to connect"); 
      } 
     } 
     Thread.sleep(1500); 
    } 
+0

MmsDecoderクラスはどこにありますか? – user1163234

+0

私はこれと似たようなことをしています! http://stackoverflow.com/questions/21748209/receive-mms-messages-in-android-kitkat – toobsco42

関連する問題