Android----弹出框选择文件夹目录以及启用新的Task打开文件_IT168文库

合集下载

Android系统文件夹目录详解 - 手机入门知..

Android系统文件夹目录详解 - 手机入门知..

\\system\\app\\Street.odex \\system\\app\\Sync.apk 同步程序 \\system\\app\\Sync.odex、 \\system\\app\\Talk.apk 语音程序 \\system\\app\\Talk.odex \\system\\app\\TelephonyProvider.apk 电话提供 \\system\\app\\TelephonyProvider.odex \\system\\app\\Up dater.apk 更新程序 \\system\\app\\Up dater.odex \\system\\app\\Vending.apk 制造商信息 \\system\\app\\Vending.odex \\system\\app\\VoiceDialer.apk 语音拨号器 \\system\\app\\VoiceDialer.odex \\system\\app\\YouTube.apk Youtube视频 \\system\\app\\YouTube.odex \\system\\bin这个目录下的文件都是系统的本地程序,从bin文件夹名称可以看出是binary二进制的程序,里面主要是 Linux系统自带的组件,Android手机网就主要文件做下简单的分析介绍: \\system\\bin\\akmd \\system\\bin\\am \\system\\bin\\app_process 系统进程 \\system\\bin\\dalvikvm Dalvik 虚拟机宿主 \\system\\bin\\dbus-daemon 系统BUS总线监控 \\system\\bin\\debuggerd 调试器 \\system\\bin\\debug_tool 调试工具 \\system\\bin\\dexopt DEX选项 \\system\\bin\\dhcpcd DHCP服务器 \\system\\bin\\dumpstate 状态抓取器 \\system\\bin\\dumpsys 系统抓取器 \\system\\bin\\dvz \\system\\bin\\fillup \\system\\bin\\flash_image 闪存映像 \\system\\bin\\hciattach \\system\\bin\\hcid HCID内核 \\system\\bin\\hostapd \\system\\bin\\hostapd_cli \\system\\bin\\htclogkernel \\system\\bin\\input \\system\\bin\\installd \\system\\bin\\itr \\system\\bin\\linker \\system\\bin\\logcat Logcat日志打印 \\system\\bin\\logwrapper \\system\\bin\\mediaserver \\system\\bin\\monkey \\system\\bin\\mountd 存储挂载器 \\system\\bin etcfg 网络设置 \\system\\bin\\ping Ping程序 \\system\\bin\\playmp3 MP3播放器 \\system\\bin\\pm 包管理器 \\system\\bin\\qemud QEMU虚拟机 \\system\\bin\\radiooptions 无线选项

12352233android系统文件夹目录说明

12352233android系统文件夹目录说明

如果您不需要这些缓存文件或者磁盘空间不足,请随意删除,删除后不会影响软件的运行。
注:删除前,请退出迅雷和迅雷看看播放器,防止由于软件对内容的读写导致无法删除。
注:在迅雷看看播放器(3.2或以上版本)中可以自定义本目录的位置。本目录为迅雷看看的缓存目录。
xv文件为片库和网页播放的缓存文件,保留这些文件可以让您再次播放的时候在联网状态下无须重新缓冲。
影片下载完后会转化为完整的视频文件,并且清除缓存文件。
如果您不需要这些缓存文件或者磁盘空间不足,请随意删除,删除后不会影响软件的运行。
注:删除前,请退出迅雷和迅雷看看播放器,防止由于软件对内容的读写导致无法删除。
注:在迅雷看看播放器(3.2或以上版本)中可以自定义本目录的位置。本目录为迅雷看看的缓存目录。
影片下载完后会转化为完整的视频文件,并且清除缓存文件。
如果您不需要这些缓存文件或者磁盘空间不足,请随意删除,删除后不会影响软件的运行。
注:删除前,请退出迅雷和迅雷看看播放器,防止由于软件对内容的读写导致无法删除。
注:在迅雷看看播放器(3.2或以上版本)中可以自定义本目录的位置。本目录为迅雷看看的缓存目录。
如果您不需要这些缓存文件或者磁盘空间不足,请随意删除,删除后不会影响软件的运行。
注:删除前,请退出迅雷和迅雷看看播放器,防止由于软件对内容的读写导致无法删除。
注:在迅雷看看播放器(3.2或以上版本)中可以自定义本目录的位置。本目录为迅雷看看的缓存目录。
xv文件为片库和网页播放的缓存文件,保留这些文件可以让您再次播放的时候在联网状态下无须重新缓冲。
本目录为迅雷看看的缓存目录。
xv文件为片库和网页播放的缓存文件,保留这些文件可以让您再次播放的时候在联网状态下无须重新缓冲。

