Search code examples
androidmobile-application

getExternalStorageDirectory() is not recognized


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";

Error:The method getExternalStorageDirectory() is undefined for the type Context

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

works fine..


Solution

  • use

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

    instead of

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