`
ericbaner
  • 浏览: 173390 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android代码如何访问Res目录下的内容

 
阅读更多

如何访问平时APK文件Res目录下的内容呢? 如果直接访问Apk下的assets目录可以使用AssetManager类处理,而需要访问res/raw这样的文件夹怎么办呢? APK在安装时已经解压缩,部分资源存放在/data/data/package_name/这里, 比如我们想访问res/raw/android123.cwj文件,可以使用android.resource://package_name/" + R.raw.android123 这个Uri,其中package_name是你工程的包名。

  完整的处理代码为 Uri uri = Uri.parse("android.resource://com.android123.Sample/raw/android123.cwj"); 即可使用工程res/raw目录下的文件了。

 

原文链接 :http://hi.baidu.com/zhoutianyang/blog/item/1a4d56df5979551f485403de.html

 

A Uri object can be used to reference a resource in an APK file. The Uri should be one of the following formats:

  • android.resource://package_name/id_number 
    package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp 
    id_number is the int form of the ID.
    The easiest way to construct this form is
    Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");
    
    
  • android.resource://package_name/type/name 
    package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp 
    type is the string form of the resource type. For example, raw or drawable . name is the string form of the resource name. That is, whatever the file name was in your res directory, without the type extension. The easiest way to construct this form is
    Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");
分享到:
评论

相关推荐

    Android代码-安卓res资源混淆器

    可以将apk安装包res目录内的文件重命名为0.png、1.png、a.9.png、A.xml...可一定程度上减少安装包体积 使用方法:拖apk文件到AndroidResProguard.bat,成功将生成xxx_r.apk,xxx_mapping.txt 注意:目前未经大量...

    Android 使用mediaplayer播放res/raw文件夹中的音乐的实例

    (2)修改layout目录下的xml布局文件,添加3个按钮空间和一个文本控件,用于提示当前播放状态和 播放暂停 停止等功能。具体代码如下 <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android ...

    Android冗余res内容清理

    不错的android冗余图片、冗余布局的清理工具,希望对大家有帮助呀!

    Android代码-个人中心页面框架

    xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@ id/item_one" android:layout_width="match_parent" android:layout_height="wrap_content" leon:leftIcon="@drawable/history" leon:...

    android-art-res, 在android开发的研究艺术中,源代码.zip

    android-art-res, 在android开发的研究艺术中,源代码 android-art-res

    疯狂Android讲义源代码2

    我个人认为 ,李刚的疯狂android讲义 讲的比较详细的,还有两个实战项目,以下是与代码对应的本书目录 第1章 Android应用与开发环境 1.1 Android的发展和历史 1.1.1 Android的发展和简介 1.1.2 Android平台架构...

    Android代码-Utils Android

    [Logo] (https://github.com/jainakhil88/android-commons/blob/master/sample/Android8/res/drawable-mdpi/ic_launcher.png) Android Commons Android Commons aims to provide quick, easy and ready to use set ...

    Android代码-AndroidUIAdapter

    第一步,复制该项目res目录下包含dimens.xml的velues文件夹到自己的项目的res目录下,其中values文件夹只复制其dimens.xml文件 直接在项目中引用, px / 密度 = dp(通常密度为2,例:10px / 2 = 5dp) ​ 可...

    Android代码-AndroidGradientUI

    xmlns:app="http://schemas.android.com/apk/res-auto" Then you can add GradientIconView in layout.xml The GradientIconView can gradient change itself from top_icon to bottom_icon. GradientIconView will...

    Android代码-CustomKeyboardView

    我们在res/xml 目录下新建一个idcard_keyboard.xml文件。 这里主要介绍一些常用的类属性,更多请参考andorid官网。 Keyboard类:存储键盘以及按键相关信息。 android:horizontalGap 按键...

    Android 播放Gif图片动画【源代码】.rar

    得到了帧文件后我们可以就编写代码,在res目录下新建anim动画文件夹,对应的item 为顺序的图片从开始到结束,duration为每张逐帧播放间隔,oneshot 为false 代表循环播放,设置为true 即播放一次即停止。具体代码...

    Android代码-Immersive

    一行代码实现沉浸式,适配android4.4到8.0 ,沉浸式前所未有的简单。 代码示例 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { ...

    Android代码-APAS

    LeetCode-Sol-Res This repository contains solutions and resources for LeetCode algorithm problems. The solutions are derived from my own thinking and the discussion. They are cleaned and optimized ...

    Android代码-VerificationCodeView

    Android Studio:在项目的根目录下build.gradle里的allprojects下添加如下引用: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } 然后在app目录下 build.gradle 下添加依赖 ...

    Android代码-AndroidWebRTC直播

    AndroidRTC WebRTC Live Streaming An Android client for ProjectRTC. It is designed to demonstrate WebRTC video calls between androids and/or desktop browsers, but WebRtcClient could be used in other ...

    Android代码-AndroidToolsExample

    Android开发在所难免的就是UI的预览和调整,一般情况下都是直接run看效果,或者是使用AS的preview预览,但这同样带来个小问题,就是你的测试内容会跟随着代码被打包到apk中,如果没做容错的处理很有可能将测试内容...

    Android代码-接手老项目,难免遇到前辈的硬编码,怎么办?利用工具剔除出来啊

    Android hardcoding extraction tool Extraction string and dimens from layout,Merge into strings.xml and dimens.xml Download Usage > Programs description > > Programs purpose: fixed Android project ...

    Android studio开发小型对话机器人app(实例代码)

    2)先写页面在res->layout目录下新建两个layout xml file activity_main作为主页面,msg_item为附在其上的消息页面。(具体代码见文末) 这里再acitvity_main采用的不是ListView而是RecyclerVie

    Android代码-自定义圆形拖动条

    xmlns:swagpoints="http://schemas.android.com/apk/res-auto" android:id="@ id/seekbar_point" android:layout_width="match_parent" android:layout_height="340dp" android:layout_gravity="center" ...

    Android代码-AndroidShortcuts

    Android Shortcuts Example app for shortcuts in design library v25 Demo Manifest Add meta-data before `````` tag in Manifest.xml Add Shortcut To add or edit a new shotcut, go to /res/xml/shortcuts....

Global site tag (gtag.js) - Google Analytics