文件選擇器android
⑴ android webview 打開文件選擇器後不能批量選擇文件
html的文件選擇器本身就只能選擇一個文件。這不是android的錯,你可以在PC上試一下,效果是一樣的。要選擇多個文件,就創建多個input框吧。。
⑵ 安卓選取文件讀取excle代碼 實現導入,我不會求教
打開文件選擇器
?
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
選擇的結果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = FileUtils.getPath(this, uri);
//自定義一個handler
//在這里開啟線程,寫入文件。
// new tread (){
//handler 通知等待寫入信息 對話框彈出
//讀取文件,
//或得list<user>
//保存。
//完成後//handler 通知等待寫入信息 對話框關閉。
//}.start();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
FileUtils文件
public class FileUtils {
public static String getPath(Context context, Uri uri) {
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = { "_data" };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection,null, null, null);
int column_index = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
// Eat it
}
}
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
}
首先需要引入jxl.jar包。
http://sourceforge.net/projects/jexcelapi/files/jexcelapi/
讀取的代碼如下:
public List<user>readExcelFile(String filePath) {
List<user> list = new ArrayList<user>()
; try {
Workbook book = Workbook.getWorkbook(new File(filePath));
System.out.println(">>>>>>number of sheet "+book.getNumberOfSheets());
// 獲得第一個工作表對象
Sheet sheet = book.getSheet(0);
int Rows = sheet.getRows();
int Cols = sheet.getColumns();
System.out.println("當前工作表的名字:" + sheet.getName());
System.out.println("總行數:" + Rows);
System.out.println("總列數:" + Cols);
for (int i = 0; i < Rows; ++i) {
user u= new user ();
for (int j = 0; j < Cols; ++j) {
// getCell(Col,Row)獲得單元格的值
System.out.print((sheet.getCell(j, i)).getContents() + "\t");
//在這里把對應單元格的值放到u對應的屬性中,
}
System.out.print("\n");
list.add(u)
}
book.close();
} catch (Exception e) {
System.out.println(e);
}
return list;
}
⑶ QQ上傳圖片時,顯示無法打開文件選擇器怎麼弄
有沒有對應的報錯彈窗?如果沒有的話我感覺你是文件缺失,從軟體開發的角度講文件選擇器是個netframe原生控制項,但我不知道QQ用的是不是它,你可能需要去微軟官網下載一個對應的dll文件替換原先損壞的那個。
QQ,是騰訊QQ的簡稱,是一款基於互聯網的即時通信軟體。
QQ已經覆蓋了Windows、macOS、iPadOS、Android、iOS、Windows Phone、Linux等多種主流平台。其標志是一隻戴著紅色圍巾的小企鵝。騰訊QQ支持在線聊天、視頻通話、點對點斷點續傳文件、共享文件、網路硬碟、自定義面板、QQ郵箱等多種功能,並可與多種通訊終端相連。
發展歷史:
2017年1月5日,騰訊和美的集團在深圳正式簽署戰略合作協議,雙方將共同構建基於知識產權授權與物聯雲技術的深度合作,實現家電產品的連接、對話和遠程式控制制。雙方合作的第一步,是共同推出基於 QQ Family 知識產權授權和騰訊物聯雲技術的多款智能家電產品。
2019年3月13日起,QQ號碼可注銷。
2021年1月,QQ更新圖標新logo,官方回應只是春節限定。
⑷ android如何實現文件打開方式可供選擇功能。
比如通過文檔查看器打開一個文本文件時,會彈出一個可用來打開的軟體列表; <activityandroid:name=.EasyNoteandroid:label=@string/app_nameandroid:launchMode=singleTaskandroid:screenOrientation=portrait <intent-filter <actionandroid:name=android.intent.action.MAIN/ <categoryandroid:name=android.intent.category.LAUNCHER/ </intent-filter <intent-filter <actionandroid:name=android.intent.action.VIEW</action <categoryandroid:name=android.intent.category.DEFAULT</category <dataandroid:mimeType=text/plain</data </intent-filter </activity 第一個<intent-filter標簽是每個程序都有的,關鍵是要添加第二個!這樣你的應用程序就會出現在默認打開列表了。。。 注意需要將mimeType修改成你需要的類型,文本文件當然就是:text/plain 還有其它常用的如:
⑸ 這是什麼文件選擇器好像和UC有關系(卸載UC就無法使用),又好像和Android有關系(Chro
運行內存不足、ram會自動清除在運行的程序、釋放空間、ram運行內存、手機內存、usb存儲器、是分開的
⑹ Android有沒有文件選擇器,類似java的FileDialog與JFileChooser 沒有的話該怎麼實現呢
Java代碼public class CopyOfFileChooserActivity extends Activity { private String mSdcardRootPath ; //sdcard 根路徑 private String mLastFilePath ; //當前顯示的路徑 private ArrayList<FileInfo> mFileLists ; private FileChooserAdapter mAdatper ; //配置適配器 private void setGridViewAdapter(String filePath) { updateFileItems(filePath); mAdatper = new FileChooserAdapter(this , mFileLists); mGridView.setAdapter(mAdatper); } //根據路徑更新數據,並且通知Adatper數據改變 private void updateFileItems(String filePath) { mLastFilePath = filePath ; mTvPath.setText(mLastFilePath); if(mFileLists == null) mFileLists = new ArrayList<FileInfo>() ; if(!mFileLists.isEmpty()) mFileLists.clear() ; File[] files = folderScan(filePath); if(files == null) return ; for (int i = 0; i < files.length; i++) { if(files[i].isHidden()) // 不顯示隱藏文件 continue ; String fileAbsolutePath = files[i].getAbsolutePath() ; String fileName = files[i].getName(); boolean isDirectory = false ; if (files[i].isDirectory()){ isDirectory = true ; } FileInfo fileInfo = new FileInfo(fileAbsolutePath , fileName , isDirectory) ; //添加至列表 mFileLists.add(fileInfo); } //When first enter , the object of mAdatper don't initialized if(mAdatper != null) mAdatper.notifyDataSetChanged(); //重新刷新 } //獲得當前路徑的所有文件 private File[] folderScan(String path) { File file = new File(path); File[] files = file.listFiles(); return files; } private AdapterView.OnItemClickListener mItemClickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { FileInfo fileInfo = (FileInfo)(((FileChooserAdapter)adapterView.getAdapter()).getItem(position)); if(fileInfo.isDirectory()) //點擊項為文件夾, 顯示該文件夾下所有文件 updateFileItems(fileInfo.getFilePath()) ; else if(fileInfo.isPPTFile()){ //是ppt文件 , 則將該路徑通知給調用者 Intent intent = new Intent(); intent.putExtra(EXTRA_FILE_CHOOSER, fileInfo.getFilePath()); setResult(RESULT_OK , intent); finish(); } else { //其他文件..... toast(getText(R.string.open_file_error_format)); } } }; public boolean onKeyDown(int keyCode , KeyEvent event){ if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_BACK){ backProcess(); return true ; } return super.onKeyDown(keyCode, event); } //返回上一層目錄的操作 public void backProcess(){ //判斷當前路徑是不是sdcard路徑 , 如果不是,則返回到上一層。 if (!mLastFilePath.equals(mSdcardRootPath)) { File thisFile = new File(mLastFilePath); String parentFilePath = thisFile.getParent(); updateFileItems(parentFilePath); } else { //是sdcard路徑 ,直接結束 setResult(RESULT_CANCELED); finish(); } } }
⑺ Android編程 打開本地文件 文件選擇器
布局文件
<?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>
代碼
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 有沒有文件選擇對話框
// filename: CallbackBundle.java
package com.example.openfiledemo;
import android.os.Bundle;
// 簡單的Bundle參數回調介面
public interface CallbackBundle {
abstract void callback(Bundle bundle);
}
[java] view plain
// filename: CallbackBundle.java
package com.example.openfiledemo;
import android.os.Bundle;
// 簡單的Bundle參數回調介面
public interface CallbackBundle {
abstract void callback(Bundle bundle);
}
然後的打開文件對話框的一下封裝:
SimpleAdapter adapter = new SimpleAdapter(getContext(), list, R.layout.filedialogitem, new String[]{"img", "name", "path"}, new int[]{R.id.filedialogitem_img, R.id.filedialogitem_name, R.id.filedialogitem_path});
this.setAdapter(adapter);
return files.length;
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// 條目選擇
String pt = (String) list.get(position).get("path");
String fn = (String) list.get(position).get("name");
if(fn.equals(sRoot) || fn.equals(sParent)){
// 如果是更目錄或者上一層
File fl = new File(pt);
String ppt = fl.getParent();
if(ppt != null){
// 返回上一層
path = ppt;
}
else{
// 返回更目錄
path = sRoot;
}
}
else{
File fl = new File(pt);
if(fl.isFile()){
// 如果是文件
((Activity)getContext()).dismissDialog(this.dialogid); // 讓文件夾對話框消失
// 設置回調的返回值
Bundle bundle = new Bundle();
bundle.putString("path", pt);
bundle.putString("name", fn);
// 調用事先設置的回調函數
this.callback.callback(bundle);
return;
}
else if(fl.isDirectory()){
// 如果是文件夾
// 那麼進入選中的文件夾
path = pt;
}
}
this.refreshFileList();
}
}
}
[java] view plain
// filename: OpenFileDialog.java
package com.example.openfiledemo;
SimpleAdapter adapter = new SimpleAdapter(getContext(), list, R.layout.filedialogitem, new String[]{"img", "name", "path"}, new int[]{R.id.filedialogitem_img, R.id.filedialogitem_name, R.id.filedialogitem_path});
this.setAdapter(adapter);
return files.length;
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// 條目選擇
String pt = (String) list.get(position).get("path");
String fn = (String) list.get(position).get("name");
if(fn.equals(sRoot) || fn.equals(sParent)){
// 如果是更目錄或者上一層
File fl = new File(pt);
String ppt = fl.getParent();
if(ppt != null){
// 返回上一層
path = ppt;
}
else{
// 返回更目錄
path = sRoot;
}
}
else{
File fl = new File(pt);
if(fl.isFile()){
// 如果是文件
((Activity)getContext()).dismissDialog(this.dialogid); // 讓文件夾對話框消失
// 設置回調的返回值
Bundle bundle = new Bundle();
bundle.putString("path", pt);
bundle.putString("name", fn);
// 調用事先設置的回調函數
this.callback.callback(bundle);
return;
}
else if(fl.isDirectory()){
// 如果是文件夾
// 那麼進入選中的文件夾
path = pt;
}
}
this.refreshFileList();
}
}
}
⑼ 求助一個Android 文件選擇器的源碼(用於上傳文件時選擇並...
打開文件選擇器:
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
選擇結果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = FileUtils.getPath(this, uri);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
FileUtils文件
public class FileUtils {
public static String getPath(Context context, Uri uri) {
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = { "_data" };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection,null, null, null);
int column_index = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
// Eat it
}
}
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
}
⑽ android 文件選擇
privatevoidopenFileBrowse(){
Intentintent=newIntent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");//文件類型
IntentwrapperIntent=Intent.createChooser(intent,"打開方式");
startActivityForResult(wrapperIntent,0);
}
protectedvoidonActivityResult(intrequestCode,intresultCode,
Intentintent){
//Stringpath;
if(resultCode==RESULT_OK){
if(requestCode==0){
if(intent==null){
Toast.makeText(this,"未選擇任何文件",Toast.LENGTH_LONG).show();
return;
}
Uriuri=intent.getData();
if(uri==null){
Toast.makeText(this,"未選擇任何文件",Toast.LENGTH_LONG).show();
return;
}
Stringscheme=uri.getScheme();
//可能是content,file等等.需要判斷其是不是file
如果不是調用文件管理器,可能返回其他
if(scheme!=null
&&("file".endsWith(scheme.toLowerCase()))
Stringpath=uri.getPath();//文件路徑
}
}
}