Android 常用代码块

来源:互联网 发布:php流量统计源码 编辑:程序博客网 时间:2024/05/17 07:36

1.去标题

方法一 :
//setTheme(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_NO_TITLE);//在setContentView
setContentView(R.layout.activity_main);  
缺点:在每个activity中都需要设置

方法二:
 android:theme="@style/AppTheme"  更改为:
 android:theme="@android:style/Theme.Black.NoTitleBar"  
缺点:应用的所有默认样式都被更改

2.XML

1.对象保存为xml文件 

File file = new File(getFilesDir(),num+".xml");
FileOutputStream os = new FileOutputStream(file);
//采用谷歌api 生成xml文件
//1.获取一个xml文件的生成器,序列化器
XmlSerializer serializer = Xml.newSerializer();
//2.初始化序列化器 设置写到哪个文件,采用什么样的编码方式
serializer.setOutput(os, "utf-8");
//3.开始写数据 ,写xml文件头,文档为独立的xml文件
serializer.startDocument("utf-8", true);
serializer.startTag(null, "student");
serializer.startTag(null, "name");
serializer.text(name);
serializer.endTag(null, "name");
serializer.startTag(null, "num");
serializer.text(num);
serializer.endTag(null, "num");
serializer.startTag(null, "sex");
if(rg_sex.getCheckedRadioButtonId()==R.id.rb_male){
serializer.text("male");
}else{
serializer.text("female");
}
serializer.endTag(null, "sex");
serializer.endTag(null, "student");
serializer.endDocument();
os.close();
Toast.makeText(this, "保存数据成功", 0).show();
2. 使用PullParser解析器解析xml
List<NewsItem> newsItems = new ArrayList<NewsItem>();
//代表一条新闻
NewsItem newsItem = null;
XmlPullParser parser = Xml.newPullParser();
// 设置参数
parser.setInput(is, "utf-8");
// 开始解析
int type = parser.getEventType();
while (type != XmlPullParser.END_DOCUMENT) {
switch (type) {
case XmlPullParser.START_TAG://标签开始
if("item".equals(parser.getName())){
//一个新闻数据要开始了。
newsItem = new NewsItem();
}else if("title".equals(parser.getName())){
String title = parser.nextText();
newsItem.setTitle(title);
}else if("description".equals(parser.getName())){
String description = parser.nextText();
newsItem.setDesc(description);
}else if("image".equals(parser.getName())){
String image = parser.nextText();
newsItem.setImage(image);
}else if("type".equals(parser.getName())){
String newtype = parser.nextText();
newsItem.setType(Integer.parseInt(newtype));
}else if("comment".equals(parser.getName())){
String comment = parser.nextText();
newsItem.setComment(Integer.parseInt(comment));
}
break;
case XmlPullParser.END_TAG://标签结束
if("item".equals(parser.getName())){
newsItems.add(newsItem);
}
break;
}
type = parser.next();// 解析下一个事件
}
return newsItems;

  使用dom4j解析xml,以读取备份的短信为例:
//RestoreSmsCallback //解析xml过程中的回调

