/// <summary>
        /// This is a sample to demonstrate how to query the media database to retrieve media content
        /// For more information about media content, see https://docs.tizen.org/application/dotnet/guides/multimedia/media-content
        /// </summary>
        public static async Task AccessMediaContentSampleAsync()
        {
            // Ask the user for the permission
            PrivacyPermissionStatus permission = await PrivacyPermissionService.RequestAsync(PrivacyPrivilege.MediaStorage);

            if (permission != PrivacyPermissionStatus.Granted)
            {
                // TODO: The permission is not granted
                return;
            }

            using (var database = new MediaDatabase())
            {
                try
                {
                    // Establish a connection to the media database.
                    database.Connect();

                    // Note that the system automactically scans storage and adds media files to the database.
                    // To request the system to scan a directory explicitly, use MediaDatabase.ScanFolderAsync()
                    // await database.ScanFolderAsync(path);

                    // Query the database to retrieve media files and get a Reader containing results.
                    var command = new MediaInfoCommand(database);
                    var reader  = command.SelectMedia(new SelectArguments()
                    {
                        FilterExpression = $"{MediaInfoColumns.MediaType}={(int)MediaType.Music}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Sound}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Video}"
                    });

                    // Iterate over media data in the results.
                    while (reader.Read())
                    {
                        var media = reader.Current;

                        // TODO: Insert code to do something with a media file.
                        // Note that your app needs adequate permissions to perform operations on the file
                        Logger.Info($"{media.MediaType}: {media.Title}");
                    }
                }
                catch (MediaDatabaseException)
                {
                    // TODO: Handle exception as appropriate to your scenario.
                }
            }
        }
        public static async Task WriteFileToSharedStorageSampleAsync()
        {
            // Ask the user to grant the privacy permissions at runtime
            var permission = await PrivacyPermissionService.RequestAsync(PrivacyPrivilege.MediaStorage);

            if (permission != PrivacyPermissionStatus.Granted)
            {
                // The permission is not granted
                return;
            }

            if (SharedStorageService.Writable)
            {
                // Store a file in public directory so that other apps can access the file
                var directory = SharedStorageService.GetDirectory(Tizen.System.DirectoryType.Downloads);
                var path      = Path.Combine(directory, "sample.txt");
                File.WriteAllText(path, "Hello World!");
            }
        }
Beispiel #3
0
        public static async Task RequestPrivacyPermissionSampleAsync()
        {
            // Note that privileges must be declared manually in manifest
            // More details at https://docs.tizen.org/application/dotnet/guides/security/requesting-permissions

            // Check whether the app has the permission
            if (PrivacyPermissionService.Check(PrivacyPrivilege.MediaStorage) == PrivacyPermissionStatus.Granted)
            {
                // the permission has already been granted
                return;
            }

            // Ask the user for the permission
            PrivacyPermissionStatus permission = await PrivacyPermissionService.RequestAsync(PrivacyPrivilege.MediaStorage);

            if (permission != PrivacyPermissionStatus.Granted)
            {
                // The permission is not granted
            }
        }