最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中調(diào)用系統(tǒng)的文件瀏覽器及自制簡單的文件瀏覽器

 更新時間:2016年04月24日 10:36:17   作者:劍蕭舞蝶  
這篇文章主要介紹了Android中調(diào)用系統(tǒng)自帶的文件瀏覽器及自制簡單的文件瀏覽器的方法,這里的例子僅展示瀏覽而沒有添加復(fù)制粘貼剪切等文件管理操作,非常簡單,需要的朋友可以參考下

調(diào)用系統(tǒng)自帶的文件瀏覽器
這很簡單:

/** 調(diào)用文件選擇軟件來選擇文件 **/ 
private void showFileChooser() { 
  intent = new Intent(Intent.ACTION_GET_CONTENT); 
  intent.setType("*/*"); 
  intent.addCategory(Intent.CATEGORY_OPENABLE); 
  try { 
    startActivityForResult(Intent.createChooser(intent, "請選擇一個要上傳的文件"), 
        FILE_SELECT_CODE); 
  } catch (android.content.ActivityNotFoundException ex) { 
    // Potentially direct the user to the Market with a Dialog 
    Toast.makeText(getActivity(), "請安裝文件管理器", Toast.LENGTH_SHORT) 
        .show(); 
  } 
} 

在catch,我們可以做更多的操作,比如會跳轉(zhuǎn)到一個下載文件管理器的頁面或者等等。

對于返回的數(shù)據(jù)怎么處理呢。我項目中的上傳是如下接收:

/** 根據(jù)返回選擇的文件,來進(jìn)行上傳操作 **/ 
  @Override 
  public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    if (resultCode == Activity.RESULT_OK) { 
      // Get the Uri of the selected file 
      Uri uri = data.getData(); 
      String url; 
      try { 
        url = FFileUtils.getPath(getActivity(), uri); 
        Log.i("ht", "url" + url); 
        String fileName = url.substring(url.lastIndexOf("/") + 1); 
        intent = new Intent(getActivity(), UploadServices.class); 
        intent.putExtra("fileName", fileName); 
        intent.putExtra("url", url); 
        intent.putExtra("type ", ""); 
        intent.putExtra("fuid", ""); 
        intent.putExtra("type", ""); 
 
        getActivity().startService(intent); 
 
      } catch (URISyntaxException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
      } 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
  } 

   
自制文件瀏覽器:
這里只加一些簡單的圖形:

2016424103446719.jpg (412×563)

來看代碼:

<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="wrap_content" 
  android:orientation="vertical" 
  android:layout_gravity="center_horizontal" 
  tools:context=".MainActivity" > 
 
  <TextView 
    android:id="@+id/txt1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
  <ImageButton  
    android:id="@+id/imageBt1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/home"/> 
 
  <ListView 
    android:id="@+id/listFile" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 
  </ListView> 
 
</LinearLayout> 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="horizontal" > 
 
  <ImageView 
    android:id="@+id/images" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
 
  <TextView 
    android:id="@+id/txtview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
 
</LinearLayout> 


package com.android.xiong.sdfilelook; 
 
import java.io.File; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
import android.app.Activity; 
import android.os.Bundle; 
import android.os.Environment; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ImageButton; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.TextView; 
 
public class MainActivity extends Activity { 
 
  private ListView listfile; 
  //當(dāng)前文件目錄 
  private String currentpath; 
  private TextView txt1; 
  private ImageView images; 
  private TextView textview; 
  private ImageButton imagebt1; 
 
