當前位置:首頁 » 安卓系統 » android文件選擇器

android文件選擇器

發布時間: 2022-08-15 01:25:46

❶ android studio設置狀態選擇器color怎麼用

不知道您說的是不是selector,如果是為按鈕什麼的加上點擊效果的話,可以將預設的selector設置到要實現點擊效果的控制項的background上,如果是radioButton,或者是CheckBox的話,可以將設置好的selector設置再該控制項的button下。selector可以根據您的需要進行狀態的額設置,大概是這樣的。

您有什麼問題可以繼續追問,希望能幫到您。謝謝。

❷ android 文件選擇器,用戶選擇保存路徑

你隨便選一個就行了。

❸ 求助一個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中文件選擇器的實現

今天給大家分享下文件選擇器的作用 , 具體就是獲取用戶在在SD卡選中的文件/文件夾路徑 ,類似於C#中
OpenFileDialog控制項(對C#的一站式開發還是念念不忘)。功能實現起來比較簡單,主要是幫助大家節省開發時間。

網上流傳較廣的一個成品如下 <[Android實例] 文件選擇器>, 本文也是根據上面的成品修改而成,使其更易
理解,效率更高。 除此之外,主要特色有:
1、我們監聽了用戶按下Back鍵的事件,使其返回上一層目錄;
2、針對不同的文件類型(文件vs文件夾 , 目標文件vs其他文件)做了特殊處理。

知識點一、 File 類的使用
文件選擇器的主要功能是:瀏覽文件\文件夾、文件類型等;都是通過java File類來實現的。
關於File類的使用,請參考如下博客:
<<來自java文檔 File類>>
<<Java File類>>

知識點二、調用方法說明
使用了startActivityForResult()發起調用以及onActivityResult()方法接受回調後的信息。

其他的也沒什麼好說了,大家看看代碼注釋吧~~ so easy - - 。

FileChooserActivity.java 實現文件選擇的類 。

[java] view plainprint?
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怎麼在代碼中設置狀態選擇器

要顯示選擇器,使用 createChooser() 創建Intent 並將其傳遞至 startActivity()。
/*
*一旦您已創建您的 Intent 並設置附加信息,調用 startActivity() 將其發送給系統 。
*如果系統識別可處理意向的多個Activity,它會為用戶顯示對話框供其選擇要使用的應用,
*如圖 1 所示。 如果只有一個Activity處理意向,系統會立即開始這個Activity。

startActivity(intent);
*/
// Build the intent
Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);

// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0);
boolean isIntentSafe = activities.size() > 0;

// Start an activity if it's safe
if (isIntentSafe) {
startActivity(mapIntent);
}
代碼選擇器:

Intent intent = new Intent(Intent.ACTION_SEND);
...

// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title);

// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

❻ android 做一個微信那樣的地區選擇器求思路,求方法

內置一個省市縣三級資料庫,然後查詢就可以了,很簡單。這個資料庫文件網上有下載的,自己想辦法導入到sqlite裡面就好。

❼ 這是什麼文件選擇器好像和UC有關系(卸載UC就無法使用),又好像和Android有關系(Chro

運行內存不足、ram會自動清除在運行的程序、釋放空間、ram運行內存、手機內存、usb存儲器、是分開的

❽ android webview 打開文件選擇器後不能批量選擇文件

html的文件選擇器本身就只能選擇一個文件。這不是android的錯,你可以在PC上試一下,效果是一樣的。要選擇多個文件,就創建多個input框吧。。

❾ 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);
}
}
熱點內容
db2新建資料庫 發布:2024-09-08 08:10:19 瀏覽:170
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:100
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:208
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554
雲伺服器的優點與缺點 發布:2024-09-08 06:30:34 瀏覽:734