是的,我們可以將使用FileProvider.Using FileProvider存儲在文件目錄到Gmail內部文件,我們可以給我們的一些應用程序的內部文件(如在filepaths.xml提到)
臨時訪問在表現爲Android的文件中所提及添加FileProvider:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.package.name.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
在應用程序的資源
現在/ XML文件夾中創建filepaths.xml,並添加以下代碼:
<paths>
<files-path path="." name="name" />
注:這將使訪問根目錄的文件目錄,如果你想給一些子目錄特定的訪問,說圖片,在你的內部存儲提到的路徑爲「圖像/」
<paths>
<files-path path="images/" name="name" />
在代碼:
File file=new File(context.getFilesDir(),"test.txt");
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test");
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] {"email-address you want to send the file to"});
Uri uri = FileProvider.getUriForFile(context,"com.package.name.fileprovider",
file);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(uri);
shareIntent .putParcelableArrayListExtra(Intent.EXTRA_STREAM,
uris);
try {
context.startActivity(Intent.createChooser(shareIntent , "Email:").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
catch(ActivityNotFoundException e) {
Toast.makeText(context,
"Sorry No email Application was found",
Toast.LENGTH_SHORT).show();
}
}
這個工作對me.Hope這有助於:)
即可獲得流直接在文件和測試你的理論呢? – MJB 2011-05-01 04:33:16
我知道一個事實,即流是可訪問的 - 其他電子郵件應用程序可以訪問它並附加它沒有問題 – user496854 2011-05-02 06:24:32