android SD卡图片浏览
来源:互联网 发布:人工智能待遇 编辑:程序博客网 时间:2024/05/16 12:19
在ActivityAction里面有一个“ACTION_GET_CONTENT”字符串常量,该常量让用户选择特定类型的数据,并返回该数据的URI.我们利用该常量,然后设置类型为“image/*”,就可获得android手机内的所有image。
main.xml :
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- <Button
- android:id="@+id/b01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <ImageView
- android:id="@+id/iv01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
Lesson_01_Pic.java:
- package com.yfz;
- import java.io.FileNotFoundException;
- import android.app.Activity;
- import android.content.ContentResolver;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.net.Uri;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- public class Lesson_01_Pic extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button button = (Button)findViewById(R.id.b01);
- button.setText("选择图片");
- button.setOnClickListener(new Button.OnClickListener(){
- @Override
- public void onClick(View v) {
- Intent intent = new Intent();
- /* 开启Pictures画面Type设定为image */
- intent.setType("image/*");
- /* 使用Intent.ACTION_GET_CONTENT这个Action */
- intent.setAction(Intent.ACTION_GET_CONTENT);
- /* 取得相片后返回本画面 */
- startActivityForResult(intent, 1);
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK) {
- Uri uri = data.getData();
- Log.e("uri", uri.toString());
- ContentResolver cr = this.getContentResolver();
- try {
- Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
- ImageView imageView = (ImageView) findViewById(R.id.iv01);
- /* 将Bitmap设定到ImageView */
- imageView.setImageBitmap(bitmap);
- } catch (FileNotFoundException e) {
- Log.e("Exception", e.getMessage(),e);
- }
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
- }
- android SD卡图片浏览
- SD卡文件浏览
- Android 图片SD卡缓存
- Android SD卡存储图片
- android浏览SD卡目录文件,实现音频播放
- Android之图片浏览
- Android WebView图片浏览
- android 图片浏览程序
- android在线浏览图片
- Android图片浏览
- android在线浏览图片
- Android ImageView 图片浏览
- android 图片浏览案例
- Android全屏浏览图片
- Android 读取本地(SD卡)图片
- android 加载sd卡的图片
- Android 批量上传sd卡图片
- android保存Bitmap图片到sd卡
- C语言中switch的用法
- 安装pydev插件
- 显示部分的架构图
- (android4.0)的编译及烧写的步骤
- 如何在Win上安装和使用GNUstep和Objective-C
- android SD卡图片浏览
- NopCommerce学习资料网址
- 官方源码包解压缩提示错误的解决办法
- 设计模式总结
- Parsley开发指南 4 依赖注入
- 关于平均值(By Dahua Lin@MIT)
- 官方Android源码编译提示
- Oracle 左连接,右连接,全连接,sql实例
- 语音识别 TTS