精华内容
下载资源
问答
  • android相册

    2014-01-02 13:45:10
    android相册
  • 云分享相册android版手机客户端下载 安卓客户端使用辅导的 下载地址1发送短信yfx到10001号10001号会回复一条含有下载客户端地址的短信直接点击安装即可 下载地址2登陆云分享网站 下载 客户端的使用步骤 点击手机应用...
  • android下载图片到相册

    2014-06-19 11:17:24
    android异步下载图片到相册,异步下载,可以自行更改,适合新手学习
  • Android选择系统相册或拍照上传源码.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
  • 注意安卓10由于权限问题,无法直接访问dcim相册目录,谨慎使用下方法提供扩展类新建项目 添加android library: toastlibrarypackage com.example.toastlibrary;import android.content.Context;import android....

    注意安卓10由于权限问题,无法直接访问dcim相册目录,谨慎使用下方法

    提供扩展类

    新建项目 添加android library: toastlibrary

    package com.example.toastlibrary;

    import android.content.Context;

    import android.content.Intent;

    import android.net.Uri;

    import java.io.File;

    public class ScanFiles {

    public void ScanFile(Context context, String filePath) {

    Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

    scanIntent.setData(Uri.fromFile(new File(filePath)));

    context.sendBroadcast(scanIntent);

    }

    }

    导出后,选择aar包里的classes.jar

    放入unity

    unity调用

    RefreshAlbum.RefreshAlbumByMyself(mFileName); //刷新安卓相册 mFileName为图片路径

    using UnityEngine;

    using System.Collections;

    public class RefreshAlbum

    {

    public static void RefreshAlbumByMyself(string photoFullName)

    {

    AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

    AndroidJavaObject currentActivity = unityPlayer.GetStatic("currentActivity");

    AndroidJavaObject context = currentActivity.Call("getApplicationContext");

    AndroidJavaObject jo = new AndroidJavaObject("com.example.toastlibrary.ScanFiles");

    jo.Call("ScanFile", context, photoFullName);

    AndroidJavaClass toast = new AndroidJavaClass("android.widget.Toast");

    currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>

    {

    toast.CallStatic("makeText", context, "截图成功保存到相册", toast.GetStatic("LENGTH_LONG")).Call("show");

    }));

    }

    }

    展开全文
  • 如标题所述,调用系统相选择图片并显示
  • 第一步:打开网站http://www.zanqianba.com并粘贴视频链接进输入框 第二步:点击下载视频链接

    第一步:打开网站http://www.zanqianba.com并粘贴视频链接进输入框

    第二步:点击下载视频链接

     
    展开全文
  • 主要为大家详细介绍了Android实现相册中图片上传或下载,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • DownLoadImageToGallery: Android 下载图片保存到相册
  • android 相册源码

    热门讨论 2012-03-20 18:00:24
    android 相册源码 android Gallery3D源码
  • android相册多选

    2014-03-19 09:32:29
    android相册多选,取消选择,显示在界面
  • 26.Android 下载图片保存到相册

    千次阅读 2015-10-20 22:58:15
    26.Android 下载图片保存到相册Android 下载图片保存到相册 前言 实现思路 自定义Dialog 自定义Handler 自定义AsyncTask AndroidManifest配置权限 DownloadImageToGalleryActivity 效果图 源码传送门前言有遇到没有...

    26.Android 下载图片保存到相册


    前言

    有遇到没有这样的一种需求:浏览的大图后,点击保存下载高清原图到相册的需求。

    现在的图片缓存大多都是Universal-Imager-Loader为多。但是我们在公司的某些离谱的需求(圈子系的需求,要求每条动态展示的图片不止6张,有一条30多张,直接报了Universal-Imager-Loader的OOM,怎么改配置都不能解决)上,后来调研了GlideFresco,发现Glide基本是完虐的节奏。

    这里给大家提一个Glide小问题:Glide自带能把图片加载成圆角,Glide加载本地图片不能实现圆角。


    实现思路

    • 1.自定义一个AsyncTask下载图片
    • 2.自定义一个Dialog显示下载进度
    • 3.自定义一个Handler刷新Dialog的进度
    • 4.下载完成后,保存图片到相册里

    自定义Dialog

    dialog_progressbar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:padding="10dip" />
    
        <TextView
            android:id="@+id/load_info_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dip"
            android:text="正在提交..."
            android:textColor="#000000" />
    
    </LinearLayout>

    CustomProgressBarDialog

        /**
         * 自定义进度条Dialog
         */
        public class CustomProgressBarDialog extends Dialog {
    
            private LayoutInflater mInflater;
            private Context mContext;
            private WindowManager.LayoutParams params;
            private View mView;
            private TextView promptTV;
    
            public CustomProgressBarDialog(Context context) {
                super(context);
                this.init(context);
            }
    
            public CustomProgressBarDialog(Context context, int themeResId) {
                super(context, themeResId);
                this.init(context);
            }
    
            protected CustomProgressBarDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
                super(context, cancelable, cancelListener);
                this.init(context);
            }
    
            private void init(Context context) {
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                this.mContext = context;
                this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                this.mView = this.mInflater.inflate(R.layout.dialog_progressbar, null);
                setContentView(this.mView);
    
                // 设置window属性
                this.params = getWindow().getAttributes();
                this.params.gravity = Gravity.CENTER;
                // 去背景遮盖
                this.params.dimAmount = 0;
                this.params.alpha = 1.0f;
                // 不能关掉
                this.setCancelable(false);
                this.getWindow().setAttributes(this.params);
                this.promptTV = (TextView) findViewById(R.id.load_info_text);
            }
    
            /**
             * 设置内容
             *
             * @param prompt
             */
            public void setLoadPrompt(String prompt) {
                this.promptTV.setText(prompt);
            }
    
        }

    自定义Handler

    注意:这里可以参考Handler 通用模板

        private static final int HANDLER_LOADING = 262;
    
        /**
         * 刷新Dialog显示的进度Handler
         */
        private static class LoadingHandler extends Handler {
            private final WeakReference<DownloadImageToGalleryActivity> mActivity;
    
            public LoadingHandler(DownloadImageToGalleryActivity activity) {
                mActivity = new WeakReference<>(activity);
            }
    
            /**
             * Subclasses must implement this to receive messages.
             *
             * @param msg
             */
            @Override
            public void handleMessage(Message msg) {
                DownloadImageToGalleryActivity activity = this.mActivity.get();
                if (activity != null) {
                    switch (msg.what) {
                        case HANDLER_LOADING: {
                            int progressValue = (int) msg.obj;
                            activity.dialog.setLoadPrompt(progressValue + "%");
                            activity.dialog.show();
                            break;
                        }
                    }
                }
            }
        }
        private final LoadingHandler loadingHandler = new LoadingHandler(DownloadImageToGalleryActivity.this);

    自定义AsyncTask

    注意:这里可以参考AsyncTask 模板

        /**
         * 下载图片异步任务
         */
        public class DownloadImageAsyncTask extends AsyncTask<String, Integer, String> {
    
            private Activity activity;
            private String localFilePath;
    
            public DownloadImageAsyncTask(Activity activity) {
                super();
                this.activity = activity;
            }
    
            /**
             * 对应AsyncTask第一个参数
             * 异步操作,不在主UI线程中,不能对控件进行修改
             * 可以调用publishProgress方法中转到onProgressUpdate(这里完成了一个handler.sendMessage(...)的过程)
             *
             * @param params The parameters of the task.
             * @return A result, defined by the subclass of this task.
             * @see #onPreExecute()
             * @see #onPostExecute
             * @see #publishProgress
             */
            @Override
            protected String doInBackground(String... params) {
                // TODO 注意这里
                /**
                 * 这里接入你所用的网络框架去下载图片,只要保证this.localFilePath的值有就可以了
                 */
                URL fileUrl = null;
                try {
                    fileUrl = new URL(params[0]);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                if (fileUrl == null) return null;
                try {
                    HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setDoInput(true);
                    connection.connect();
    
                    //计算文件长度
                    int lengthOfFile = connection.getContentLength();
                    /**
                     * 不存在SD卡,就放到缓存文件夹内
                     */
                    File cacheDir = this.activity.getCacheDir();
                    File downloadFile = new File(cacheDir, UUID.randomUUID().toString() + ".jpg");
                    this.localFilePath = downloadFile.getPath();
                    if (!downloadFile.exists()) {
                        File parent = downloadFile.getParentFile();
                        if (parent != null) parent.mkdirs();
                    }
                    FileOutputStream output = new FileOutputStream(downloadFile);
                    InputStream input = connection.getInputStream();
                    InputStream bitmapInput = connection.getInputStream();
                    //下载
                    byte[] buffer = new byte[1024];
                    int len;
                    long total = 0;
                    // 计算进度
                    while ((len = input.read(buffer)) > 0) {
                        total += len;
                        this.publishProgress((int) ((total * 100) / lengthOfFile));
                        output.write(buffer, 0, len);
                    }
                    output.close();
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }
    
            /**
             * 对应AsyncTask第三个参数 (接受doInBackground的返回值)
             * 在doInBackground方法执行结束之后在运行,此时已经回来主UI线程当中 能对UI控件进行修改
             *
             * @param string The result of the operation computed by {@link #doInBackground}.
             * @see #onPreExecute
             * @see #doInBackground
             * @see #onCancelled(Object)
             */
            @Override
            protected void onPostExecute(String string) {
                /**
                 * 设置按钮可用,并隐藏Dialog
                 */
                DownloadImageToGalleryActivity.this.saveBT.setEnabled(true);
                DownloadImageToGalleryActivity.this.dialog.hide();
    
                DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                int screenWidth = metrics.widthPixels;
                int screenHeight = metrics.heightPixels;
                /**
                 * ImageUtil.decodeScaleImage 解析图片
                 */
                Bitmap bitmap = ImageUtil.decodeScaleImage(this.localFilePath, screenWidth, screenHeight);
                DownloadImageToGalleryActivity.this.saveIV.setImageBitmap(bitmap);
                /**
                 * 保存图片到相册
                 */
                String imageName = System.currentTimeMillis() + ".jpg";
                MediaStore.Images.Media.insertImage(DownloadImageToGalleryActivity.this.getApplicationContext().getContentResolver(), bitmap, imageName, "牙医助理");
                Toast.makeText(this.activity, "已保存:" + imageName, Toast.LENGTH_LONG).show();
            }
    
            /**
             * 对应AsyncTask第二个参数
             * 在doInBackground方法当中,每次调用publishProgress方法都会中转(handler.sendMessage(...))到onProgressUpdate
             * 在主UI线程中,可以对控件进行修改
             *
             * @param values The values indicating progress.
             * @see #publishProgress
             * @see #doInBackground
             */
            @Override
            protected void onProgressUpdate(Integer... values) {
                // 主线程Handler实例消息
                Message message = DownloadImageToGalleryActivity.this.loadingHandler.obtainMessage();
                message.obj = values[0];
                message.what = HANDLER_LOADING;
                // 给主线程Handler发送消息
                DownloadImageToGalleryActivity.this.loadingHandler.handleMessage(message);
            }
    
            /**
             * 运行在主UI线程中,此时是预执行状态,下一步是doInBackground
             *
             * @see #onPostExecute
             * @see #doInBackground
             */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }
    
            /**
             * <p>Applications should preferably override {@link #onCancelled(Object)}.
             * This method is invoked by the default implementation of
             * {@link #onCancelled(Object)}.</p>
             * <p/>
             * <p>Runs on the UI thread after {@link #cancel(boolean)} is invoked and
             * {@link #doInBackground(Object[])} has finished.</p>
             *
             * @see #onCancelled(Object)
             * @see #cancel(boolean)
             * @see #isCancelled()
             */
            @Override
            protected void onCancelled() {
                /**
                 * 设置按钮可用
                 */
                DownloadImageToGalleryActivity.this.saveBT.setEnabled(true);
                super.onCancelled();
            }
    
        }

    AndroidManifest配置权限

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    DownloadImageToGalleryActivity

    activity_download_image_to_grallery.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center_horizontal"
        tools:context=".DownloadImageToGrallery">
    
        <TextView
            android:id="@+id/save_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="6dp"
            android:padding="6dp" />
    
        <Button
            android:id="@+id/save_bt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="6dp"
            android:padding="6dp"
            android:text="保存" />
    
        <ImageView
            android:id="@+id/save_iv"
            android:layout_width="360dp"
            android:layout_height="360dp"
            android:layout_margin="6dp" />
    
    </LinearLayout>

    DownloadImageToGalleryActivity

    public class DownloadImageToGalleryActivity extends AppCompatActivity implements View.OnClickListener {
    
        private static final String OBJECT_IMAGE_URL = "https://img-blog.csdn.net/20150913233900119";
    
        private Button saveBT;
        private ImageView saveIV;
        private CustomProgressBarDialog dialog;
    
    
    
        /**
         * Called when a view has been clicked.
         *
         * @param v The view that was clicked.
         */
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.save_bt: {
                    v.setEnabled(false);
                    /**
                     * 设置按钮不可用,开始执行任务
                     */
                    new DownloadImageAsyncTask(this).execute(OBJECT_IMAGE_URL);
                    break;
                }
            }
        }
    
        private static final int HANDLER_LOADING = 262;
    
        /**
         * 刷新Dialog显示的进度Handler
         */
        private static class LoadingHandler extends Handler {
            private final WeakReference<DownloadImageToGalleryActivity> mActivity;
    
            public LoadingHandler(DownloadImageToGalleryActivity activity) {
                mActivity = new WeakReference<>(activity);
            }
    
            /**
             * Subclasses must implement this to receive messages.
             *
             * @param msg
             */
            @Override
            public void handleMessage(Message msg) {
                DownloadImageToGalleryActivity activity = this.mActivity.get();
                if (activity != null) {
                    switch (msg.what) {
                        case HANDLER_LOADING: {
                            int progressValue = (int) msg.obj;
                            activity.dialog.setLoadPrompt(progressValue + "%");
                            activity.dialog.show();
                            break;
                        }
                    }
                }
            }
        }
        private final LoadingHandler loadingHandler = new LoadingHandler(DownloadImageToGalleryActivity.this);
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_download_image_to_grallery);
    
            this.saveBT = (Button) this.findViewById(R.id.save_bt);
            this.saveIV = (ImageView) this.findViewById(R.id.save_iv);
    
            ((TextView) this.findViewById(R.id.save_tv)).setText(OBJECT_IMAGE_URL);
            this.dialog = new CustomProgressBarDialog(this);
            this.saveBT.setOnClickListener(this);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_download_image_to_grallery, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
    
            return super.onOptionsItemSelected(item);
        }
    
        /**
         * 自定义进度条Dialog
         */
        public class CustomProgressBarDialog extends Dialog {
    
            private LayoutInflater mInflater;
            private Context mContext;
            private WindowManager.LayoutParams params;
            private View mView;
            private TextView promptTV;
    
            public CustomProgressBarDialog(Context context) {
                super(context);
                this.init(context);
            }
    
            public CustomProgressBarDialog(Context context, int themeResId) {
                super(context, themeResId);
                this.init(context);
            }
    
            protected CustomProgressBarDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
                super(context, cancelable, cancelListener);
                this.init(context);
            }
    
            private void init(Context context) {
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                this.mContext = context;
                this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                this.mView = this.mInflater.inflate(R.layout.dialog_progressbar, null);
                setContentView(this.mView);
    
                // 设置window属性
                this.params = getWindow().getAttributes();
                this.params.gravity = Gravity.CENTER;
                // 去背景遮盖
                this.params.dimAmount = 0;
                this.params.alpha = 1.0f;
                // 不能关掉
                this.setCancelable(false);
                this.getWindow().setAttributes(this.params);
                this.promptTV = (TextView) findViewById(R.id.load_info_text);
            }
    
            /**
             * 设置内容
             *
             * @param prompt
             */
            public void setLoadPrompt(String prompt) {
                this.promptTV.setText(prompt);
            }
    
        }
    
        /**
         * 下载图片异步任务
         */
        public class DownloadImageAsyncTask extends AsyncTask<String, Integer, String> {
    
            private Activity activity;
            private String localFilePath;
    
            public DownloadImageAsyncTask(Activity activity) {
                super();
                this.activity = activity;
            }
    
            /**
             * 对应AsyncTask第一个参数
             * 异步操作,不在主UI线程中,不能对控件进行修改
             * 可以调用publishProgress方法中转到onProgressUpdate(这里完成了一个handler.sendMessage(...)的过程)
             *
             * @param params The parameters of the task.
             * @return A result, defined by the subclass of this task.
             * @see #onPreExecute()
             * @see #onPostExecute
             * @see #publishProgress
             */
            @Override
            protected String doInBackground(String... params) {
                // TODO 注意这里
                /**
                 * 这里接入你所用的网络框架去下载图片,只要保证this.localFilePath的值有就可以了
                 */
                URL fileUrl = null;
                try {
                    fileUrl = new URL(params[0]);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                if (fileUrl == null) return null;
                try {
                    HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setDoInput(true);
                    connection.connect();
    
                    //计算文件长度
                    int lengthOfFile = connection.getContentLength();
                    /**
                     * 不存在SD卡,就放到缓存文件夹内
                     */
                    File cacheDir = this.activity.getCacheDir();
                    File downloadFile = new File(cacheDir, UUID.randomUUID().toString() + ".jpg");
                    this.localFilePath = downloadFile.getPath();
                    if (!downloadFile.exists()) {
                        File parent = downloadFile.getParentFile();
                        if (parent != null) parent.mkdirs();
                    }
                    FileOutputStream output = new FileOutputStream(downloadFile);
                    InputStream input = connection.getInputStream();
                    InputStream bitmapInput = connection.getInputStream();
                    //下载
                    byte[] buffer = new byte[1024];
                    int len;
                    long total = 0;
                    // 计算进度
                    while ((len = input.read(buffer)) > 0) {
                        total += len;
                        this.publishProgress((int) ((total * 100) / lengthOfFile));
                        output.write(buffer, 0, len);
                    }
                    output.close();
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }
    
            /**
             * 对应AsyncTask第三个参数 (接受doInBackground的返回值)
             * 在doInBackground方法执行结束之后在运行,此时已经回来主UI线程当中 能对UI控件进行修改
             *
             * @param string The result of the operation computed by {@link #doInBackground}.
             * @see #onPreExecute
             * @see #doInBackground
             * @see #onCancelled(Object)
             */
            @Override
            protected void onPostExecute(String string) {
                /**
                 * 设置按钮可用,并隐藏Dialog
                 */
                DownloadImageToGalleryActivity.this.saveBT.setEnabled(true);
                DownloadImageToGalleryActivity.this.dialog.hide();
    
                DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                int screenWidth = metrics.widthPixels;
                int screenHeight = metrics.heightPixels;
                /**
                 * ImageUtil.decodeScaleImage 解析图片
                 */
                Bitmap bitmap = ImageUtil.decodeScaleImage(this.localFilePath, screenWidth, screenHeight);
                DownloadImageToGalleryActivity.this.saveIV.setImageBitmap(bitmap);
                /**
                 * 保存图片到相册
                 */
                String imageName = System.currentTimeMillis() + ".jpg";
                MediaStore.Images.Media.insertImage(DownloadImageToGalleryActivity.this.getApplicationContext().getContentResolver(), bitmap, imageName, "牙医助理");
                Toast.makeText(this.activity, "已保存:" + imageName, Toast.LENGTH_LONG).show();
            }
    
            /**
             * 对应AsyncTask第二个参数
             * 在doInBackground方法当中,每次调用publishProgress方法都会中转(handler.sendMessage(...))到onProgressUpdate
             * 在主UI线程中,可以对控件进行修改
             *
             * @param values The values indicating progress.
             * @see #publishProgress
             * @see #doInBackground
             */
            @Override
            protected void onProgressUpdate(Integer... values) {
                // 主线程Handler实例消息
                Message message = DownloadImageToGalleryActivity.this.loadingHandler.obtainMessage();
                message.obj = values[0];
                message.what = HANDLER_LOADING;
                // 给主线程Handler发送消息
                DownloadImageToGalleryActivity.this.loadingHandler.handleMessage(message);
            }
    
            /**
             * 运行在主UI线程中,此时是预执行状态,下一步是doInBackground
             *
             * @see #onPostExecute
             * @see #doInBackground
             */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }
    
            /**
             * <p>Applications should preferably override {@link #onCancelled(Object)}.
             * This method is invoked by the default implementation of
             * {@link #onCancelled(Object)}.</p>
             * <p/>
             * <p>Runs on the UI thread after {@link #cancel(boolean)} is invoked and
             * {@link #doInBackground(Object[])} has finished.</p>
             *
             * @see #onCancelled(Object)
             * @see #cancel(boolean)
             * @see #isCancelled()
             */
            @Override
            protected void onCancelled() {
                /**
                 * 设置按钮可用
                 */
                DownloadImageToGalleryActivity.this.saveBT.setEnabled(true);
                super.onCancelled();
            }
    
        }
    
    }

    效果图

    DownLoadImageToGallery


    源码传送门

    DownLoadImageToGallery

    展开全文
  • 安卓相册浏览器

    2014-01-11 21:53:26
    相册浏览器,安卓,可以查看文件内的图片 ,并浏览
  • Android相册示例代码

    2011-09-08 17:56:23
    Android相册示例代码 Android相册示例代码 Android相册示例代码
  • 安卓相册操作, 预览相册图片, 选择相册图片,支持放大显示
  • android-相册

    2017-07-08 11:36:05
    android-相册
  • Android下载图片到相册

    千次阅读 2018-09-19 14:46:33
    下载类,可以url下载,也可以本地的drawable下载相册,记得在清单加权限,6.0代码动态加权限判断,下载图片要在子线程中下载下载完后广播更新相册 代码下载地址:链接:...

    下载类,可以url下载,也可以本地的drawable下载到相册,记得在清单加权限,6.0代码动态加权限判断,下载图片要在子线程中下载,下载完后广播更新相册

    代码下载地址:链接:https://pan.baidu.com/s/1dsjx2QCSw2SxRcUW0Z3Xqg 
                            提取码:i8j2

       <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    package com.example.administrator.myimageload;
    
    /**
     * Created by Administrator on 2018/9/17.
     */
    
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Environment;
    import android.os.Handler;
    import android.os.Message;
    import android.provider.MediaStore;
    import android.text.TextUtils;
    import android.util.Log;
    import android.widget.Toast;
    
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.UUID;
    
    /**
     * Created by vimi8 on 2017/6/9.
     */
    
    public class ImgDonwloads {
    
        private static String filePath;
        private static Bitmap mBitmap;
        private static String mFileName="sshs";
        private static String mSaveMessage;
        private final static String TAG = "ImageActivity";
        private static Context context;
    
        private static ProgressDialog mSaveDialog = null;
    
        public static void donwloadImg(Context contexts,String filePaths){
            context = contexts;
            filePath = filePaths;
            mSaveDialog = ProgressDialog.show(context, "保存二维码", "二维码图片正在保存中,请稍等...", true);
    
            new Thread(saveFileRunnable).start();
        }
    
        private static Runnable saveFileRunnable = new Runnable(){
            @Override
            public void run() {
                try {
    //                mBitmap = BitmapFactory.decodeStream(getImageStream(filePath));
    
                    if (!TextUtils.isEmpty(filePath)) {                 //网络图片
                        //对资源链接
                        URL url=new URL(filePath);
                        //打开输入流
                        InputStream inputStream=url.openStream();
                        //对网上资源进行下载转换位图图片
                        mBitmap= BitmapFactory.decodeStream(inputStream);
                        inputStream.close();
                    }
    
                    Bitmap    bmp = BitmapFactory.decodeResource(context.getResources(),R.drawable.bg_guid_1 );   //本地的图片,根据自己情况
    //                saveFile(mBitmap, mFileName);
                    saveFile(bmp);
                    mSaveMessage = "图片保存成功!";
                } catch (IOException e) {
                    mSaveMessage = "图片保存失败!";
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                messageHandler.sendMessage(messageHandler.obtainMessage());
            }
        };
        private static Handler messageHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                mSaveDialog.dismiss();
                Log.d(TAG, mSaveMessage);
                Toast.makeText(context, mSaveMessage, Toast.LENGTH_SHORT).show();
            }
        };
    
    
        /**
         * Get image from newwork
         * @param path The path of image
         * @return InputStream
         * @throws Exception
         */
        public static InputStream getImageStream(String path) throws Exception{
            URL url = new URL(path);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5 * 1000);
            conn.setRequestMethod("GET");
            if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
                return conn.getInputStream();
            }
            return null;
        }
        /**
         * 保存文件
         * @param bm
         * @param fileName
         * @throws IOException
         */
        public static void saveFile(Bitmap bm, String fileName) throws IOException {
            File dirFile = new File(Environment.getExternalStorageDirectory().getPath());
            if(!dirFile.exists()){
                dirFile.mkdir();
            }
            fileName = UUID.randomUUID().toString()+".jpg";
            File myCaptureFile = new File(Environment.getExternalStorageDirectory().getPath() +"/DCIM/Camera/"+ fileName);
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
            bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
            bos.flush();
            bos.close();
    
            //把图片保存后声明这个广播事件通知系统相册有新图片到来
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri uri = Uri.fromFile(myCaptureFile);
            intent.setData(uri);
            context.sendBroadcast(intent);
        }
        /**
         * 保存图片到图库
         * @param bmp
         */
        public static void saveFile( Bitmap bmp) {
            // 首先保存图片
            File appDir = new File(Environment.getExternalStorageDirectory(),
                    "sshs");
            if (!appDir.exists()) {
                appDir.mkdir();
            }
            String fileName = System.currentTimeMillis() + ".jpg";
            File file = new File(appDir, fileName);
            try {
                FileOutputStream fos = new FileOutputStream(file);
                bmp.compress(Bitmap.CompressFormat.JPEG, 80, fos);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
    
                e.printStackTrace();
            }
    
            // 其次把文件插入到系统图库
            try {
                MediaStore.Images.Media.insertImage(context.getContentResolver(),
                        file.getAbsolutePath(), fileName, null);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            // 最后通知图库更新
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    Uri.fromFile(new File(file.getPath()))));
        }
    }

    MainActivity类

    
    public class MainActivity extends AppCompatActivity {
        private Bitmap bitmap;
        private TextView tv ;
        String iPath = "http://i.imgur.com/DvpvklR.png";
      
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            tv = (TextView) findViewById(R.id.tv);
    //        download() ;
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    List<String> permissionList = new ArrayList<>();
                    if (ContextCompat.checkSelfPermission(MainActivity.this,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    }
                    if (!permissionList.isEmpty()) {
                        String[] permissions = permissionList.toArray(new String[permissionList.size()]);
                        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
                    } else {
                        ImgDonwloads.donwloadImg(MainActivity.this,"");//iPath
                    }
    
    
                }
            });
    
        }
        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
            switch (requestCode) {
                case 1:
                    if (grantResults.length > 0) {
                        for (int result : grantResults) {
                            if (result != PackageManager.PERMISSION_GRANTED) {
                                Toast.makeText(this, "拒绝了权限", Toast.LENGTH_SHORT).show();
    //                            finish();
                                return;
                            }
                        }
                        ImgDonwloads.donwloadImg(MainActivity.this,"");
                    } else {
                        Toast.makeText(this, "发生未知错误", Toast.LENGTH_SHORT).show();
    //                    finish();
                    }
                    break;
                default:
            }
        }
       
    
        
    }
    

     

    展开全文
  • 一个比较简洁的类似微信相册多选的库,代码量比较少,修改定制比较简单。 考虑到几乎所有app都必备图片加载框架,所以需要自己实现图片加载接口。 图片预览控件来自:TouchImageView ...
  • android相册文档

    2012-06-11 20:33:12
    这是本人写的一个有关于Android的手机相册,具体可以实现照片的查看,编辑,上传下载等功能。希望与大家共同学习。
  • android相册demo

    热门讨论 2014-05-15 01:23:21
    Gallery结合Camera的相册实例 工程源码
  • 安卓11版本,下载视频uni.downloadFile并保存到相册uni.saveImageToPhotosAlbum提示成功,但相册里没有视频其他安卓版本和iphone,可以正常保存save(video) {uni.showLoading()const downloadTask = uni....
  • Android图片下载显示(相册效果),自己开发用到,没研究完,只是个半成品,记录一下
  • Android相册Demo

    2018-08-23 17:46:39
    查询系统数据库文件,获取手机内所有的图片。采用rxjava获取
  • android 相册图片多选

    2013-11-29 15:57:40
    android 相册图片多选-模仿微信朋友圈发帖的功能,功能和微信一致,相册图片多选显示删除等
  • android 相册选择+剪裁
  • android 电子相册

    2014-01-11 10:35:12
    该电子相册实现了android自带电子相册的基本功能,适合android入门学习
  • android相册上传插件

    2014-09-23 13:58:21
    android相册上传插件,可以选择本地图片或者拍照上传。。选定图片后可以截取图片。比较不错的功能插件。
  • Android 安卓将网络图片保存到相册 封装了一个工具类! 请先加上读写权限: 如果是Android6.0之后,加上权限后再动态申请权限 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { if (ActivityCompat....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 32,392
精华内容 12,956
关键字:

安卓相册下载