在角落访问存储 [英] Accessing Storage on the Nook

查看:158
本文介绍了在角落访问存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最接近的文件,我可以找到有做文件存储为<一个href="http://nookdeveloper.zendesk.com/entries/20257971-updated-what-are-the-size-constraints-on-my-applications"相对=nofollow>这个帖子(见下文,如果你不能访问),但它让我有几个问题。

我真的,真的,真的喜欢什么路径,一个知识渊博的解释映射到哪些存储在这里,看到我们应该如何硬code,以及如何precisely我们预计访问它们。实际的code样品将是最高级。从瞎搞这个我最好的猜测是:

  • / sdcard->映射到内部的eMMC插槽,和访问限制。 Environment.getExternalStorageDirectory(); ......还是返回这一点。
  • /媒体 - >映射到内部8GB内存(我可以写本)
  • /数据 - >?
  • ? - >映射到可选的microSD卡

我们如何可以访问外部(可选的,额外的,一来可以弹出)SD卡,如果<一个href="http://connect.nookdeveloper.com/t5/General-Discussion/sdcard-not-being-recognized/m-p/275#M121"相对=nofollow> / SD卡映射到受限存储,而不是的?

现在引用的角落开发文档:

  

背景有在角落两种不同的分区方案   在市场上彩色设备的今天,一个是只提供给250MB   在/ data分区和4GB的可用的应用程序之一   在/ data分区的应用程序。其结果是,它必须   该应用程序的设计和以这样一种方式,以开发   有效地管理空间。这挡不应用程序,因此不会   接受通过店铺分布情况。

     

领域相关的技术建议或解决方案,如果你的   应用需要大量的数据(包括但不限   为图像,音频或视频内容),你应该下载那些   在运行时的资源并存储它们的更大的分区   设备。如果你的应用程序将请求和存储超过   数据或资源,你必须恪守的100MB以下   限制:

     

您的应用程序必须清楚明确地说明,在说明   提供所使用/由传送大量数据的   应用。你必须写你的资源和数据到适当的   划分。可以检测是否该设备具有的放大/数据   分区如下:

 体statfs STAT =新体statfs(/数据);
长方bytesAvailable =(长)stat.getBlockSize()*(长)stat.getBlockCount();
长megAvailable =方bytesAvailable / 1048576;
如果(megAvailable&GT; 1000){
...写你的资源/数据
} 其他 {
...在/ mnt /媒体写你的资源...
}
 

要写入数据到应用程序的私有空间/数据

 的FileOutputStream FOS = openFileOutput(文件名,Context.MODE_WORLD_READABLE);
 

您的应用程序不应该承担   presence设备上的SD卡,但你可以通过调用检验:   以

     

Environment.getExternalStorageState();如果没有找到SD卡,   应用程序必须有一个通知给用户正常退出   作为对退出的原因。

     

记住,访问/媒体的分区,以及   ExternalStorage你需要在你的清单声明:

 &LT;使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E&GT;
&LT; /使用-许可&GT;
 

解决方案

首先,请尝试以下方法:

  • <一个href="http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir%28java.lang.String%29"相对=nofollow> Context.getExternalFilesDir
  • Context.getExternalCacheDir
  • <一个href="http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29"相对=nofollow> Environment.getExternalStoragePublicDirectory

如果没有那些回报你,你可以写一个目录,检查以下的谷歌组线程,并使用在最后的答案提供的code,其中列举了目前所有的挂载点:

  

我与银河S的同样的问题到现在为止所有的Andr​​oid设备的I
  得到了有安装命令可用。我建立可用卷的列表   解析摩的的回应。这不是完美的,但菜刀比Android   存储API。

 字符串CMD =/系统/斌/安装;
尝试 {
   运行时室温=调用Runtime.getRuntime();
   流程PS = rt.exec(CMD);

   的BufferedReader RD =新的BufferedReader(新的InputStreamReader(ps.getInputStream()));
   字符串RS;
   而((RS = rd.readLine())!= NULL)
   {
       //查询你所需要的!
       Log.i(MOUNT_CMD,RS);
   }
   rd.close();
   ps.waitFor();
}赶上(例外五){
// ...
}
 

