Android 安卓彩信通过彩信url下载彩信内容
我正试图通过彩信url下载Android 安卓彩信通过彩信url下载彩信内容,android,mms,msisdn,Android,Mms,Msisdn,我正试图通过彩信url下载MMS图片内容,但它返回403(禁止)服务器响应,带有无效的MSISDN编号。我在下面粘贴了我的代码以供参考。提前谢谢 private static boolean downloadThroughGateway(Context context, String host, String port, String urlMms) throws Exception { URL url = new URL(urlMms);
MMS
图片内容,但它返回403(禁止)服务器响应,带有无效的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;
}
private static boolean downloadThroughGateway(上下文、字符串主机、,
字符串端口,字符串URL(MMS)引发异常{
URL=新URL(urlMms);
//设置代理
if(host!=null&&port!=null&&host.equals(“”)&&port.equals(“”){
Log.d(标记“[MMS接收器]设置代理”(“+host+”:“+port
+ ")");
Properties systemProperties=System.getProperties();
setProperty(“http.proxyHost”,host);
setProperty(“http.proxyPort”,port);
setProperty(“http.keepAlive”、“false”);
}
//开放连接
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
//禁用缓存
connection.setUseCaches(false);
//设定暂停时间
connection.setConnectTimeout(超时);
connection.setReadTimeout(超时);
//连接到MMSC
Log.d(标记“[MMS接收器]连接到MMS Url”+urlMms);
connection.connect();
试一试{
Log.d(标签,
“[MMS接收器]响应代码为”
+connection.getResponseCode());
if(connection.getContentLength()>=0){
Log.d(标签,“[MMS接收器]下载彩信数据(大小:”
+connection.getContentLength()+“”);
byte[]responseArray=新字节[connection.getContentLength()];
DataInputStream i=新的DataInputStream(
connection.getInputStream());
int b=0;
int指数=0;
而((b=i.read())!=-1){
responseArray[索引]=(字节)b;
索引++;
}
i、 close();
//解析响应
彩信解码器解析器=新的彩信解码器(responseArray);
parser.parse();
字节[][]图像字节=新字节[parser.getParts().size()][];
for(int j=0;j
现在我能够找到解决方案,但我发现有时下载的代码不起作用,但当您再次尝试时,它起作用,尽管我所缺少的首先建立了与服务器的连接。我在下面提到了连接方法,在此调用之后,方法名称downloadThroughGateway(parameters),这是在这个问题代码中提到的
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);
}
用户访问凭据呢?您是否检查了是否为数据服务访问设置了正确的凭据。您是否尝试过使用WireShark等(网络协议分析器)工具。。解密MMS提交请求(HTTP PDU)和来自远程MMSC的相应响应。未提供有关连接的任何详细信息,如远程MMSC URL,登录凭据很难复制并提供问题的解决方案。如何传递凭据,我也没有需要提供的有关凭据的任何信息?首先,请检查您是否能够在浏览器上成功访问并启动google.com。然后,您可以通过导航到(在android 2.0上)设置->移动网络->接入点名称->您的网络提供商名称,导航到彩信特定的设置。在这里,您可以找到如下选项卡:1.)彩信2.)彩信代理3.)彩信端口4.)用户名5.)密码。一旦您在手机上的上述选项卡下设置了正确的凭据,请参阅帖子()通过编程读取这些凭证来设置连接参数。实际上,您可以在这里观察其他信息,我正在做类似的事情!!!