iOS
iOSãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ããã¡ã€ã«ã·ã¹ãã ã®æŠå¿µã¯ãŠãŒã¶ãŒã«å¯ŸããŠé ãããŠããããã¡ã€ã«ãšã®å¯Ÿè©±ã¯ã¢ããªã±ãŒã·ã§ã³èªäœã«ãã£ãŠå®è¡ãããã¢ããªã±ãŒã·ã§ã³ãã£ã¬ã¯ããªã«ãããã¡ã€ã«ãšã®ã¿å®è¡ãããŸãã ãã¡ã€ã«ãã¢ããªã±ãŒã·ã§ã³ãã£ã¬ã¯ããªã«ã€ã³ããŒãããã«ã¯ãiTunesãã¡ã€ã«å ±æã䜿çšããããã¢ããªã±ãŒã·ã§ã³ã®ãã¡ã€ã«ã¿ã€ããç»é²ããæ¹æ³ãããã€ããããŸãã
iTunesãã¡ã€ã«å ±æã䜿çšããŠããå Žåãã¢ããªã±ãŒã·ã§ã³ã¯iTunesã®ãäžè¬ãã¡ã€ã«ãã»ã¯ã·ã§ã³ã«è¡šç€ºãããã³ã³ãã¥ãŒã¿ãŒããã¢ããªã±ãŒã·ã§ã³ã«ãã¡ã€ã«ãè¿œå ã§ããŸãã ãã®æ¹æ³ã§è¿œå ããããã¡ã€ã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®/ Documentsãã£ã¬ã¯ããªã«åé¡ãããŸãã
ã¢ããªã±ãŒã·ã§ã³èªäœã¯ãæ°ãããã¡ã€ã«çšã«ãã®ãã£ã¬ã¯ããªãå¶åŸ¡ããå¿ èŠããããŸãã ãŸããå®éã«ã¯ãiTunesãã¡ã€ã«å ±æã¯ãŠãŒã¶ãŒã«ããã¥ã¡ã³ããžã®çŽæ¥ã¢ã¯ã»ã¹ãæäŸããããããã®ãã£ã¬ã¯ããªå ã®ãã¡ã€ã«ã®ååãå€æŽãããããã€ã§ãåé€ãããã§ããããšãå¿ããªãã§ãã ããã
iTunesãã¡ã€ã«å ±æã䜿çšããã«ã¯ã UIFileSharingEnabled ïŒã¢ããªã±ãŒã·ã§ã³ãiTunesãã¡ã€ã«å ±æããµããŒãããŠããïŒãã©ã°ãinfo.plistã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã«ã«è¿œå ããå¿ èŠããããŸãã
<key>UIFileSharingEnabled</key> <true/>
ãã¡ã€ã«ã®çš®é¡ãç»é²ããå Žåãæšæºã®ãã¢ããªã±ãŒã·ã§ã³ã§éãããã€ã¢ãã°ããã¯ã¹ãã¯ãªãã¯ãããšãã¢ããªã±ãŒã·ã§ã³ãéžæãªã¹ãã«è¡šç€ºãããŠãã¡ã€ã«ãéããŸãã
ãã®æ¹æ³ã§ãã¡ã€ã«ãéããšããã®ã³ããŒã/ Documents / Inboxãã£ã¬ã¯ããªã«é 眮ãããã¢ããªã±ãŒã·ã§ã³ã¯applicationïŒopenURLïŒsourceApplicationïŒannotationïŒ protocol UIApplicationDelegate methodãåŒã³åºããŸãã ãã®ã¡ãœããã§ã¯ãéããã¡ã€ã«ã®URLãæž¡ãããŸãã
/ Documents / Inboxãã£ã¬ã¯ããªå ã®ãã¡ã€ã«ã¯èªã¿åãããã³åé€ã§ããŸãããå€æŽããããšã¯ã§ããŸããã ãã¡ã€ã«ãå€æŽããã«ã¯ãå¥ã®ãã£ã¬ã¯ããªãããšãã°/ Documentsã«ç§»åããå¿ èŠããããŸãã
ãã®æ¹æ³ã§ãã¡ã€ã«ãã€ã³ããŒãããã«ã¯ã info.plistã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã«ã«CFBundleDocumentTypes ïŒããã¥ã¡ã³ãã¿ã€ãïŒããŒãè¿œå ããå¿ èŠããããŸãã ãã®å€ã¯é åã§ããããã®åèŠçŽ ã¯ãã¢ããªã±ãŒã·ã§ã³ã§ãµããŒããããåã¿ã€ãã®ããã¥ã¡ã³ããèšè¿°ããããã«äœ¿çšãããèŸæžã§ãã å¯èœãªæããããšãã®æå³ã®å®å šãªèª¬æã¯ãããã¥ã¡ã³ãã«ãããŸãïŒ developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
ãã¡ã€ã«ã®çš®é¡ãå¶éããŸããã§ããããä»»æã®ãã¡ã€ã«ãã€ã³ããŒãã§ããããã«ããŸããã åæã«Info.plistã¯æ¬¡ã®ããã«ãªããŸãã
<key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>All files</string> <key>CFBundleTypeRole</key> <string>Viewer</string> <key>LSHandlerRank</key> <string>Alternate</string> <key>LSItemContentTypes</key> <array> <string>public.data</string> </array> </dict> </array>
ã¢ããªã±ãŒã·ã§ã³ãããã¡ã€ã«ããšã¯ã¹ããŒãããã«ã¯ãåããã¢ããªã±ãŒã·ã§ã³ã§éãããã€ã¢ãã°ããã¯ã¹ã䜿çšããã UIDocumentInteractionControllerãåæåãããŸãã ãã¡ã€ã«ãéãããã®ã¢ããªã±ãŒã·ã§ã³ã®ãªã¹ããããã«éãããããã¡ã€ã«ãéãããã®ã¢ããªã±ãŒã·ã§ã³ã®ãªã¹ããéãããããã¡ã€ã«ã®å°å·ãã¡ãŒã«ã§ã®éä¿¡ãªã©ã®æšæºãµãŒãã¹ãéãããšãã§ããŸãã ãŸããçµã¿èŸŒã¿ã®ãã¬ãã¥ãŒã¢ã§ãã¡ã€ã«ãéãããšãã§ããŸãããããããå¥ã®ã¢ããªã±ãŒã·ã§ã³ã§ãã¡ã€ã«ãéãããã®ãã¿ã³ã䜿çšã§ããŸãã
Android
Androidã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã¯ãã©ã€ããŒãã¢ããªã±ãŒã·ã§ã³ãã£ã¬ã¯ããªå ã®ãã¡ã€ã«ä»¥å€ã®ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ã§ããŸãã
ãã¡ã€ã«ã®éžæãé»åã¡ãŒã«ã®éä¿¡ããã©ãŠã¶ã§ãªã³ã¯ãéããªã©ã®æäœãå®è¡ããã«ã¯ãã€ã³ãã³ãã䜿çšãããŸãã
ãã¡ã€ã«ã·ã¹ãã ãããã¡ã€ã«ãéžæããã«ã¯ã ACTION_GET_CONTENTã¢ã¯ã·ã§ã³ã䜿çšããå¿ èŠããããŸãã
setTypeïŒïŒã¡ãœããã䜿çšããŠãéžæå¯èœãªãã¡ã€ã«ã¿ã€ããæå®ã§ããŸãã ããšãã°ãæå®ããå Žå
setTypeïŒâ audio / mp3âïŒ ããã¡ã€ã«ã衚瀺ããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãæ¡åŒµåã.mp3ã®ãã¡ã€ã«ã®ã¿ã衚瀺ãããããã¹ãŠã®ãã¡ã€ã«ã衚瀺ãããããã«â * / *âãæå®ããŸãã ãã®åŸã startActivityForResultïŒïŒã¡ãœãããåŒã³åºããŸãããã®ã¡ãœããã§ã¯ããã©ã¡ãŒã¿ãŒãšããŠIntent.createChooserïŒïŒãæž¡ããã¢ããªã±ãŒã·ã§ã³éžæãã€ã¢ãã°ãäœæããŸãã
ãŸãããããã§ã¹ããã¡ã€ã«ã§ãå¿ èŠãªæš©éãè¿œå ããå¿ èŠããããŸãã
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
ãã¡ã€ã«ãããŒãžã£ãŒã§ãã¡ã€ã«ãéžæããåŸã onActivityResultã¡ãœããïŒint requestCodeãint resultCodeãIntent dataïŒãååŸããŸããããã§ã ããŒã¿ã¯ãã¡ã€ã«ã®Uriã§ãã
ãµãŒãã¹ãããã¡ã€ã«ãéãã«ã¯ã ACTION_VIEWã¢ã¯ã·ã§ã³ã䜿çšããŸãã ãã¡ã€ã«ãéãããã®ã¢ããªã±ãŒã·ã§ã³ã¯ã FileOpenã¯ã©ã¹ïŒStackOverFlowã®æ¡åŒµéšåã«ããããããã«ããçŽãïŒã䜿çšããŠéžæãããæœåšçãªæ¡åŒµåã«åŸã£ãŠãéãããšããŠãããã¡ã€ã«ã®çš®é¡ã確èªããŸãã
Fileopen.class
public class FileOpen { public static void openFile(Context context, File url) throws IOException { File file = url; Uri uri = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); if (url.toString().contains(".doc") || url.toString().contains(".docx") || url.toString().contains(".odt")) { // Word document intent.setDataAndType(uri, "application/msword"); } else if (url.toString().contains(".pdf")) { // PDF file intent.setDataAndType(uri, "application/pdf"); } else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) { // Powerpoint file intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) { // Excel file intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (url.toString().contains(".zip") || url.toString().contains(".rar")) { // ZIP Files intent.setDataAndType(uri, "application/zip"); } else if (url.toString().contains(".rtf")) { // RTF file intent.setDataAndType(uri, "application/rtf"); } else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) { // WAV audio file intent.setDataAndType(uri, "audio/x-wav"); } else if (url.toString().contains(".gif")) { // GIF file intent.setDataAndType(uri, "image/gif"); } else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg") || url.toString().contains(".png")) { // JPG file intent.setDataAndType(uri, "image/jpeg"); } else if (url.toString().contains(".txt")) { // Text file intent.setDataAndType(uri, "text/plain"); } else if (url.toString().contains(".3gp") || url.toString().contains(".mpg") || url.toString().contains(".mpeg") || url.toString().contains(".mpe") || url.toString().contains(".mp4") || url.toString().contains(".avi")) { // Video files intent.setDataAndType(uri, "video/*"); } else { intent.setDataAndType(uri, "*/*"); } intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }
äžèŽãããã®ãèŠã€ãããšãã¯ã setDataAndTypeïŒïŒã¡ãœããã䜿çšããŠãéä¿¡ããããŒã¿ã®Uriããã³MIMEã¿ã€ããæå®ããŸãã
ãã¡ã€ã«ã«åœç€Ÿãèæ ®ããŠããªã圢åŒãå«ãŸããŠããå Žåã setDataAndTypeïŒïŒã§ã¿ã€ããšããŠã* / *ã ãæå®ããŸãã ãããã£ãŠãã·ã¹ãã ã¯ããã€ã¹ã«ã€ã³ã¹ããŒã«ãããŠãããã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã衚瀺ãããã¡ã€ã«ãéã察象ãèªåã§éžæã§ããããã«ããŸãã
Windows Phone
Windowsã¹ãã¢/ Windows Phoneã¹ãã¢ã®ãŠãããŒãµã«ã¢ããªã±ãŒã·ã§ã³ã¯ãå°ãªããšãã·ã¹ãã ãã©ã«ããŒã§ã¯ãªãããã¡ã€ã«ã·ã¹ãã ãã»ãŒå®å šã«éããŸãã OpenFilePickerã¯ã©ã¹ã䜿çšãããšãããã€ã¹ã¡ã¢ãªãå€éšã¡ãã£ã¢ãšããã€ã¹ãã¯ã©ãŠãïŒé©åãªã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ãããŠããå ŽåïŒã®ä»»æã®ãœãŒã¹ããä»»æã®ãã©ãããã©ãŒã ã§ãã¡ã€ã«ãéãããšãã§ããŸãã ãã®ç¹ã§ããããã®ããã€ã¹ã§ãã¡ã€ã«ãéãããšã«åé¡ã¯ãããŸãããæšæºã¯ã©ã¹ã§ã¯ããã¡ã€ã«éžæã¡ãã¥ãŒããåçãæ®ãããšãã§ããŸããããã¯éåžžã«äŸ¿å©ã§ãã
æšæºã®ãã¡ã€ã«éžæãã€ã¢ãã°ãããã¡ã€ã«ãéãã«ã¯ãOpenFilePickerã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããããã€ãã®ãã©ã¡ãŒã¿ãŒã§åæåããå¿ èŠããããŸãã
List<string> .FileTypeFilter
-èš±å¯ããããã¡ã€ã«æ¡åŒµåã®ã³ã¬ã¯ã·ã§ã³ïŒãã¡ã€ã«ãéžæã§ããããã«ããã«ã¯ããšã³ããªã*ããè¿œå ããå¿
èŠããããŸãïŒã
-ãã®åæåã«ããããã€ã¢ãã°ã§æåã«éãå Žæãæå®ã§ããŸãïŒäŸïŒPickerLocationId.ComputerFolderïŒãPickerLocationId .SuggestedStartLocation
-ãã¡ã€ã«è¡šç€ºã®ã¿ã€ãïŒãªã¹ããŸãã¯ã°ãªããïŒãéžæã§ããŸããPickerViewMode .ViewMode
Windows 8.1ãšWindows Phone 8.1ã®ãã¡ã€ã«éžæãã€ã¢ãã°ã®åŒã³åºãã¯ããŠãããŒãµã«APIã«ãé¢ãããç°ãªããŸãïŒãåãã®ãšããã100ïŒ ãŠãããŒãµã«ã§ã¯ãããŸããïŒã
Windows 8.1ã¢ããªã±ãŒã·ã§ã³ã®å Žåã1ã€ãŸãã¯è€æ°ã®ãã¡ã€ã«ãéžæããå¿ èŠããããã©ããã«å¿ããŠã .PickMultipleFilesAsyncïŒïŒãŸãã¯.PickSingleFileAsyncïŒïŒã¡ãœãããåŒã³åºãå¿ èŠããããŸãã ãããã®ã¡ãœããã¯ãããããIReadOnlyList <StorageFile>ããã³StorageFileãè¿ããŸãïŒå³å¯ã«ã¯ãTaskãè¿ããããasync / awaitã䜿çšããå¿ èŠããããŸãïŒã
Windows Phone 8.1ã®å Žåãäºæ ã¯ããå°ãè€éã§ãã åæ§ã®ã¡ãœããã¯.PickMultipleFilesAndContinueïŒïŒããã³.PickSingleFileAndContinueïŒïŒãšåŒã°ããŸãã ã©ã¡ãã®ã¡ãœãããäœãè¿ããªãïŒvoidïŒãããã€ã¢ãã°ã§ãã¡ã€ã«ãéžæããåŸã IFileOpenPickerContinuableã€ã³ã¿ãŒãã§ã€ã¹ã®ã¡ã³ããŒã§ããContinueFileOpenPickerïŒïŒã¡ãœãããåŒã³åºãããã ãã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯æšæºAPIã«ã¯çµã¿èŸŒãŸããŠããŸãããã ContinuationManagerã¯ã©ã¹ã§äœ¿çšã§ããŸãã * AndContinueïŒïŒã¡ãœãããåŒã³åºããåŸãäœæ¥ãââç¶è¡ããæ¹æ³ã«ã€ããŠã¯ã ContinuationManagerã¯ã©ã¹ãããŠã³ããŒãããŠãã ãã ã ãã®ãããæ瀺ã«åŸã£ãŠContnuationManagerã¯ã©ã¹ããããžã§ã¯ãã«è¿œå ããåŸã .PickMultipleFilesAsync ïŒïŒãŸãã¯.PickSingleFileAsyncïŒïŒã¡ãœããã®åŒã³åºã å ã®ã¯ã©ã¹ãç¶æ¿ãã IFileOpenPickerContinuableã€ã³ã¿ãŒãã§ã€ã¹ããç¶æ¿ããå¿ èŠããããŸãã 次ã«ã void ContinueFileOpenPickerïŒFileOpenPickerContinuationEventArgs argsïŒã¡ãœãããå®è£ ããå¿ èŠããããŸããargs.Filesã«ã¯StorageFileãªããžã§ã¯ãã®ã³ã¬ã¯ã·ã§ã³ãå«ãŸããŸãã
ãµãŒãã¹ãããã¡ã€ã«ãéãã«ã¯ããã¡ã€ã«ãã¢ããªã±ãŒã·ã§ã³ã®å éšãã©ã«ããŒã®ãã£ã¹ã¯ã«ä¿åãã Launcherã¯ã©ã¹ã®LaunchFileAsyncïŒïŒã¡ãœããã§æå®ããŸãã ãã®åŸãã·ã¹ãã ã¯ããã®ã¿ã€ãã®ãã¡ã€ã«ã®ããã©ã«ãã®ã¢ããªã±ãŒã·ã§ã³ã§ãã¡ã€ã«ãéãããã€ã³ã¹ããŒã«æžã¿ã®ã¢ããªã±ãŒã·ã§ã³ããã¢ããªã±ãŒã·ã§ã³ãéžæããããã¹ãã¢ã§æ€çŽ¢ããããææ¡ããŸãã