android/Context: add GetExternalFilesDir()

This commit is contained in:
Max Kellermann 2021-08-24 21:58:09 +02:00
parent 811860c3b4
commit 2dba06dc34
2 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,25 @@
#include "AudioManager.hxx"
AllocatedPath
Context::GetExternalFilesDir(JNIEnv *env, const char *_type) noexcept
{
assert(_type != nullptr);
Java::Class cls{env, env->GetObjectClass(Get())};
jmethodID method = env->GetMethodID(cls, "getExternalFilesDir",
"(Ljava/lang/String;)Ljava/io/File;");
assert(method);
Java::String type{env, _type};
jobject file = env->CallObjectMethod(Get(), method, type.Get());
if (Java::DiscardException(env) || file == nullptr)
return nullptr;
return Java::File::ToAbsolutePath(env, file);
}
AllocatedPath
Context::GetCacheDir(JNIEnv *env) const noexcept
{

View File

@ -30,6 +30,10 @@ public:
Context(JNIEnv *env, jobject obj) noexcept
:Java::GlobalObject(env, obj) {}
[[gnu::pure]]
AllocatedPath GetExternalFilesDir(JNIEnv *env,
const char *type) noexcept;
[[gnu::pure]]
AllocatedPath GetCacheDir(JNIEnv *env) const noexcept;