1、權限
2、代碼
name=etmc.gettext().tostring();//擷取歌曲自定義名稱
byte[]
bname=name.getbytes();
try
{
name=new string(bname,"utf-8");//中文轉碼
}
catch
(unsupportedencodingexception e1)
e1.printstacktrace();
new
thread()
public void
run()
url url=new
url(uri);//擷取連結
httpurlconnection conn = (httpurlconnection)
url.openconnection();//打開連結
conn.setconnecttimeout(6*
1000);//設定時間緩沖
if (conn.getresponsecode() != 200) throw new
runtimeexception("請求url失敗");//判斷連結是否失敗
inputstream is =
conn.getinputstream();//擷取inputstream流對象
readasfile(is,new
file("/sdcard/"+name+".mp3"));//将擷取inputstream流對象資料存入指定檔案夾
catch (exception e)
e.printstacktrace();
}.start();