שיתוף קבצים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
לעתים קרובות אפליקציות צריכות להציע קובץ אחד או יותר שלהן לאפליקציה אחרת. לדוגמה, יכול להיות שגלריית תמונות תרצה להציע קבצים לעורכי תמונות, או שאפליקציית ניהול קבצים תרצה לאפשר למשתמשים להעתיק ולהדביק קבצים בין אזורים באחסון החיצוני. אחת מהדרכים שבהן אפליקציה שולחת יכולה לשתף קובץ היא להגיב לבקשה מאפליקציה מקבלת.
בכל המקרים, הדרך המאובטחת היחידה להציע קובץ מהאפליקציה שלכם לאפליקציה אחרת היא לשלוח לאפליקציה המקבלת את ה-URI של תוכן הקובץ ולהעניק הרשאות גישה זמניות ל-URI הזה.
מזהי URI של תוכן עם הרשאות גישה זמניות ל-URI מאובטחים כי הם חלים רק על האפליקציה שמקבלת את ה-URI, ופג התוקף שלהם באופן אוטומטי. הרכיב FileProvider
ב-Android מספק את השיטה getUriForFile()
ליצירת URI של תוכן של קובץ.
אם רוצים לשתף בין אפליקציות כמויות קטנות של טקסט או נתונים מספריים, צריך לשלוח Intent
שמכיל את הנתונים. במאמר שיתוף נתונים פשוטים מוסבר איך שולחים נתונים פשוטים באמצעות Intent
.
בכיתה הזו מוסבר איך לשתף קבצים מהאפליקציה שלכם לאפליקציה אחרת באופן מאובטח באמצעות URI של תוכן שנוצר על ידי הרכיב FileProvider
של Android והרשאות זמניות שאתם מעניקים לאפליקציה המקבלת עבור URI התוכן.
שיעורי מוזיקה
- הגדרת שיתוף קבצים
-
איך מגדירים את האפליקציה לשיתוף קבצים
- שיתוף קובץ
-
איך מציעים קובץ לאפליקציה אחרת על ידי יצירת URI תוכן לקובץ, מתן הרשאות גישה ל-URI ושליחת ה-URI לאפליקציה.
- בקשה לקבלת קובץ ששותף
-
איך מבקשים קובץ ששותף על ידי אפליקציה אחרת, מקבלים את ה-URI של התוכן של הקובץ ומשתמשים ב-URI של התוכן כדי לפתוח את הקובץ.
-
אחזור פרטי הקובץ
-
איך אפליקציה יכולה להשתמש ב-URI של תוכן שנוצר על ידי
FileProvider
כדי לאחזר את פרטי הקובץ, כולל סוג ה-MIME וגודל הקובץ.
מידע נוסף בנושא זמין במאמרים הבאים:
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Sharing files\n\nApps often have a need to offer one or more of their files to another app. For example, an image\ngallery may want to offer files to image editors, or a file management app may want to allow\nusers to copy and paste files between areas in external storage. One way a sending app can\nshare a file is to respond to a request from the receiving app.\n\n\nIn all cases, the only secure way to offer a file from your app to another app is to send the\nreceiving app the file's content URI and grant temporary access permissions to that URI.\nContent URIs with temporary URI access permissions are secure because they apply only to the\napp that receives the URI, and they expire automatically. The Android\n[FileProvider](/reference/androidx/core/content/FileProvider) component provides the method\n[getUriForFile()](/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context, java.lang.String, java.io.File)) for\ngenerating a file's content URI.\n\n\nIf you want to share small amounts of text or numeric data between apps, you should send an\n[Intent](/reference/android/content/Intent) that contains the data. To learn how to send simple data with an\n[Intent](/reference/android/content/Intent), see the training class\n[Sharing simple data](/training/sharing).\n\n\nThis class explains how to securely share files from your app to another app using content URIs\ngenerated by the Android [FileProvider](/reference/androidx/core/content/FileProvider) component and\ntemporary permissions that you grant to the receiving app for the content URI.\n\nLessons\n-------\n\n**[Setting up file sharing](/training/secure-file-sharing/setup-sharing)**\n:\n Learn how to set up your app to share files.\n\n**[Sharing a file](/training/secure-file-sharing/share-file)**\n:\n Learn how to offer a file to another app by generating a content URI for the file,\n granting access permissions to the URI, and sending the URI to the app.\n\n**[Requesting a shared file](/training/secure-file-sharing/request-file)**\n:\n Learn how to request a file shared by another app, receive the content URI for the file,\n and use the content URI to open the file.\n\n\n**[Retrieving file information](/training/secure-file-sharing/retrieve-info)**\n:\n Learn how an app can use a content URI generated by a\n [FileProvider](/reference/androidx/core/content/FileProvider) to retrieve file information including\n MIME type and file size.\n\nFor additional related information, refer to:\n\n- [Storage Options](/guide/topics/data/data-storage)\n- [Saving Files](/training/basics/data-storage/files)\n- [Sharing Simple Data](/training/sharing)"]]