public override ParcelFileDescriptor OpenFile(Android.Net.Uri uri, String mode) { const string logTag = ClassName + " - openFile"; Log.Verbose(logTag, "Called with uri: '" + uri + "'." + uri.LastPathSegment); if (uri.ToString().StartsWith("content://" + Authority)) { // The desired file name is specified by the last segment of the // path // E.g. // 'content://keepass2android.provider/Test.txt' // Take this and build the path to the file String fileLocation = Context.CacheDir + File.Separator + AttachmentCacheSubDir + File.Separator + uri.LastPathSegment; // Create & return a ParcelFileDescriptor pointing to the file // Note: I don't care what mode they ask for - they're only getting // read only ParcelFileDescriptor pfd = ParcelFileDescriptor.Open(new File( fileLocation), ParcelFileMode.ReadOnly); return pfd; } Log.Verbose(logTag, "Unsupported uri: '" + uri + "'."); throw new FileNotFoundException("Unsupported uri: " + uri.ToString()); }
public bool OnError(MediaPlayer mp, Android.Media.MediaError e, int s) { #if DEBUG Console.WriteLine("{0}", e.ToString()); #endif return true; }
public static async Task<Android.Net.Uri> DownloadDocument (Context ctx, Android.Net.Uri uriToDownload, string saveFilePath, IProgress<DownloadBytesProgress> progessReporter) { int receivedBytes = 0; int totalBytes = 0; using (var assetFileDescriptor = ctx.ContentResolver.OpenAssetFileDescriptor (uriToDownload, "r")) using (var fileOutputStream = new Java.IO.FileOutputStream (saveFilePath)) using (var inputStream = assetFileDescriptor.CreateInputStream ()) { var buffer = new byte [BufferSize]; totalBytes = (int)assetFileDescriptor.Length; for (;;) { var bytesRead = await inputStream.ReadAsync (buffer, 0, buffer.Length); if (bytesRead == 0) { await Task.Yield(); break; } await fileOutputStream.WriteAsync (buffer, 0, buffer.Length); receivedBytes += bytesRead; if (progessReporter != null) { var args = new DownloadBytesProgress (uriToDownload.ToString (), saveFilePath, receivedBytes, totalBytes); progessReporter.Report(args); } } inputStream.Close (); fileOutputStream.Close (); } var file = new Java.IO.File (saveFilePath); var docUri = Android.Net.Uri.FromFile (file); return docUri; }
public override ParcelFileDescriptor OpenFile(Android.Net.Uri uri, string mode) { string fileName = uri.ToString ().Substring (CONTENT_URI.ToString ().Length); System.Console.WriteLine (fileName + " - File to open in external app"); if (System.IO.File.Exists (fileName)) { return ParcelFileDescriptor.Open(new Java.IO.File(fileName), ParcelFileMode.ReadOnly); } return null; }
void ShowPdfDocument (Android.Net.Uri docUri) { // Customize thumbnailBar color defaults var thumbnailBarThemeConfiguration = new ThumbnailBarThemeConfiguration.Builder (this) .SetBackgroundColor (Android.Graphics.Color.Argb (255, 52, 152, 219)) .SetThumbnailBorderColor (Android.Graphics.Color.Argb (255, 44, 62, 80)) .Build (); // Show Document using PSPDFKit activity var pspdfkitConfiguration = new PSPDFActivityConfiguration.Builder (ApplicationContext, yourLicenseKey) .ScrollDirection (PageScrollDirection.Horizontal) .ShowPageNumberOverlay () .ShowThumbnailGrid () .ShowThumbnailBar () .ThumbnailBarThemeConfiguration (thumbnailBarThemeConfiguration) .Build (); if (!PSPDFKitGlobal.IsOpenableUri (this, docUri)) ShowError ("This document uri cannot be opened \n " + docUri.ToString ()); else PSPDFAppCompatActivity.ShowDocument (this, docUri, pspdfkitConfiguration); }
private string GetPathToImage(Android.Net.Uri uri) { string doc_id = ""; try{ using (var c1 = Application.Context.ContentResolver.Query (uri, null, null, null, null)) { c1.MoveToFirst (); String document_id = c1.GetString (0); doc_id = document_id.Substring (document_id.LastIndexOf (":") + 1); } }catch{ Log.Debug ("GetPathToImage","Excepcion! El content es File"); Android.Content.Context context = Android.App.Application.Context; try{ String[] proj = { MediaStore.MediaColumns.Data }; Log.Debug ("GetPathToImage","Y la URI? "+uri.ToString()); // var c1 = context.ContentResolver.Query (uri, proj, null, null, null) var loader = new CursorLoader (context, uri, proj, null, null, null); var c1 = (ICursor)loader.LoadInBackground(); if(c1==null){ Log.Debug ("GetPathToImage","Sigue siendo nulo-"); } c1.MoveToFirst (); Log.Debug ("GetPathToImage","Pasamos?"); String document_id = c1.GetString (0); doc_id = document_id.Substring (document_id.LastIndexOf (":") + 1); Log.Debug ("GetPathToImage","Y bien? "+doc_id); } catch(Exception ex){ Log.Debug ("GetPathToImage","Excepcion! "+ex); } } string path = null; // The projection contains the columns we want to return in our query. string selection = Android.Provider.MediaStore.Images.Media.InterfaceConsts.Id + " =? "; using (var cursor = Application.Context.ContentResolver.Query(Android.Provider.MediaStore.Images.Media.ExternalContentUri, null, selection, new string[] {doc_id}, null)) { if (cursor == null) return path; var columnIndex = cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data); cursor.MoveToFirst(); path = cursor.GetString(columnIndex); //cursor.Close (); } return path; }
public override bool OnContextItemSelected (Android.Views.IMenuItem item) { //Note how this callback is using the fully-qualified class name Toast.MakeText (this, "Got click: " + item.ToString (), ToastLength.Short).Show (); return true; }
public bool OnError(Android.Media.MediaPlayer mp, Android.Media.MediaError what, int extra) { this.RootPlayer.FireError (what.ToString ()); return true; }
public bool OnError (Android.Media.MediaPlayer mp, Android.Media.MediaError what, int extra) { this.ParentElement.HasError = true; this.ParentElement.ErrorMessage = what.ToString (); this._HasEnded = true; // true handle, false allow pass return false; }
public override string GetType (Android.Net.Uri uri) { var mimeType = MimeTypeHelper.GetMimeType(uri.ToString()); return mimeType; }
public void EmptyToString() { Android A1 = new Android(123, "blabla"); Assert.IsNotEmpty(A1.ToString()); }
void ShowPdfDocument(Android.Net.Uri docUri, string filename) { // Customize thumbnailBar color defaults var thumbnailBarThemeConfiguration = new ThumbnailBarThemeConfiguration.Builder (Forms.Context) .SetBackgroundColor (Android.Graphics.Color.Argb (255, 52, 152, 219)) .SetThumbnailBorderColor (Android.Graphics.Color.Argb (255, 44, 62, 80)) .Build (); // Show Document using PSPDFKit activity var pspdfkitConfiguration = new PSPDFActivityConfiguration.Builder (Forms.Context, MainActivity.LicenseKey) .ScrollDirection (PageScrollDirection.Horizontal) .ShowPageNumberOverlay () .ShowThumbnailGrid () .ShowThumbnailBar () .ThumbnailBarThemeConfiguration (thumbnailBarThemeConfiguration) .Build (); if (!PSPDFKitGlobal.IsOpenableUri (Forms.Context, docUri)) { ShowError ("This document uri cannot be opened \n " + docUri.ToString ()); } else { try{ PSPDFAppCompatActivity.ShowDocument (Forms.Context, docUri, pspdfkitConfiguration); } catch(Exception ex){ var error = ex.StackTrace; } } }