1. I searched recusively, and loaded all the images but I think this
is an inefficient way of searching on a phone, plus it means one will
load many irrelevant image files like website images.
2. Is it better to just search /sdcard/dcim ?
3. I used the MediaScanner class but it seems to display an icon with
an exclamation mark, why? I tested the code below in 1.5 and 2.1 and
the result was the same - an icon with an exclamation mark.
Can someone shed some light on this issue?
public class MediaScannerActivity extends Activity implements
MediaScannerConnectionClient {
private static final String SCAN_PATH = "/sdcard/";
private static final String FILE_TYPE = "image/jpeg";
private MediaScannerConnection conn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan);
Button scanBtn = (Button) findViewById(R.id.scanBtn);
scanBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startScan();
}
});
}
private void startScan() {
if (conn != null) {
conn.disconnect();
}
conn = new MediaScannerConnection(this, this);
conn.connect();
}
@Override
public void onMediaScannerConnected() {
conn.scanFile(SCAN_PATH, FILE_TYPE);
}
@Override
public void onScanCompleted(String path, Uri uri) {
try {
if (uri != null) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
}
catch(Exception e){
Log.d("ERROR", e.getMessage());
}
finally {
conn.disconnect();
conn = null;
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en