无法在 Android 上使用 FileDataStoreFactory 为 Youtube Data api v3 创建目录

Unable to create directory using FileDataStoreFactory on Android for Youtube Data api v3

我正在尝试在下面的行中使用 Youtube Data API for my android project. And I guess API Client Library Java now supports Android. I'm following these samples. In my Auth.java :

private static final String CREDENTIALS_DIRECTORY = ".oauth-credentials";
File dataDirectory = new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY);
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(dataDirectory);

我遇到了以下错误。

unable to create directory: /.oauth-credentials

我尝试使用以下代码在 SD 卡中创建一个目录:

Environment.getExternalStorageDirectory().getAbsolutePath()

并授予权限:

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

但我仍然无法创建目录。

我正在使用的库的其他版本:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.apis:google-api-services-youtube:v3-rev162-1.20.0'
    compile 'com.google.oauth-client:google-oauth-client-java6:1.20.0'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
}

试试这个: File dataDirectory = new File(getContext().getFilesDir(), CREDENTIALS_DIRECTORY);