public static void restore(Context c,FileInputStream fis,RestoreSmsCallback callback) {SAXReader reader = new SAXReader();int count = 0;try {Document doc = reader.read(fis);Element root = doc.getRootElement();int amount=Integer.parseInt(root.attribute(0).getText());callback.onStart(amount);List<Element> eleSmss = root.elements("sms");callback.onStart(eleSmss.size());ContentValues values = new ContentValues();for (Element smsEle : eleSmss){String address =smsEle.elementText("address");//电话号    values.put("address", address);    String body = EncryptUtil.decrypt(SEED, smsEle.elementText("body"));//电话号    System.out.println(body);    values.put("body", body);    values.put("date", smsEle.elementText("date"));    values.put("type", smsEle.elementText("type"));    //还原短信    //c.getContentResolver().insert(Uri.parse("content://sms/sent"), values);    callback.onDoing(++count);}} catch (DocumentException e) {callback.onFailed(e);e.printStackTrace();} catch (Exception e) {callback.onFailed(e);e.printStackTrace();}callback.onFinish(count);}


3.下载网络上的文件

String path = context.getResources().getString(R.string.serverip);
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
//设置连接超时时间
conn.setConnectTimeout(5000);
//设置读取超时时间
conn.setReadTimeout(5000);
int code = conn.getResponseCode();
if(code ==200){
InputStream is = conn.getInputStream();//代表的rss数据源,xml文件。
return NewsInfoParser.parseNews(is);
}

4.测试

1.继承AndroidTestCase类
public class TestCalcService extends AndroidTestCase{
/**
 * 2.编写测试方法记得 说有的测试方法 都应该是public
 * 记得让测试方法直接抛出异常
 * 根据需求进行断言操作 assert
 */
public void testAdd() throws Exception{
CalcService calcService = new CalcService();
int result = calcService.add(3, 5);
assertEquals(8, result);
}
}
2. 在AndroidManifest.xml中配置  测试lib和测试类
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.itheima.junit"    android:versionCode="1"    android:versionName="1.0" ><instrumentation android:name="android.test.InstrumentationTestRunner"    android:targetPackage="com.itheima.junit"></instrumentation>    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >       <uses-library android:name="android.test.runner"/>        <activity            android:name="com.itheima.junit.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


4. 常用 utils

1.Stream 转化为String
/**
* 流的工具类
*
* @author Administrator
*
*/
public class StreamTools {
/**
* 把输入流的内容转换成字符串
*
* @param is
* @return null解析失败, string读取成功
*/
public static String readStream(InputStream is) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
is.close();
String temptext = new String(baos.toByteArray());
return new String(baos.toByteArray(), "gbk");
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
public class StreamTools {/** * 把输入流的内容转换成字符串 * @param is * @return null解析失败, string读取成功 */public static String readStream(InputStream is) {try {ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = -1;while( (len = is.read(buffer))!=-1){baos.write(buffer, 0, len);}is.close();String temptext = new String(baos.toByteArray());if(temptext.contains("charset=gb2312")){//解析meta标签return new String(baos.toByteArray(),"gb2312");}else{return new String(baos.toByteArray(),"utf-8");}} catch (IOException e) {e.printStackTrace();return null;}}}
2.在任意类修改主线程的ui
private void showToastInAnyThread(final String text) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, text, 0).show();
}
});
}
3.解析jason
普通jason
if(code == 200){
//得到json数据,字符串
InputStream is = conn.getInputStream();
String json = StreamTools.readStream(is).replace("__GetZoneResult_ = ", "");
JSONObject jsonObject = new JSONObject(json);
final String catName = jsonObject.getString("catName");
final String province = jsonObject.getString("province");
showToastInAnyThread( "运营商:"+catName+"\n归属地:"+province);
}
4jasonArray
private String jsonStr = "{carrier:'重庆移动'}";
private String jsonArrStr ="[{carrier:'重庆移动'},{carrier:'广东移动'},{carrier:'广西移动'}]";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
JSONArray jsonArray = new JSONArray(jsonArrStr);
String str = jsonArray.get(0).toString();
System.out.println(str);
} catch (Exception e) {
e.printStackTrace();
}
}

5.SharedPreferences

SharedPreferences sp= this.getSharedPreferences("config.xml", 0);
CheckBox cb = (CheckBox) findViewById(R.id.cb);
//回显数据
boolean status = sp.getBoolean("status", false);//第一个是key 第二个参数是默认值
cb.setChecked(status);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(MainActivity.this, "勾选状态:"+isChecked, 0).show();
//获取编辑器i
Editor editor = sp.edit();
editor.putBoolean("status", isChecked);
editor.commit();//数据库的事务 ,提交数据。把数据保存起来
}
});

    

5.动画

1.gif 显示 开源的GifMovieView
public class MainActivity extends Activity {
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final GifMovieView gif1 = (GifMovieView) findViewById(R.id.gif1);
gif1.setMovieResource(R.drawable.gif_heart);
}
public void onGifClick(View v) {
GifMovieView gif = (GifMovieView) v;
gif.setPaused(!gif.isPaused());
}
 
}
2.补单动画 Tween Animnation
有5个分类

AlphaAnimation:透明度(alpha)渐变效果,对应<alpha/>标签。

TranslateAnimation:位移渐变,需要指定移动点的开始和结束坐标,对应<translate/>标签。

ScaleAnimation:缩放渐变,可以指定缩放的参考点,对应<scale/>标签。

RotateAnimation:旋转渐变,可以指定旋转的参考点,对应<rotate/>标签。

AnimationSet:组合渐变,支持组合多种渐变效果,对应<set/>标签。

