Я пытаюсь загрузить содержимое изображения MMS
через URL-адрес MMS, но он возвращается с ответом сервера 403 (Forbidden) с недопустимым номером MSISDN
. Я применил свой код ниже для справки. Спасибо заранее!
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;
}