如果它可以插入microSD卡在角落装置,在运行过程中,你也可以尝试以下方法:

  mVolumeManagerReceiver =新的BroadcastReceiver(){
  公共无效的onReceive(上下文的背景下,意图意图){
    Log.i(MediaMounter,存储+ intent.getData());
  }
};

IntentFilter的过滤器=新的IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
filter.addDataScheme(文件);
context.registerReceiver(mVolumeManagerReceiver,过滤器);
 

The closest thing to documentation I can find having to do with file storage is this post (see below if you can't access it), but it leaves me with several questions.

I would really, really, really like a knowledgeable explanation of what paths map to what storage here, seeing as how we're supposed to hard-code them, and how precisely we're expected to access them. An actual code sample would be superlative. My best guess from messing around with this is that:

  • /sdcard-> maps to the internal eMMC slot, and access is restricted. Environment.getExternalStorageDirectory(); ... still returns this.
  • /media -> maps to the internal 8GB memory (I can write to this)
  • /data -> ?
  • ? -> maps to the optional microSD card

How can we access the external (optional, additional, the one you can pop out) sdcard, if /sdcard maps to restricted storage instead?

Now to quote the Nook developer docs:

Background There are two different partition schemes for the NOOK Color devices in market today, one with only 250MB available to applications on the /data partition and one with 4GB available to applications on the /data partition. As a result, it is imperative that applications are designed and developed in such a way as to manage space effectively. Applications which fail to do so will not be accepted for distribution via the Shop.

Area Associated Technical Recommendation or Solution if your application requires large amount of data (including but not limited to images, audio or video content), you should download those resources at runtime and store them in the larger partition of the device. If your application is going to request and store more than 100MB of data or resource you MUST abide by the the following restrictions:

Your application must clearly and explicitly state in the description provided that a large amount of data is used/delivered by the application. You MUST write your resources and data onto appropriate partition. You can detect if the device has an enlarged /data partition as follows :

StatFs stat = new StatFs("/data"); 
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount(); 
long megAvailable = bytesAvailable / 1048576; 
if (megAvailable > 1000){   
... write your resources in /data
} else {  
... write your resources on /mnt/media ... 
} 

To write data into your application's private space on /data

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE); 

Your application should NOT assume the presence of an sdcard on device, but you can test for one via a call to

Environment.getExternalStorageState(); If an SD Card is not found, your application MUST exit gracefully with a notification to the user as to the reason for the exit.

Remember, that to access the /media partition, as well as ExternalStorage you need to declare in your manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>

解决方案

First of all try the following methods:

If neither of those return you a directory where you can write to, check the following google-groups thread, and use the code provided in the last answer, which enumerates all current mount-points:

I have the same issue with Galaxy S. Until now all Android devices I
got have "mount" command available. I build a list of available volume parsing "mount" response. This is not perfect but cleaver than Android storage API.

String cmd = "/system/bin/mount"; 
try { 
   Runtime rt = Runtime.getRuntime(); 
   Process ps = rt.exec(cmd); 

   BufferedReader rd = new BufferedReader( new InputStreamReader(ps.getInputStream()) ); 
   String rs; 
   while ((rs = rd.readLine()) != null) 
   { 
       //check what you need! 
       Log.i("MOUNT_CMD", rs); 
   } 
   rd.close(); 
   ps.waitFor(); 
} catch(Exception e) { 
//...
}

If it is possible to insert the microSD card in the Nook device, while it is running, you could also try the following:

mVolumeManagerReceiver = new BroadcastReceiver() { 
  public void onReceive(Context context, Intent intent) { 
    Log.i("MediaMounter", "Storage: " + intent.getData()); 
  } 
}; 

IntentFilter filter = new IntentFilter(); 
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); 
filter.addAction(Intent.ACTION_MEDIA_REMOVED); 
filter.addDataScheme("file"); 
context.registerReceiver(mVolumeManagerReceiver, filter);

这篇关于在角落访问存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