1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:47:52 +08:00

Use ContentResolver for getting filename.

This commit is contained in:
Lucas A 2020-12-05 11:50:08 +01:00
parent dd21de0cd5
commit 280abdc473

View File

@ -1,12 +1,12 @@
// 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.
using System.Linq;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Provider;
using Android.Views;
using osu.Framework.Android;
@ -39,11 +39,14 @@ namespace osu.Android
{
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);
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
game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename)));
game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column))));
}
base.OnNewIntent(intent);