Use ContentResolver for getting filename.

This commit is contained in:
Lucas A 2020-12-05 11:50:08 +01:00
parent dd21de0cd5
commit 280abdc473
1 changed files with 6 additions and 3 deletions

View File

@ -1,12 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.Content.PM; using Android.Content.PM;
using Android.OS; using Android.OS;
using Android.Provider;
using Android.Views; using Android.Views;
using osu.Framework.Android; using osu.Framework.Android;
@ -39,11 +39,14 @@ protected override void OnNewIntent(Intent intent)
{ {
if (intent.Action == Intent.ActionView) if (intent.Action == Intent.ActionView)
{ {
var filename = intent.Data.Path.Split('/').Last(); var cursor = ContentResolver.Query(intent.Data, null, null, null);
var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName);
cursor.MoveToFirst();
var stream = ContentResolver.OpenInputStream(intent.Data); var stream = ContentResolver.OpenInputStream(intent.Data);
if (stream != null) if (stream != null)
// intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import
game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename))); game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column))));
} }
base.OnNewIntent(intent); base.OnNewIntent(intent);