السلام عليكم ورحمة الله وبركاته
كنت سألت فى موضوع سابق عن عرض الصور وتم بحمد الله عرض الصور وكانت المشكلة عند عمل connection إضافة deviceside=false;ConnectionType=mds-public إلى الURL
ولكن عندما أردت عمل داونلود لملفات صوت لم أستطع ولم يحدث داونلود مع إن الconnection يتم فأرجو المساعدة وهذا هو الكود الذى أستخدمه
{
try
{
String pathis =path+url+";deviceside=false;ConnectionType=mds-public";
System.out.println(pathis);
httpConnection=(HttpConnection)Connector.open(pathis,Connector.READ_WRITE);
httpConnection.setRequestMethod("GET");
}catch(Exception ee){ee.printStackTrace();}
}
private boolean writeFile(String path,byte []outputData)
{
javax.microedition.io.Connection connection=null;
OutputStream os=null;
try
{
// "file:///files/preferences.pfs"
String pathis="file:///"+localPath+path;
connection=Connector.open(pathis,Connector.READ_WRITE);
FileConnection fileConnection=(FileConnection)connection;
if(!fileConnection.exists())
{
System.out.println("can write"+ fileConnection.canWrite());
fileConnection.create();
}
else
fileConnection.truncate(0);
os=fileConnection.openOutputStream();
os.write(outputData);
os.flush();
return true;
}catch(Exception ee)
{
ee.printStackTrace();
return false;
}
finally
{
try{
if(os!=null)
{
os.close();
}
if(connection!=null)
{
connection.close();
}
}catch(Exception ee)
{
ee.printStackTrace();
}
}
}
public void downloadFile(final String file)
{
Thread thread=new Thread()
{
public void run()
{
try {
openConnection(file);
InputStream is = httpConnection.openInputStream();
ByteArrayOutputStream bstr = new ByteArrayOutputStream();
int ch;
int value=((is.available()/downloader.gauge.getMaxValue()));
int count=1;
while((ch = is.read())!= -1)
{
bstr.write(ch);
count++;
if((count%value)==1)
{
downloader.gauge.setValue((downloader.gauge.getValue()+1));
}
if(cancel)
{
break;
}
sleep(1);
}
downloader.downloadComplete();
byte [] byteAudio = bstr.toByteArray();
InputStream is1 = new ByteArrayInputStream(byteAudio);
writeFile(file, byteAudio);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
};
thread.start();
}
public void openConnection(String url)