2011-10-11 12 views
4

與文件存儲最接近的文檔是this post(如果無法訪問,請參閱下面的內容),但這會給我留下幾個問題。在角落上訪問存儲

我真的真的很喜歡關於什麼路徑映射到這裏的存儲空間的明智解釋,看到我們應該如何對它們進行硬編碼,以及我們期望如何精確訪問它們。實際的代碼示例將是最高級的。我最好的猜測是:

  • /sdcard->映射到內部eMMC插槽,並且訪問受到限制。 Environment.getExternalStorageDirectory(); ...仍然返回這個。
  • /media - >映射到內部的8GB內存(我可以寫到這個)
  • /data - >?
  • ? - >映射到可選的microSD卡

如何訪問外部存儲設備(可選,另外可以彈出的設備)sdcard,如果/sdcard maps to restricted storage instead

我們引用的Nook開發者文檔:

背景有對市場的今天,一個可用來在/ data分區 應用程序和一個角落 顏色設備只有250MB兩種不同的分區方案4GB可用於/ data分區上的 應用程序。因此,應用程序的設計和開發勢在必行 有效地管理空間。未能這樣做的應用程序將不會被 通過商店接受分發。

領域相關技術建議或解決方案,如果你的 應用程序需要大量數據(包括但不限 於圖片,音頻或視頻內容),你應該在運行時下載這些 資源,並將它們存儲在更大的分區 設備。如果您的應用程序將請求和存儲超過 100MB的數據或資源必須由以下 限制遵守:

您的應用程序中提供了大量的數據是描述 必須清楚和明確規定由 應用程序使用/交付。您必須將您的資源和數據寫入適當的 分區。您可以檢測,如果該設備具有放大/數據 分區如下:

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 ... 
} 

在此書寫/數據

數據到應用程序的私人空間
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE); 

你的應用程序不應該承擔 存在設備上的SD卡,但可以通過呼叫測試一個 至

Environment.getExternalStorageState();如果未找到SD卡, 您的應用程序必須正常退出,並通知用戶 關於退出的原因。

記住,訪問/媒體分區,以及 ExternalStorage你需要在你的清單聲明:

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

這似乎是不可能訪問您提供的鏈接:http://nookdeveloper.zendesk.com/entries/20257971-updated-what-are-the-size -constraints-on-my-applications沒有註冊(這看起來不像一個單擊過程)。你應該在某個地方複製討論,這樣更多的人可以訪問它。 – Idolon

+0

說文字被複制。 – Turnsole

回答

0

首先請嘗試以下方法:

如果沒有那些回報你的目錄,你可以寫,檢查以下google-groups thread,並使用在最後回答中提供的代碼,其中列舉了目前所有的安裝點:

我與Galaxy S有同樣的問題。到目前爲止,所有Android設備 都得到了「安裝」命令。我構建了一個解析「安裝」響應的可用卷 的列表。這不是完美的,但切肉刀比Android 存儲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) { 
//... 
} 

如果它可以插入在Nook上設備的microSD卡,而它正在運行,你也可以嘗試以下方法:

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); 
+0

@Hydrangea你嘗試過嗎?我想知道我提到的一種解決方案是否適合你。還有一個想法:有些設備將內置的SD卡安裝到'/ sdcard/sd /'路徑上,您也可以在Nook上嘗試它。 – Idolon

+0

即將坐下來。我對這種緩慢的反應表示歉意。 – Turnsole

+0

所以,看起來我沒有時間回到今晚,但不想浪費賞金,它很快就會到期,所以它是你的。儘快回到問題。 – Turnsole

4

好了,這就是我所學到在過去幾周。

如果要寫入內部 SD卡,使用Context.getFilesDir()。它會返回您的應用程序的私人目錄。您無法在內部閃存(又名「/ data」)上創建自己的目錄。除了應用程序分配的文件夾外,您無權寫入任何地方。假設有兩個內部分區,「/ data」和「/ media」,但我無法獲得「/ media」來拯救我的生命。

如果存在閃存「/ sdcard」,則可以使用外部閃存。這是您可以從設備中彈出的卡。有兩種方法去了解這一點:分配給您的應用程序文件夾中

  • 店裏的東西(所以它會被刪除 當你的應用被卸載)。您可以使用 Context.getExternalFilesDir()找到該文件夾​​。
  • 將東西存儲在「/ sdcard/foo/bar」下的某個硬編碼路徑中,或存儲在Environment.getExternalStorageDirectory()/whatever中的任何位置。

This post,由B &Ñ代表(我在我的問題提及)原來是有點紅鯡魚,「/ SD卡」不映射到的eMMC槽,並且我不知道「我們將SD卡映射到我們的內部eMMC」是什麼意思。

This B&N post說,「/ media」是內部的,但即使我擁有適當的清單權限,我也無法寫入它...所以請進入圖。

這是我的測試設備的擷取畫面,顯示是什麼,是不是訪問: enter image description here

操作的代碼(注意,文件實用程序未包括在默認情況下,SDK,它是從組織.apache.commons.io LIB):

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TextView dataView = (TextView) findViewById(R.id.data); 
    dataView.setText(testIt("/data")); 

    TextView mediaView = (TextView) findViewById(R.id.media); 
    mediaView.setText(testIt("/media")); 

    TextView mntMediaView = (TextView) findViewById(R.id.mntMedia); 
    mntMediaView.setText(testIt("/mnt/media")); 

try { 
     File fd = this.getFilesDir(); 
     if(fd != null) { 
      TextView fdView = (TextView) findViewById(R.id.filesDir); 
      fdView.setText("getFilesDir(): " + testIt(fd.toString())); 
     } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

try { 
     File efd = this.getExternalFilesDir(null); 
     if(efd != null) { 
      TextView efdView = (TextView) findViewById(R.id.externalFilesDir); 
      efdView.setText("getExternalFilesDir(): " + testIt(efd.toString())); 
     } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

try { 
    File esd = Environment.getExternalStorageDirectory(); 
     if(esd != null) { 
      TextView esdView = (TextView) findViewById(R.id.externalStorageDirectory); 
      esdView.setText("getExternalStorageDirectory(): " + testIt(esd.toString())); 
     } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

try { 
    File espd = Environment.getExternalStoragePublicDirectory(null); 
     if(espd != null) { 
      TextView espdView = (TextView) findViewById(R.id.externalStoragePublicDirectory); 
      espdView.setText("getExternalStoragePublicDirectory(): " + testIt(espd.toString())); 
     } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
} 

public String testIt(String dir){ 
    StatFs stat = new StatFs(dir); 
     long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount(); 
     long megAvailable = bytesAvailable/FileUtils.ONE_MB; 
     File dirFile = new File(dir + "/test/"); 
     dirFile.mkdir(); 

     return dir + "/test \n canRead() " + dirFile.canRead() + ", \n canWrite() " + dirFile.canWrite() + " with " + megAvailable + "MB available"; 
}