我在做一款播放器软件 想要实现下载MP3的功能可以将MP3文件下载到SD卡上,而且下载的时候可以跳转到别的页面,而下载仍然继续。用AsyncTask可以做么?如果不能请各位大神给出一个合理的方案。
解决方案 »
- 声音管理类里AudioManager里setMode和setRingMode的区别
- ZXing源码包中,google官方给的例子到底是哪个。。。
- eclipse4.2中ADT18,layout目录下的xml文件无法使用复制,粘贴等快捷键!
- 求类似gallery效果,效果如同ViewFlipper的控件
- Android 迷茫
- 请问下,下面这些文件之间的关系是什么,谢谢
- 界面 弹出自定义View
- Android源码编译出问题
- 关于Eclipse安卓模拟器通过http访问地址的问题
- Android popupWindow 问题,跪求大神,
- Android如何获取系统空闲时间
- 不小心把R.java删除了,怎么样再自动生成出来
private void getDataSource(String strPath) throws Exception
{
if (!URLUtil.isNetworkUrl(strPath))
{
mTextView01.setText("错误的URL");
}
else
{
/*取得URL*/
URL myURL = new URL(strPath);
/*创建连接*/
URLConnection conn = myURL.openConnection();
conn.connect();
/*InputStream 下载文件*/
InputStream is = conn.getInputStream();
if (is == null)
{
throw new RuntimeException("stream is null");
}
/*创建临时文件*/
File myTempFile = File.createTempFile(fileNa, "."+fileEx);
/*取得站存盘案路径*/
currentTempFilePath = myTempFile.getAbsolutePath();
/*将文件写入暂存盘*/
FileOutputStream fos = new FileOutputStream(myTempFile);
byte buf[] = new byte[128];
do
{
int numread = is.read(buf);
if (numread <= 0)
{
break;
}
fos.write(buf, 0, numread);
}while (true);
/*打开文件进行安装*/
openFile(myTempFile);
try
{
is.close();
}
catch (Exception ex)
{
Log.e(TAG, "error: " + ex.getMessage(), ex);
}
}
}
在service里面开个子线程。然后把这代码放进去就可以了
http://blog.csdn.net/Android_Tutor/archive/2010/08/04/5789203.aspx