当前位置:首页 » 安卓系统 » 文件选择器android

文件选择器android

发布时间: 2022-05-23 05:23:07

⑴ 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();//文件路径
}
}
}

热点内容
windows文件夹图标下载 发布:2024-05-19 13:25:44 浏览:689
数据库存储数据类型 发布:2024-05-19 13:25:28 浏览:584
电脑开机密码忘记了如何解锁没有管理员窗口 发布:2024-05-19 13:24:50 浏览:277
畅捷支付刷脸机如何设置密码 发布:2024-05-19 13:03:10 浏览:764
java麻将 发布:2024-05-19 13:03:00 浏览:433
存储过程大数据游标 发布:2024-05-19 13:00:50 浏览:515
内存存储价格 发布:2024-05-19 13:00:48 浏览:389
隔离期的算法 发布:2024-05-19 12:55:13 浏览:530
苹果怎么装安卓模拟器 发布:2024-05-19 12:42:15 浏览:801
脚本养微信 发布:2024-05-19 12:42:14 浏览:148