  private int[] img = { R.drawable.file, R.drawable.folder, R.drawable.home }; 
  private File[] files; 
  private SimpleAdapter simple; 
 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    listfile = (ListView) findViewById(R.id.listFile); 
    txt1 = (TextView) findViewById(R.id.txt1); 
    imagebt1 = (ImageButton) findViewById(R.id.imageBt1); 
    init(Environment.getExternalStorageDirectory()); 
    listfile.setOnItemClickListener(new OnItemClickListener() { 
 
      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
          long arg3) { 
        // TODO Auto-generated method stub 
        // 獲取單擊的文件或文件夾的名稱 
        String folder = ((TextView) arg1.findViewById(R.id.txtview)) 
            .getText().toString(); 
        try { 
          File filef = new File(currentpath + '/' 
              + folder); 
          init(filef); 
 
        } catch (Exception e) { 
          e.printStackTrace(); 
        } 
 
      } 
    }); 
    //回根目錄 
    imagebt1.setOnClickListener(new OnClickListener() { 
       
      @Override 
      public void onClick(View v) { 
        init(Environment.getExternalStorageDirectory());   
      } 
    }); 
     
  } 
  // 界面初始化 
  public void init(File f) { 
    if (Environment.getExternalStorageState().equals( 
        Environment.MEDIA_MOUNTED)) { 
      // 獲取SDcard目錄下所有文件名 
      files = f.listFiles(); 
      if (!files.equals(null)) { 
        currentpath=f.getPath(); 
        txt1.setText("當(dāng)前目錄為:"+f.getPath()); 
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); 
        for (int i = 0; i < files.length; i++) { 
          Map<String, Object> maps = new HashMap<String, Object>(); 
          if (files[i].isFile()) 
            maps.put("image", img[0]); 
          else 
            maps.put("image", img[1]); 
          maps.put("filenames", files[i].getName()); 
          list.add(maps); 
        } 
        simple = new SimpleAdapter(this, list, 
            R.layout.fileimageandtext, new String[] { "image", 
                "filenames" }, new int[] { R.id.images, 
                R.id.txtview }); 
        listfile.setAdapter(simple); 
 
      } 
    } else { 
      System.out.println("該文件為空"); 
    } 
  } 
 
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
  } 
 
} 


相關(guān)文章

  • Android Intent封裝的實例詳解

    Android Intent封裝的實例詳解

    這篇文章主要介紹了Android Intent封裝的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • Android實現(xiàn)屏幕截圖并保存截圖到指定文件

    Android實現(xiàn)屏幕截圖并保存截圖到指定文件

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)屏幕截圖并保存截取圖片到指定文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Android利用zxing生成二維碼的過程記錄

    Android利用zxing生成二維碼的過程記錄

    Android中二維碼生成的最常用庫就是zxing了,正好目前項目有了生成二維碼的需求,所以下面這篇文章主要給大家介紹了關(guān)于Android利用zxing生成二維碼的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • Android TreeView實現(xiàn)帶復(fù)選框樹形組織結(jié)構(gòu)

    Android TreeView實現(xiàn)帶復(fù)選框樹形組織結(jié)構(gòu)

    這篇文章主要為大家詳細(xì)介紹了Android TreeView實現(xiàn)帶復(fù)選框樹形組織結(jié)構(gòu),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • 解決Bitmap通過getWidth和getHeight獲取尺寸不符的問題

    解決Bitmap通過getWidth和getHeight獲取尺寸不符的問題

    這篇文章主要介紹了解決Bitmap通過getWidth和getHeight獲取尺寸不符的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Android實現(xiàn)聊天界面

    Android實現(xiàn)聊天界面

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)聊天界面的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android實現(xiàn)圖片區(qū)域裁剪功能

    Android實現(xiàn)圖片區(qū)域裁剪功能

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)圖片區(qū)域裁剪功能,調(diào)用相冊、拍照實現(xiàn)縮放、切割圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • RN在Android打包發(fā)布App(詳解)

    RN在Android打包發(fā)布App(詳解)

    下面小編就為大家?guī)硪黄猂N在Android打包發(fā)布App(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Android中使用ScrollView實現(xiàn)滑動到底部顯示加載更多

    Android中使用ScrollView實現(xiàn)滑動到底部顯示加載更多

    本文主要介紹了android利用ScrollView實現(xiàn)滑動到底部顯示加載更多的示例代碼。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-04-04
  • 詳解android 中animation-list 動畫的應(yīng)用

    詳解android 中animation-list 動畫的應(yīng)用

    本篇文章主要介紹了詳解android 中animation-list 動畫的應(yīng)用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12

最新評論

莱阳市| 稷山县| 黎平县| 安泽县| 建阳市| 镇平县| 庆云县| 瓦房店市| 年辖:市辖区| 略阳县| 农安县| 沙田区| 高雄市| 古蔺县| 庆云县| 浦东新区| 延边| 天柱县| 桐梓县| 峡江县| 乐清市| 娄烦县| 庄浪县| 灵山县| 抚顺县| 甘德县| 明水县| 横山县| 北票市| 高唐县| 永靖县| 扬中市| 雅安市| 朝阳区| 普宁市| 股票| 泗水县| 清涧县| 托克逊县| 登封市| 南平市|