2012-06-22 174 views
0
private Context mContext; 


public Upload(Context context, DropboxAPI<?> api, String dropboxPath) 
    { 

     // We set the context this way so we don't accidentally leak activities 
     mContext = context.getApplicationContext(); 

     String outPath = mContext.getExternalStorageDirectory(null).getAbsolutePath() + "/" +"a1.jpg"; 

錯誤:方法getExternalStorageDirectory()是未定義的類型上下文getExternalStorageDirectory()不被識別

String outPath = mContext.getExternalFilesDir("mnt/sdcard").getAbsolutePath() + "/" +"a1.jpg"; 

工作正常..

+0

其靜態的環境類沒有上下文http://stackoverflow.com/questions/5453708/android-how-to-use-environment- getexternalstoragedirectory – Slartibartfast

回答

1

使用

String outPath = Environment.getExternalStorageDirectory(null).getAbsolutePath() + "/" +"a1.jpg"; 

,而不是

String outPath = mContext.getExternalStorageDirectory(null).getAbsolutePath() + "/" +"a1.jpg"; 
3

getExternalStorageDirectory()沒有爲語境類型定義的。它在Environment類中定義,它是一種靜態方法。