java 实现:
RotateAnimation rotateAnima = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);rotateAnima.setDuration(1000);rotateAnima.setFillAfter(true); // 设置动画执行完毕时, 停留在完毕的状态下.ScaleAnimation scaleAnima = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);scaleAnima.setDuration(1000);scaleAnima.setFillAfter(true);AlphaAnimation alphaAnima = new AlphaAnimation(0, 1);alphaAnima.setDuration(2000);alphaAnima.setFillAfter(true);// 把三个动画合在一起, 组成一个集合动画AnimationSet setAnima = new AnimationSet(false);setAnima.addAnimation(rotateAnima);setAnima.addAnimation(scaleAnima);setAnima.addAnimation(alphaAnima);rootView.startAnimation(setAnima);setAnima.setAnimationListener(this);
xml文件实现 旋转动画:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"      android:interpolator="@android:anim/accelerate_decelerate_interpolator"      android:fromDegrees="0"      android:toDegrees="360"      android:duration="1000"      android:repeatCount="1"      android:repeatMode="reverse"/>  <!--   fromDegrees:表示旋转的起始角度  toDegrees:表示旋转的结束角度  repeatCount:旋转的次数  默认值是0 代表旋转1次  如果值是repeatCount=4 旋转5次,值为-1或者infinite时,表示补间动画永不停止  repeatMode 设置重复的模式。默认是restart。当repeatCount的值大于0或者为infinite时才有效。  repeatCount=-1 或者infinite 循环了  还可以设成reverse,表示偶数次显示动画时会做与动画文件定义的方向相反的方向动行。   -->  



3.属性动画
java实现
ObjectAnimator oa=ObjectAnimator.ofFloat(v, "rotation",0,360);oa.setDuration(5000);oa.setRepeatCount(ObjectAnimator.INFINITE);oa.start();
xml实现:
<?xml version="1.0" encoding="utf-8"?><objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="2000"    android:propertyName="translationX"    android:valueFrom="0"    android:valueTo="200"    android:valueType="floatType" ></objectAnimator>



6.Handler 处理消息

handler.post(),handler.send();
//1.在主线程里面声明消息处理器 handler
private Handler handler = new Handler(){
//处理消息的
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case YIHAOYUANGONG:
//3.处理消息 运行在主线程
Bitmap bitmap = (Bitmap) msg.obj;
iv.setImageBitmap(bitmap);
System.out.println("1号员工的缓存图片");
break;
case ERHAOYUANGONG:
Bitmap bitmap2 = (Bitmap) msg.obj;
iv.setImageBitmap(bitmap2);
System.out.println("2号员工的下载的图片");
break;
case ERROR:
Toast.makeText(MainActivity.this, "请求失败", 0).show();
break;
case EXCEPTION:
Toast.makeText(MainActivity.this, "发生异常,请求失败", 0).show();
break;
}
super.handleMessage(msg);
}
};

Android的AsyncTask比Handler更轻量级一些,适用于简单的异步处理。

