コード例 #1
0
            /// <summary>
            /// verschiebt das Objekt (API level 14)
            /// </summary>
            /// <param name="storagenamesrc">z.B. "primary" oder "19F4-0903"</param>
            /// <param name="volpathsrc">abs. Pfad im Volume</param>
            /// <param name="storagenamenewparent">Zielvolume</param>
            /// <param name="volpathnewparent">Zielverzeichnis</param>
            /// <returns></returns>
            public bool Move(string storagenamesrc, string volpathsrc, string storagenamenewparent, string volpathnewparent)
            {
                /*
                 * DocumentFile srcdoc = GetExistingDocumentFile(volpathsrc);
                 * DocumentFile dstdoc = GetDocumentFile(volpathdst, true); // Zielverzeichnis (wird notfalls erzeugt)
                 * Android.Net.Uri srcuri = srcdoc.Uri;
                 * Android.Net.Uri srcparenturi = srcdoc.ParentFile.Uri;
                 * Android.Net.Uri dstparenturi = dstdoc.Uri;
                 */
                DocumentFile dstdoc = GetDocumentFile(storagenamesrc, volpathnewparent, true); // Zielverzeichnis (wird notfalls erzeugt)

                /*
                 * public static Uri moveDocument (ContentResolver content,
                 *                              Uri sourceDocumentUri,            document with FLAG_SUPPORTS_MOVE
                 *                              Uri sourceParentDocumentUri,      parent document of the document to move
                 *                              Uri targetParentDocumentUri)      document which will become a new parent of the source document
                 * return the moved document, or null if failed.
                 *
                 * Moves the given document under a new parent.
                 * Added in API level 24; Deprecated in API level Q
                 *
                 * neu:
                 * ContentProviderClient provclient = Activity.ContentResolver.AcquireUnstableContentProviderClient(srcdoc.Uri.Authority);
                 * DocumentsContract.MoveDocument(provclient, srcdoc.Uri, srcparenturi.Uri, dstparentdoc.Uri);
                 *
                 *    intern:
                 *    Bundle inbundle = new Bundle();
                 *    inbundle.PutParcelable(DocumentsContract.EXTRA_URI, srcdoc.Uri);                    "uri"
                 *    inbundle.PutParcelable(DocumentsContract.EXTRA_PARENT_URI, srcparenturi.Uri);       "parentUri"
                 *    inbundle.PutParcelable(DocumentsContract.EXTRA_TARGET_URI, dstparentdoc.Uri);       "android.content.extra.TARGET_URI"
                 *    Bundle outbundle = provclient.Call(METHOD_MOVE_DOCUMENT, null, inbundle);           "android:moveDocument"
                 *    return outbundle.GetParcelable(DocumentsContract.EXTRA_URI);                        "uri"
                 */
                global::Android.Net.Uri newuri = DocumentsContract.MoveDocument(Activity.ContentResolver,
                                                                                GetDocumentUriUsingTree(storagenamesrc, volpathsrc),
                                                                                GetDocumentUriUsingTree(storagenamenewparent, Path.GetDirectoryName(volpathsrc)),
                                                                                dstdoc.Uri);

                System.Diagnostics.Debug.WriteLine("AndroidMove(" + storagenamesrc + ", " + volpathsrc + ", " + storagenamenewparent + ", " + volpathnewparent + ") = " + (newuri != null).ToString());

                return(newuri != null);
            }