如何让机器人厨房的文件夹路径动态? [英] how to get path of android galley folder dynamically?

查看:108
本文介绍了如何让机器人厨房的文件夹路径动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存在图像的Andr​​oid相机库文件夹路径

i want to get android camera gallery folder path to save images in that

在不同的手机是在星系例如不同的是

in different mobile phones it is different for example in galaxy it is

/sdcard/DCIM/camera/image.jpg

和其他手机例如:

/sdcard/media/images/image.jpg

热得路径,最多动态库文件夹?

hot get path up to gallery folder dynamically?

任何帮助将是AP preciated。

any help would be appreciated.

推荐答案

您可以使用文件资源管理器上显示为您的手机的所有的东西,你会从galary

You Can Use Following example of File Explorer Which Display All Stuff of Your phone and You will Select Your items from galary

FileExplorer.java

FileExplorer.java

  package com.fileUpload;

  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import android.app.AlertDialog;
  import android.app.ListActivity;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;

  public class FileExplorer extends ListActivity {

  private List<String> item;
  private List<String> path;
  private String root="/";
  private TextView myPath;

  /** Called when the activity is first created. */
  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.file);
    myPath = (TextView)findViewById(R.id.path);
    getDir(root);
}

private void getDir(String dirPath)
{
 myPath.setText("Location: " + dirPath);

 item = new ArrayList<String>();
 path = new ArrayList<String>();

 File f = new File(dirPath);
 File[] files = f.listFiles();

 if(!dirPath.equals(root))
 {

  item.add(root);
  path.add(root);

  item.add("../");
  path.add(f.getParent());

 }

 for(int i=0; i < files.length; i++)
 {
   File file = files[i];
   path.add(file.getPath());
   if(file.isDirectory())
    item.add(file.getName() + "/");
   else
    item.add(file.getName());
 }

 ArrayAdapter<String> fileList =
  new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, item);
 setListAdapter(fileList);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

File file = new File(path.get(position));

  if (file.isDirectory())
  {
    if(file.canRead())
        getDir(path.get(position));
   else
   {
      new AlertDialog.Builder(this)
      .setIcon(R.drawable.icon)
      .setTitle("[" + file.getAbsolutePath() + "] folder can't be read!")
      .setPositiveButton("OK", 
       new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
          }
         }).show();
     }
   }
   else
   {
       Bundle b=new Bundle();
       b.putString("param1",file.getAbsolutePath());
       Intent i=new Intent(this,DemoActivity.class);
       i.putExtras(b);
       startActivity(i);

 }
 }
 }

这篇关于如何让机器人厨房的文件夹路径动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