public class ProgressBarAsyncTask extends AsyncTask<Integer, Integer, String> {private TextView textView;private ProgressBar progressBar;public ProgressBarAsyncTask(TextView textView, ProgressBar progressBar) {super();this.textView = textView;this.progressBar = progressBar;}/*** 这里的Integer参数对应AsyncTask中的第一个参数* 这里的String返回值对应AsyncTask的第三个参数* 该方法并不运行在UI线程当中,主要用于异步操作,所有在该方法中不能对UI当中的空间进行设置和修改* 但是可以调用publishProgress方法触发onProgressUpdate对UI进行操作*/@Overrideprotected String doInBackground(Integer... params) {NetOperator netOperator = new NetOperator();int i = 0;for (i = 10; i <= 100; i+=10) {netOperator.operator();publishProgress(i);}return i + params[0].intValue() + "";}/*** 这里的String参数对应AsyncTask中的第三个参数(也就是接收doInBackground的返回值)* 在doInBackground方法执行结束之后在运行,并且运行在UI线程当中 可以对UI空间进行设置*/@Overrideprotected void onPostExecute(String result) {textView.setText("异步操作执行结束" + result);}//该方法运行在UI线程当中,并且运行在UI线程当中 可以对UI空间进行设置@Overrideprotected void onPreExecute() {textView.setText("开始执行异步线程");}/*** 这里的Intege参数对应AsyncTask中的第二个参数* 在doInBackground方法当中,,每次调用publishProgress方法都会触发onProgressUpdate执行* onProgressUpdate是在UI线程中执行,所有可以对UI空间进行操作*/@Overrideprotected void onProgressUpdate(Integer... values) {int vlaue = values[0];progressBar.setProgress(vlaue);}


7.文件权限

1.文件访问权限MODE_PRIVATE,MODE_WORLD_WRITEABLE,MODE_WORLD_READABLE,MODE_WORLD_READABLE+MODE_WORLD_WRITEABLE
public void click(View view) {
try {
int id = rg_mode.getCheckedRadioButtonId();
FileOutputStream fos = null;
switch (id) {
case R.id.rb_private:// 私有文件
fos = openFileOutput("private.txt", MODE_PRIVATE);
break;
case R.id.rb_public:// 可读可写文件
fos = openFileOutput("public.txt", + MODE_WORLD_READABLE+MODE_WORLD_WRITEABLE
break;
case R.id.rb_readble:// 全局可读文件
fos = openFileOutput("readble.txt", MODE_WORLD_READABLE);
break;
case R.id.rb_writeable:// 全局可写文件
fos = openFileOutput("writeable.txt", MODE_WORLD_WRITEABLE);
break;
}
fos.write("dfafda".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
2


8.向server 提交数据

1.get 方式
拼接url ,其中的中文需要转码后发送,长度不能超过4k
安全性低
优点,代码简单
String path = getString(R.string.serverip);
URL url = new URL(path+"?qq="+URLEncoder.encode(qq,"utf-8")+"&password="+URLEncoder.encode(pwd,"utf-8"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
int code = conn.getResponseCode();
if(code == 200){
InputStream is = conn.getInputStream();
String result = StreamTools.readFromStream(is);
showToastInAnyThread(result);
}else{
showToastInAnyThread("请求失败:"+code);
}

2.post 方式
 数据是以流的方式写给服务器
>优点:1.安全  2. 长度没有限制
>缺点:代码编写麻烦

        //重要:记得设置请求方式post
        conn.setRequestMethod("POST");
        //重要:记得设置数据的类型
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        String data = "qq="+qq+"&password="+pwd;
        //重要,记得设置数据的长度
        conn.setRequestProperty("Content-Length", String.valueOf(data.length()));
        //重要,记得给服务器写数据
        conn.setDoOutput(true);//声明要给服务器写数据
        //重要,把数据写给服务器。
        conn.getOutputStream().write(data.getBytes());
//post请求提交数据
String path = getString(R.string.serverip);
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//重要:记得设置请求方式post
conn.setRequestMethod("POST");
//重要:记得设置数据的类型
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String data = "qq="+URLEncoder.encode(qq, "utf-8")+"&password="+URLEncoder.encode(pwd, "utf-8");
//重要,记得设置数据的长度
conn.setRequestProperty("Content-Length", String.valueOf(data.length()));
//重要,记得给服务器写数据
conn.setDoOutput(true);//声明要给服务器写数据
//重要,把数据写给服务器。
conn.getOutputStream().write(data.getBytes());
int code = conn.getResponseCode();
if(code == 200){
InputStream is = conn.getInputStream();
String result = StreamTools.readFromStream(is);
showToastInAnyThread(result);
}else{
showToastInAnyThread("请求失败:"+code);
}



使用Apache-Httpclient 

##Apache-Httpclient
>代码模拟浏览器的行为
>1. 打开浏览器
>2. 输入数据
>3. 敲回车
public void run() {
String path = "http://10.0.2.2:8080/User/login";
Message msg = Message.obtain();
try {
/*////使用get方式
//1.打开浏览器
HttpClient client=new DefaultHttpClient();
//2.输入网址
HttpGet get=new HttpGet(path+"?name="+URLEncoder.encode(name, "utf-8")+"?password="+URLEncoder.encode(pwd, "utf-8"));
//3回车
HttpResponse response = client.execute(get);
int code = response.getStatusLine().getStatusCode();
if (200 == code) {
InputStream in = response.getEntity().getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String responseMsg = new String(baos.toByteArray());
// msg.what=1;
msg.obj = responseMsg;
 
}else{
msg.obj =code;
}
*/
////post方式
HttpClient client=new DefaultHttpClient();
HttpPost post=new HttpPost(path);
String data="name="+URLEncoder.encode(name, "utf-8")+"?password="+URLEncoder.encode(pwd, "utf-8");
List<NameValuePair> ls=new ArrayList<NameValuePair>();
NameValuePair names=new BasicNameValuePair("name",name);
ls.add(names);
ls.add(new BasicNameValuePair("password",pwd));
post.setEntity(new UrlEncodedFormEntity(ls,"utf-8"));
client.execute(post);
HttpResponse response = client.execute(post);
int code = response.getStatusLine().getStatusCode();
if (200 == code) {
InputStream in = response.getEntity().getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String responseMsg = new String(baos.toByteArray());
// msg.what=1;
msg.obj = responseMsg;
 
}else{
msg.obj =code;
}
 
} catch (Exception e) {
// msg.what=-1;
// msg.obj="net connection error ! try again later ";
msg.obj = e.toString();
e.printStackTrace();
}
handler.sendMessage(msg);
}
}).start();

AsyncHttpClient

get
//登陆的操作,网络请求
AsyncHttpClient client = new AsyncHttpClient();
String url = getResources().getString(R.string.serverip)+"?qq="+URLEncoder.encode(qq)+"&password="+URLEncoder.encode(pwd);
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Toast.makeText(MainActivity.this, new String(responseBody), 0).show();
}
@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
Toast.makeText(MainActivity.this, new String(responseBody), 0).show();
}
});
post

//登陆的操作,网络请求
AsyncHttpClient client = new AsyncHttpClient();
String url = getResources().getString(R.string.serverip);
RequestParams params = new RequestParams();
params.put("qq", qq);
params.put("password", pwd);
client.post(url, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Toast.makeText(MainActivity.this, new String(responseBody), 0).show();
}
@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
Toast.makeText(MainActivity.this, new String(responseBody), 0).show();
}
});
//上传文件
public void upload(View view){
String path = et_path.getText().toString().trim();
File file = new File(path);
if(file.exists()){
String serverurl = getString(R.string.server);
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
try {
params.put("file", file);
} catch (FileNotFoundException e) {
e.printStackTrace();
} // Upload a File
client.post(serverurl, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Toast.makeText(MainActivity.this, "上传成功", 0).show();
}
@Override
public void onProgress(int bytesWritten, int totalSize) {
progressBar1.setMax(totalSize);
progressBar1.setProgress(bytesWritten);
super.onProgress(bytesWritten, totalSize);
}
@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
Toast.makeText(MainActivity.this, "上传失败", 0).show();
}
});
}else{
Toast.makeText(this, "文件不存在,请检查路径", 0).show();
}
}
3.多线程下载文件 FinalHttp
public void download(View view) {
path = et_path.getText().toString().trim();
if (TextUtils.isEmpty(path) && !path.startsWith("http://")) {
Toast.makeText(this, "下载路径不合法", 0).show();
return;
}
FinalHttp fh = new FinalHttp();
fh.download(path, "/mnt/sdcard/haha.exe", true, new AjaxCallBack<File>() {
 
@Override
public void onLoading(long count, long current) {
pb.setMax((int) count);
pb.setProgress((int) current);
super.onLoading(count, current);
}
 
@Override
public void onSuccess(File t) {
Toast.makeText(MainActivity.this, "下载成功", 0).show();
super.onSuccess(t);
}
 
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
System.out.println(strMsg);
super.onFailure(t, errorNo, strMsg);
}
});
 
}
4.多线程下载文件 xUtils

public void download(View v){
HttpUtils http=new HttpUtils();
String path=et_path.getText().toString();
String fileName=Environment.getExternalStorageDirectory()+"/"+path.substring(path.lastIndexOf("/")+1);
http.download(path,fileName,new RequestCallBack<File>() {
@Override
public void onLoading(long total, long current, boolean isUploading) {
pb_proc.setMax((int) total);
pb_proc.setProgress((int) current);
}
 
@Override
public void onStart() {
Toast.makeText(MainActivity.this,"开始下载",0).show();
super.onStart();
}
 
@Override
public void onSuccess(ResponseInfo<File> arg0) {
Toast.makeText(MainActivity.this,"下载完成",0).show();
 
}
@Override
public void onFailure(HttpException arg0, String arg1) {
Toast.makeText(MainActivity.this,"网络异常,下载失败",0).show();
 
}
});
}
0 0
原创粉丝点击