2012-11-06 43 views
2

我的應用程序生成的kml(xml)文件,我希望用戶能夠通過電子郵件,藍牙或任何其他方式共享。我看過幾十個例子,但顯然仍然在做錯事。如果我選擇Gmail,則電子郵件會正確加載,但文件未附加。如果我選擇藍牙,藍牙管理器會崩潰。我在這裏做錯了什麼?Android:無法正確創建分享kml(xml)文件的意圖

private void createShareIntent(String filename) { 
    Log.d(Common.APP_TAG, "** Create share intent **"); 
    String mime = "text/plain"; 
    File exportFile = new File(filename); 
    Log.d(Common.APP_TAG, Uri.fromFile(exportFile).toString()); 
    // logcat says : file:///mnt/sdcard/Android/data/com.gmail.qkzoo1978.qwhereami/files/exports/qExport_11-6-2012_1648.kml 
    Intent intent = new Intent(); 
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); 
    intent.putExtra(Intent.EXTRA_SUBJECT, "Test"); 
    intent.putExtra(Intent.EXTRA_TEXT, "Text"); 
    intent.setType(mime); 
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(exportFile)); 
    //intent.setDataAndType(Uri.fromFile(exportFile), mime); 
    startActivity(Intent.createChooser(intent, "Share Kml")); 
} 
+0

您是否嘗試過在數據文件夾之外選擇文件? Android的可能不會給你的權限從那裏讀 – dymmeh

+0

http://stackoverflow.com/questions/587917/trying-to-attach-a-file-from-sd-card-to-email [此線索] [1]有很多有用的信息。 [1]:http://stackoverflow.com/questions/587917/trying-to-attach-a-file-from-sd-card-to-email –

+0

我還沒有以相同的嘗試文件在其他地方,但它讓我在這裏讀/寫,這個應用程序創建了這個文件。上面的目錄是我的SD卡上的apps目錄。 – qkzoo1978

回答

0

不知道,如果你曾經解決了這一點,但我遇到了同樣的問題,這個週末意識到這是因爲我節約,我的應用可訪問的,但其他應用沒有一個文件。因此,當用於處理共享的應用程序嘗試讀取文件權限時被拒絕。奇怪的是,這在日誌中並不清楚。

解決此問題的方法是將文件保存到外部存儲器,這可能不太理想。

或者作爲更好的解決方案,使用文件提供程序並授予權限。