diff --git a/soft1614080902444/6-1.png b/soft1614080902444/6-1.png new file mode 100644 index 000000000..c5b78d5ed Binary files /dev/null and b/soft1614080902444/6-1.png differ diff --git a/soft1614080902444/6-2.png b/soft1614080902444/6-2.png new file mode 100644 index 000000000..a08d9c9a5 Binary files /dev/null and b/soft1614080902444/6-2.png differ diff --git a/soft1614080902444/app/6-1.png b/soft1614080902444/app/6-1.png new file mode 100644 index 000000000..c5b78d5ed Binary files /dev/null and b/soft1614080902444/app/6-1.png differ diff --git a/soft1614080902444/app/6-2.png b/soft1614080902444/app/6-2.png new file mode 100644 index 000000000..a08d9c9a5 Binary files /dev/null and b/soft1614080902444/app/6-2.png differ diff --git a/soft1614080902444/app/java/edu/hzuapps/androidlabs/soft1614080902444/DownloadActivity.java b/soft1614080902444/app/java/edu/hzuapps/androidlabs/soft1614080902444/DownloadActivity.java new file mode 100644 index 000000000..501f4b736 --- /dev/null +++ b/soft1614080902444/app/java/edu/hzuapps/androidlabs/soft1614080902444/DownloadActivity.java @@ -0,0 +1,83 @@ +package edu.hzuapps.androidlabs.soft1614080902444; + import android.support.v7.app.AppCompatActivity; + import java.io.File; + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.InputStream; + import java.net.MalformedURLException; + import java.net.URL; + import android.graphics.Bitmap; + import android.graphics.BitmapFactory; + import android.os.Bundle; + import android.os.Environment; + import android.os.Handler; + import android.os.Message; + import android.view.View; + import android.view.View.OnClickListener; + import android.widget.Button; + import android.widget.EditText; + import android.widget.ImageView; + public class DownloadActivity extends AppCompatActivity { + private EditText editText; + private Button button; + private ImageView imageView; + + private Bitmap bitmap; + //手柄更新的作用 + Handler handler=new Handler(){ + public void handleMessage(Message msg) { + if(msg.what==111){ + imageView.setImageBitmap(bitmap); + } + }; + }; + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_download); + + //初始化组件 + editText=(EditText) findViewById(R.id.imagepath); + button=(Button) findViewById(R.id.upload); + imageView=(ImageView) findViewById(R.id.imageView); + + //给下载按钮添加一个监听 + button.setOnClickListener(new OnClickListener() { + public void onClick(View arg0) { + new Thread(t).start();//启动线程t + } + }); + } + + //为了下载图片资源,开辟一个新的子线程,线程名字为t + Thread t=new Thread(){ + public void run() { + //下载图片的路径 + String iPath=editText.getText().toString(); + try { + //对资源链接 + URL url=new URL(iPath); + //打开输入流 + InputStream inputStream=url.openStream(); + //对网上资源进行下载转换位图图片 + bitmap=BitmapFactory.decodeStream(inputStream); + handler.sendEmptyMessage(111); + inputStream.close(); + + //再一次打开 + inputStream=url.openStream(); + File file=new File(Environment.getExternalStorageDirectory()+"/DCIM/"); + FileOutputStream fileOutputStream=new FileOutputStream(file); + int hasRead=0; + while((hasRead=inputStream.read())!=-1){ + fileOutputStream.write(hasRead); + } + fileOutputStream.close(); + inputStream.close(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + }; + }; + } diff --git a/soft1614080902444/app/manifests/AndroidManifest.xml b/soft1614080902444/app/manifests/AndroidManifest.xml index 82550614f..ab30ce85c 100644 --- a/soft1614080902444/app/manifests/AndroidManifest.xml +++ b/soft1614080902444/app/manifests/AndroidManifest.xml @@ -1,5 +1,6 @@ + + + + + - + + + + + + + + \ No newline at end of file diff --git a/soft1614080902444/app/res/layout/activity_download.xml b/soft1614080902444/app/res/layout/activity_download.xml new file mode 100644 index 000000000..7f88d0379 --- /dev/null +++ b/soft1614080902444/app/res/layout/activity_download.xml @@ -0,0 +1,27 @@ + + + + + +