How we can remove
contain pictures under sdcardJust call the system comes as the same gallery, but I want to show a list
Is there any way it
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Such systems can open gallery
Intent intent = new Intent (Intent.ACTION_PICK, null);
intent.setDataAndType (
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
IMAGE_UNSPECIFIED);
startActivityForResult (intent, 1);
Get gallery content, just rewrite onActivityResult, made after reading your own layout interface allows.
Reply:
By the way, you do not choose, it can be taken directly from MediaStore.Image inside.
Reply:
Will it be able to have direct access to the folder.
Reply:
Can take it directly to a folder
Reply:
File file = new File (filePath);
/ / Bottom is the viewer through pictures Intent calling system key code
Intent intent = new Intent ();
intent.setAction (android.content.Intent.ACTION_VIEW);
intent.setDataAndType (Uri.fromFile (file), "image / *");
startActivity (intent);
You debug it, the main code should be like, the picture browser package name to go on it.
Reply:
Or to direct their own sd card scan all folders, find all contain the suffix. Bmp,. Jpg,. Jpeg, png, etc. files folder.
Reply:
First scan each folder, each file folder to read, to determine whether it is a file bmp, jpg, jpeg, png and other formats, the file path is then stored in a record collection, scanning all After a folder, call the system picture viewer shows the array of all the pictures.
Reply:
SD cards can traverse all directories under the
Reply:
package com.example.imageshow;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.example.adapter.ImageListFileAdapter;
@ SuppressLint ("HandlerLeak")
public class ImageViewFileListActivity extends Activity implements OnItemClickListener {
private ListView image_list = null;
public ImageListFileAdapter adapter = null;
private ArrayList
private ArrayList
private HashMap
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
setContentView (R.layout.image_list);
initView ();
System.out.println ("======== ImageViewFileListActivity ============ oncreate -----");
}
private void initView () {
image_list = (ListView) findViewById (R.id.image_file_list);
imagePathList = new ArrayList
bitMapList = new ArrayList
adapter = new ImageListFileAdapter (this, imagePathList, bitMapList);
image_list.setAdapter (adapter);
new Thread (new GetImageFilePathThread ()) start ();.
/ / Loader = new AsyncImageListLoader (this);
/ / Loader.execute (Executors.newCachedThreadPool ());
image_list.setOnItemClickListener (this);
}
@ Override
public void onItemClick (AdapterView parent, View view, int position,
long id) {
if (imagePathList.size ()> 0) {
Intent intent = new Intent ();
Bundle bundle = new Bundle ();
bundle.putString ("filePath", imagePathList.get (position));
intent.setClass (this, MainActivity.class);
intent.putExtras (bundle);
startActivity (intent);
}
}
Handler handler = new Handler () {
@ SuppressWarnings ({"unchecked", "rawtypes"})
@ Override
public void handleMessage (Message msg) {
HashMap
Iterator it = map.entrySet () iterator ();.
while (it.hasNext ()) {
/ / System.out.println ("SHEN ℃ Chiguan efficiency ��");
Map.Entry entry = (Map.Entry) it.next ();
String filePath = (String) entry.getKey ();
String bitmapPath = (String) entry.getValue ();
/ / Gemianweijian Pian Fangechailang Kunsuolizhao ㄩ Quarters �H Ren Xin Zhang Xie Hay ya study Qiqiejuta Feifanqionggao
adapter.addData (filePath, bitmapPath);
adapter.notifyDataSetChanged ();
}
map.clear ();
super.handleMessage (msg);
}
};
private class GetImageFilePathThread implements Runnable {
@ Override
public void run () {
File file = new File (Environment.getExternalStorageDirectory () + "");
getFileList (file);
}
}
private void getFileList (File file) {
File [] files = file.listFiles ();
if (files! = null) {
for (File f: files) {
if (f.isFile ()) {
if (". png". equals (getFileEx (f))) {
if (! imageMap.containsKey (file.getAbsolutePath ())) {
imageMap.put (file.getAbsolutePath (), f.getAbsolutePath ());
HashMap
temp.put (file.getAbsolutePath (), f.getAbsolutePath ());
Message msg = handler.obtainMessage ();
msg.obj = temp;
handler.sendMessage (msg);
}
}
if (". jpg". equals (getFileEx (f))) {
if (! imageMap.containsKey (file.getAbsolutePath ())) {
imageMap.put (file.getAbsolutePath (), f.getAbsolutePath ());
HashMap
temp.put (file.getAbsolutePath (), f.getAbsolutePath ());
Message msg = handler.obtainMessage ();
msg.obj = temp;
handler.sendMessage (msg);
}
}
} Else {
getFileList (f);
}
}
}
}
public String getFileEx (File file) {
String fileName = file.getName ();
int index = fileName.indexOf ('.');
if (index! = -1) {
int length = fileName.length ();
String str = fileName.substring (index, length);
return str;
}
return "";
}
@ Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged (newConfig);
if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_LANDSCAPE) {
System.out.println ("--------------------- One ------------");
}
else if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_PORTRAIT) {
System.out.println ("--------------- Two ------------");
}
}
}
Reply:
package com.example.imageshow;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.example.adapter.ImageListFileAdapter;
@ SuppressLint ("HandlerLeak")
public class ImageViewFileListActivity extends Activity implements OnItemClickListener {
private ListView image_list = null;
public ImageListFileAdapter adapter = null;
private ArrayList
private ArrayList
private HashMap
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
setContentView (R.layout.image_list);
initView ();
System.out.println ("======== ImageViewFileListActivity ============ oncreate -----");
}
private void initView () {
image_list = (ListView) findViewById (R.id.image_file_list);
imagePathList = new ArrayList
bitMapList = new ArrayList
adapter = new ImageListFileAdapter (this, imagePathList, bitMapList);
image_list.setAdapter (adapter);
new Thread (new GetImageFilePathThread ()) start ();.
/ / Loader = new AsyncImageListLoader (this);
/ / Loader.execute (Executors.newCachedThreadPool ());
image_list.setOnItemClickListener (this);
}
@ Override
public void onItemClick (AdapterView parent, View view, int position,
long id) {
if (imagePathList.size ()> 0) {
Intent intent = new Intent ();
Bundle bundle = new Bundle ();
bundle.putString ("filePath", imagePathList.get (position));
intent.setClass (this, MainActivity.class);
intent.putExtras (bundle);
startActivity (intent);
}
}
Handler handler = new Handler () {
@ SuppressWarnings ({"unchecked", "rawtypes"})
@ Override
public void handleMessage (Message msg) {
HashMap
Iterator it = map.entrySet () iterator ();.
while (it.hasNext ()) {
/ / System.out.println ("no pause");
Map.Entry entry = (Map.Entry) it.next ();
String filePath = (String) entry.getKey ();
String bitmapPath = (String) entry.getValue ();
/ / Add the picture to the adapter inside, in order to adjust the picture properties
adapter.addData (filePath, bitmapPath);
adapter.notifyDataSetChanged ();
}
map.clear ();
super.handleMessage (msg);
}
};
private class GetImageFilePathThread implements Runnable {
@ Override
public void run () {
File file = new File (Environment.getExternalStorageDirectory () + "");
getFileList (file);
}
}
private void getFileList (File file) {
File [] files = file.listFiles ();
if (files! = null) {
for (File f: files) {
if (f.isFile ()) {
if (". png". equals (getFileEx (f))) {
if (! imageMap.containsKey (file.getAbsolutePath ())) {
imageMap.put (file.getAbsolutePath (), f.getAbsolutePath ());
HashMap
temp.put (file.getAbsolutePath (), f.getAbsolutePath ());
Message msg = handler.obtainMessage ();
msg.obj = temp;
handler.sendMessage (msg);
}
}
if (". jpg". equals (getFileEx (f))) {
if (! imageMap.containsKey (file.getAbsolutePath ())) {
imageMap.put (file.getAbsolutePath (), f.getAbsolutePath ());
HashMap
temp.put (file.getAbsolutePath (), f.getAbsolutePath ());
Message msg = handler.obtainMessage ();
msg.obj = temp;
handler.sendMessage (msg);
}
}
} Else {
getFileList (f);
}
}
}
}
public String getFileEx (File file) {
String fileName = file.getName ();
int index = fileName.indexOf ('.');
if (index! = -1) {
int length = fileName.length ();
String str = fileName.substring (index, length);
return str;
}
return "";
}
@ Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged (newConfig);
if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_LANDSCAPE) {
System.out.println ("--------------------- One ------------");
}
else if (this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_PORTRAIT) {
System.out.println ("--------------- Two ------------");
}
}
}
Reply:
I also met this problem, can not find copies of the source code under study. Thank you, landlord. 940361004@qq.com
Reply:
A source it? To share it rhamiss@163.com
No comments:
Post a Comment