Android7.0运行时权限弹窗问题的解决

Android7.0运行时权限弹窗问题的解决

Android7.0运⾏时权限弹窗问题的解决Android 7.0系统在运⾏应⽤的时候,对权限做了诸多限制,normal, dangerous, signature, signatureOrSystem ,取决于保护级别,在确定是否授予权限时,系统可能采取不同的操作。

normal 表⽰权限是低风险的,不会对系统、⽤户或其他应⽤程序造成危害;dangerous 表⽰权限是⾼风险的,系统将可能要求⽤户输⼊相关信息,才会授予此权限;signature 表⽰只有当应⽤程序所⽤数字签名与声明引权限的应⽤程序所⽤数字签名相同时,才能将权限授给它;signatureOrSystem 表⽰将权限授给具有相同数字签名的应⽤程序或android 包类。

这⼀保护级别适和于⾮常特殊的情况,⽐如多个供应商需要通过系统映像共享功能时运⾏时权限弹窗问题是很多系统定制的客户要求屏蔽的,⼀直以来没有特别好的⽅法,下⾯我分享⼀下我⾃⼰验证可⾏的⽅案⽅案1,修改frameworks/base/services/core/java/com/android/server/pm/PackageManagerService和frameworks/base/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy⽂件,PackageManagerService ⽂件修改代码如下:@Overridepublic void systemReady() {...synchronized (mPackages) {...for (int userId : UserManagerService.getInstance().getUserIds()) {//if (!mSettings.areDefaultRuntimePermissionsGrantedLPr(userId)) {//注释掉这个判断grantPermissionsUserIds = ArrayUtils.appendInt(grantPermissionsUserIds, userId);//}}}DefaultPermissionGrantPolicy⽂件修改代码如下:private void grantPermissionsToSysComponentsAndPrivApps(int userId) {Log.i(TAG, "Granting permissions to platform components for user " + userId);synchronized (mService.mPackages) {for (PackageParser.Package pkg : mService.mPackages.values()) {// if (!isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) //删掉isSysComponentOrPersistentPlatformSignedPrivAppLPr判断if(!doesPackageSupportRuntimePermissions(pkg)|| pkg.requestedPermissions.isEmpty()) {continue;}Set<String> permissions = new ArraySet<>();final int permissionCount = pkg.requestedPermissions.size();for (int i = 0; i < permissionCount; i++) {String permission = pkg.requestedPermissions.get(i);BasePermission bp = mService.mSettings.mPermissions.get(permission);if (bp != null && bp.isRuntime()) {permissions.add(permission);}}if (!permissions.isEmpty()) {grantRuntimePermissionsLPw(pkg, permissions, true, userId);}}}}简单说明下这个⽅案的修改原理,在PMS的systemReady⽅法中会遍历所有拥有默认运⾏时权限应⽤,通过遍历它们的UserId来赋予权限,注释掉判断是否为拥有运⾏时权限的应⽤⽅法后,会遍历所有应⽤,遍历应⽤且赋予权限的操作是在DefaultPermissionGrantPolicy中grantPermissionsToSysComponentsAndPrivApps⽅法,注释掉判断签名应⽤和系统应⽤的⽅法,普通应⽤也可以获取所有运⾏时权限,这样所有应⽤都不会有运⾏时权限的弹窗了。

安卓系统文件夹结构及其文件解析

安卓系统文件夹结构及其文件解析

安卓系统文件夹结构及其文件解析安卓系统的文件夹结构是由多个文件夹和文件组成,每个文件夹和文件都有特定的功能和用途。

下面将详细介绍安卓系统文件夹结构及其文件解析。

1.根目录(/)根目录是整个文件系统的起点,它包含了一些重要的目录和文件,例如:- system:系统文件夹,包含了系统的核心文件和程序。

- data:数据文件夹,包含了应用程序的数据和设置。

- dev:设备文件夹,包含了设备的文件和设备节点。

- proc:进程文件夹,包含了正在运行的进程的信息。

- etc:配置文件夹,包含了系统的配置文件。

- mnt:挂载文件夹,包含了已挂载的存储设备。

- sys:系统文件夹,包含了系统的配置和状态信息。

- vendor:供应商文件夹,包含了设备供应商提供的一些文件。

2. system文件夹system文件夹是安卓系统的核心,包含了系统的核心文件和程序。

其中一些重要的子文件夹和文件包括:- app:应用程序文件夹,包含了系统预装的应用程序。

- etc:配置文件夹,包含了系统的配置文件。

- lib:共享库文件夹,包含了系统的共享库文件。

- media:多媒体文件夹,包含了系统的多媒体文件。

- framework:框架文件夹,包含了系统的框架文件。

- priv-app:特权应用程序文件夹,包含了一些特权应用程序。

3. data文件夹data文件夹包含了应用程序的数据和设置。

其中一些重要的子文件夹和文件包括:- app:应用程序文件夹,包含了已安装的应用程序。

- data:数据文件夹,包含了应用程序的数据。

- system:系统数据文件夹,包含了一些系统的数据文件。

- dalvik-cache:Dalvik虚拟机缓存文件夹,包含了应用程序的二进制代码缓存。

- shared_prefs:共享首选项文件夹,包含了应用程序的共享首选项。

4. dev文件夹dev文件夹包含了设备的文件和设备节点。

其中一些重要的文件和文件夹包括:- null:空设备文件,用于丢弃输出。

Android编译命令

Android编译命令

Android编译命令⼀、引⾔先看下⾯⼏条指令,相信编译过Android源码的⼈都再熟悉不过的。

source setenv.shlunchmake -j12记得最初刚接触Android时,同事告诉我⽤上⾯的指令就可以编译Android源码,指令虽短但过⼏天就记不全或者忘记顺序,每次编译时还需要看看⾃⼰的云笔记,冰冷的指令总是难以让我记忆。

后来我决定认真研究下这个指令的含义。

知其然还需知其所以然,这样能更深层次的理解并记忆,才能与⾃⾝的知识体系建⽴强连接,或许还有意外收获,果然如此,接下来跟⼤家分享⼀下在研究上述⼏条指令含义的过程中,深⼊了解到的Android Build(编译)系统。

⼆、编译命令准备好编译环境后,编译Android源码的第⼀步是source build/envsetup.sh,其中source命令就是⽤于运⾏shell脚本命令,功能等价于”.”,因此该命令也等价于. build/envsetup.sh。

在⽂件envsetup.sh声明了当前会话终端可⽤的命令,这⾥需要注意的是当前会话终端,也就意味着每次新打开⼀个终端都必须再⼀次执⾏这些指令。

起初并不理解为什么新开的终端不能直接执⾏make指令,到这⾥总算明⽩了。

接下来,解释⼀下本⽂开头的引⽤的命令:source setenv.sh //初始化编译环境,包括后⾯的lunch和make指令lunch //指定此次编译的⽬标设备以及编译类型make -j12 //开始编译,默认为编译整个系统,其中-j12代表的是编译的job数量为12。

所有的编译命令都在envsetup.sh⽂件能找到相对应的function,⽐如上述的命令lunch,make,在⽂件⼀定能找到function lunch(){...}function make(){...}source envsetup.sh,需要cd到setenv.sh⽂件所在路径执⾏,路径可能在build/envsetup.sh,或者integrate/envsetup.sh,再或者不排除有些⼚商会封装⾃⼰的.sh脚本,但核⼼思路是⼀致的。

Android中调用文件管理器并返回选中文件的路径

Android中调用文件管理器并返回选中文件的路径

Android中调⽤⽂件管理器并返回选中⽂件的路径实际项⽬中经常需要调⽤⽂件管理器,选择下载路径或者上传的本地⽂件路径。

今天就给⼤家做个demo⽰范该功能的实现过程。

⼀、实现效果预览以下为三星S6的样机测试效果,当然不同⼿机调⽤后的效果不⼀样。

⼆、代码实现布局⽂件很简单,就⼀个Button和TextView,这⾥不⽰范了,直接上实现代码:1package com.panhouye.selectfile;23import android.annotation.SuppressLint;4import android.app.Activity;5import android.content.ContentUris;6import android.content.Context;7import android.content.Intent;8import android.database.Cursor;9import .Uri;10import android.os.Build;11import android.os.Bundle;12import android.os.Environment;13import android.provider.DocumentsContract;14import android.provider.MediaStore;15import android.support.v7.app.AppCompatActivity;16import android.view.View;17import android.widget.Button;18import android.widget.TextView;19import android.widget.Toast;2021public class MainActivity extends AppCompatActivity {22 TextView tv;23 @Override24protected void onCreate(Bundle savedInstanceState) {25super.onCreate(savedInstanceState);26 setContentView(yout.activity_main);27 Button btn = (Button) findViewById(R.id.btn);28 tv = (TextView) findViewById();29 btn.setOnClickListener(new View.OnClickListener() {30 @Override31public void onClick(View v) {32 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);33//intent.setType(“image/*”);//选择图⽚34//intent.setType(“audio/*”); //选择⾳频35//intent.setType(“video/*”); //选择视频(mp4 3gp 是android⽀持的视频格式)36//intent.setType(“video/*;image/*”);//同时选择视频和图⽚37 intent.setType("*/*");//⽆类型限制38 intent.addCategory(Intent.CATEGORY_OPENABLE);39 startActivityForResult(intent, 1);40 }41 });42 }43 String path;44 @Override45protected void onActivityResult(int requestCode, int resultCode, Intent data) {46if (resultCode == Activity.RESULT_OK) {47 Uri uri = data.getData();48if ("file".equalsIgnoreCase(uri.getScheme())){//使⽤第三⽅应⽤打开49 path = uri.getPath();50 tv.setText(path);51 Toast.makeText(this,path+"11111",Toast.LENGTH_SHORT).show();52return;53 }54if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {//4.4以后55 path = getPath(this, uri);56 tv.setText(path);57 Toast.makeText(this,path,Toast.LENGTH_SHORT).show();58 } else {//4.4以下下系统调⽤⽅法59 path = getRealPathFromURI(uri);60 tv.setText(path);61 Toast.makeText(MainActivity.this, path+"222222", Toast.LENGTH_SHORT).show();62 }63 }64 }6566public String getRealPathFromURI(Uri contentUri) {67 String res = null;68 String[] proj = { MediaStore.Images.Media.DATA };69 Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);70if(null!=cursor&&cursor.moveToFirst()){;71int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);72 res = cursor.getString(column_index);73 cursor.close();74 }75return res;76 }7778/**79 * 专为Android4.4设计的从Uri获取⽂件绝对路径,以前的⽅法已不好使80*/81 @SuppressLint("NewApi")82public String getPath(final Context context, final Uri uri) {8384final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 8586// DocumentProvider87if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {88// ExternalStorageProvider89if (isExternalStorageDocument(uri)) {90final String docId = DocumentsContract.getDocumentId(uri);91final String[] split = docId.split(":");92final String type = split[0];9394if ("primary".equalsIgnoreCase(type)) {95return Environment.getExternalStorageDirectory() + "/" + split[1];96 }97 }98// DownloadsProvider99else if (isDownloadsDocument(uri)) {100101final String id = DocumentsContract.getDocumentId(uri);102final Uri contentUri = ContentUris.withAppendedId(103 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));104105return getDataColumn(context, contentUri, null, null);106 }107// MediaProvider108else if (isMediaDocument(uri)) {109final String docId = DocumentsContract.getDocumentId(uri);110final String[] split = docId.split(":");111final String type = split[0];112113 Uri contentUri = null;114if ("image".equals(type)) {115 contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;116 } else if ("video".equals(type)) {117 contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;118 } else if ("audio".equals(type)) {119 contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;120 }121122final String selection = "_id=?";123final String[] selectionArgs = new String[]{split[1]};124125return getDataColumn(context, contentUri, selection, selectionArgs);126 }127 }128// MediaStore (and general)129else if ("content".equalsIgnoreCase(uri.getScheme())) {130return getDataColumn(context, uri, null, null);131 }132// File133else if ("file".equalsIgnoreCase(uri.getScheme())) {134return uri.getPath();135 }136return null;137 }138139/**140 * Get the value of the data column for this Uri. This is useful for141 * MediaStore Uris, and other file-based ContentProviders.142 *143 * @param context The context.144 * @param uri The Uri to query.145 * @param selection (Optional) Filter used in the query.146 * @param selectionArgs (Optional) Selection arguments used in the query.147 * @return The value of the _data column, which is typically a file path.148*/149public String getDataColumn(Context context, Uri uri, String selection,150 String[] selectionArgs) {151152 Cursor cursor = null;153final String column = "_data";154final String[] projection = {column};155156try {157 cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,158null);159if (cursor != null && cursor.moveToFirst()) {160final int column_index = cursor.getColumnIndexOrThrow(column);161return cursor.getString(column_index);162 }163 } finally {164if (cursor != null)165 cursor.close();166 }167return null;168 }169170/**171 * @param uri The Uri to check.172 * @return Whether the Uri authority is ExternalStorageProvider.173*/174public boolean isExternalStorageDocument(Uri uri) {175return "com.android.externalstorage.documents".equals(uri.getAuthority());176 }177178/**179 * @param uri The Uri to check.180 * @return Whether the Uri authority is DownloadsProvider.181*/182public boolean isDownloadsDocument(Uri uri) {183return "com.android.providers.downloads.documents".equals(uri.getAuthority());184 }185186/**187 * @param uri The Uri to check.188 * @return Whether the Uri authority is MediaProvider.189*/190public boolean isMediaDocument(Uri uri) {191return "com.android.providers.media.documents".equals(uri.getAuthority());192 }193 }三、⼩结这是调⽤系统⾃带的⽂件管理,⽆法保证和控制统⼀的界⾯显⽰,所以⼤家还是要实现与⾃⼰APP统⼀的⽂件管理界⾯,共勉。

android task用法

android task用法

android task用法在Android中,Task是一个抽象概念,用于描述应用程序中的活动堆栈。

一个Task可以包含一个或多个Activity,这些Activity按照打开的顺序排列在堆栈中。

当用户启动一个应用程序时,系统会为该应用程序创建一个新的Task,并将其作为栈顶Activity的Task。

以下是关于Android Task用法的一些方面:1. 启动新的Task,在AndroidManifest.xml文件中,可以通过设置Activity的launchMode属性为singleTask或singleInstance来启动一个新的Task。

这样做会创建一个新的Task,并将该Activity作为Task的栈顶Activity。

2. Task的生命周期,Task的生命周期与Activity的生命周期相关联。

当用户启动一个Activity时,系统会将该Activity压入Task的堆栈中;当用户按下返回按钮时,系统会将该Activity弹出栈,销毁该Activity并恢复上一个Activity。

3. Task的管理,可以使用Intent标志(Intent.FLAG_ACTIVITY_NEW_TASK)来在应用程序中创建新的Task。

此外,可以使用TaskAffinity属性来指定Activity所属的Task。

4. 任务切换,在多任务处理时,用户可以通过最近任务列表(Recents)来切换不同的Task。

当用户切换到另一个Task时,系统会将该Task的顶部Activity显示在屏幕上。

5. 任务栈的清理,在某些情况下,系统可能会清理Task堆栈,释放资源。

开发人员可以通过设置Activity的clearTaskOnLaunch属性来控制Task的清理行为。

总的来说,Android中的Task提供了一种组织和管理Activity的方式,开发人员可以通过合理地使用Task来实现不同的导航和用户交互体验。

Android----弹出框选择文件夹目录以及启用新的Task打开文件_IT168文库

Android----弹出框选择文件夹目录以及启用新的Task打开文件_IT168文库

[ c-sh a r p ]
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45.
列表显示 It e m 通过布局文件 file _ro w.xm l
[ c-sh a r p ]

01. 02. 03. 04.
<?xml version= " 1.0" encoding = " utf-8" ?> <LinearLayout xmlns:android= " /apk/res/android" android:orientation= " horiz ontal"
04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29.
android:orientation= " horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" android:backg round= " #ffffff" > <LinearLayout android:orientation= " horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" android:backg round= " @ drawable/listview_selected" android:padding = " 6px" > <Imag eView android:id= " @ +id/icon" android:layout_width= " 30dip" android:layout_heig ht= " 30dip" > </Imag eView> <T extView android:id= " @ +id/text" android:layout_g ravity= " center_horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " wrap_content" android:textColor= " @ drawable/black" > </T extView> </LinearLayout> </LinearLayout>
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

But t o n弹出显示文件夹选择框 T e xt Vie w就是用来显示当前选择的文件夹路径
[ c-sh a r p ]
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31.
<?xml version= " 1.0" encoding = " utf-8" ?> <LinearLayout xmlns:android= " /apk/res/android" android:layout_width= " 250px" android:layout_heig ht= " 400px" android:orientation= " vertical" android:backg round= " @ drawable/white" > <T extView android:id= " @ +id/mPath" android:layout_width= " wrap_content" android:layout_heig ht= " wrap_content" android:padding = " 5px" android:textSiz e= " 18sp" android:textColor= " @ drawable/blue" > </T extView> <ListView android:id= " @ android:id/list" android:layout_width= " fill_parent" android:layout_heig ht= " 330px" > </ListView> <LinearLayout android:g ravity= " center" android:layout_width= " wrap_content" android:layout_heig ht= " wrap_content" android:orientation= " horiz ontal" android:backg round= " @ drawable/white" > <Button android:id= " @ +id/buttonConfirm" android:layout_width= " 125px" android:layout_heig ht= " fill_parent" android:text= " 确定" /> <Button android:id= " @ +id/buttonCancle" android:layout_width= " 125px" android:layout_heig ht= " fill_parent" android:text= " 取消" /> </LinearLayout> </LinearLayout>
18. 19. 20. 21. 22. 23.
android:textSiz e= " 20px" android:textColor= " #219ac6" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" /> </LinearLayout>
<?xml version= " 1.0" encoding = " utf-8" ?> <LinearLayout xmlns:android= " /apk/res/android" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" android:orientation= " vertical" android:backg round= " @ drawable/white" > <Button android:id= " @ +id/button" android:layout_width= " fill_parent" android:layout_heig ht= " wrap_content" android:text= " 选择文件" /> <T extView android:id= " @ +id/fileT ext" android:g ravity= " center" android:textSiz e= " 20px"
列表显示 It e m 通过布局文件 file _ro w.xm l
[ c-sh a r p ]
01. 02. 03. 04.
<?xml version= " 1.0" encoding = " utf-8" ?> <LinearLayout xmlns:android= " /apk/res/android" android:orientation= " horiz ontal"
public class MainAcivity extends Activity{ public static final int FILE_RESULT _CODE = 1; private T extView textView; @ Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(yout.main); Button button = (Button)findViewById(R.id.button); textView = (T extView)findViewById(R.id.fileT ext); button.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(MainAcivity. this ,MyFileManag er. class ); startActivityForResult(intent, FILE_RESULT _CODE); } }); } @ Override protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (FILE_RESULT _CODE == requestCode){ Bundle bundle = null ; if (data!= null &&(bundle=data.g etExtras())!= null ){ textView.setT ext( " 选择文件夹为:" +bundle.g etString ( " file" )); } } } }
[ c-sh a r p ]
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45.
这里通过 st art Act ivit yFo rRe sult () 弹出的 Act ivit y 所以要重写 o nAct ivit yRe sult 方法 在目标 Act ivit y调用方法 finish() 的时候会回调 这里需要注意在按返回键时也会调用该方法 所以这里还需要判空 然后再 MyFile Manage r 这个 Act ivit y中通过 List Vie w来显示文件列表 布局文件 file se le ct .xm l
Android----弹 出 框 选 择 文 件 夹 目 录 以 及 启 用 新 的 Task打 开 文 件
首先看效果图
第一个 Act ivit y很简单就是一个按钮 But t o n 加一个 T e xt Vie w 见 m ain.xm l
[ c-sh a r p ]
01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16.08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29.
android:orientation= " horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" android:backg round= " #ffffff" > <LinearLayout android:orientation= " horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " fill_parent" android:backg round= " @ drawable/listview_selected" android:padding = " 6px" > <Imag eView android:id= " @ +id/icon" android:layout_width= " 30dip" android:layout_heig ht= " 30dip" > </Imag eView> <T extView android:id= " @ +id/text" android:layout_g ravity= " center_horiz ontal" android:layout_width= " fill_parent" android:layout_heig ht= " wrap_content" android:textColor= " @ drawable/black" > </T extView> </LinearLayout> </LinearLayout>
相关文档
最新文档