2016-11-17 123 views
1

正在關注Instagram's video sharing Android Intent。簡單的編輯可以繞過選擇器並直接啓動Instagram。相關代碼和adb輸出的See GistInstagram的視頻共享Android意圖

Kit Kat設備按照預期工作,但是Nougat設備下降到第20行,啓動Play Store,就好像Instagram沒有安裝。

在這兩個設備上,ShareDialog的startInstagram()的第14行確實提供了一個支持視頻共享功能的應用程序(包括Instagram)的選擇器。

用這種方法共享圖像的相關代碼在兩個設備上按預期工作。

UPDATE 1:實施新的ContentProvider方法會導致Instagram在啓動共享Intent時崩潰。我會測試分享視頻到另一個社交網絡,看看是否有效。

更新2:原來的Instagram沒有發揮好與

share.setDataAndType(contentUri, "video/*");

單獨設置它們,使所有內容處於正常工作狀態。

share.setType("video/*"); share.putExtra(Intent.EXTRA_STREAM, contentUri);

+0

當你看到Android 7.0上的'Exception'時,你學到了什麼? – CommonsWare

+0

E/ShareDialog:e.getLocalizedMessage >> file:///storage/emulated/0/870_90.mp4通過ClipData.Item.getUri()暴露超出應用程序 E/ShareDialog:e.getCause >> null' – es0329

回答

1

登錄Android上的牛軋糖的要點異常揭示了問題:

android.os.FileUriExposedException:文件:///storage/emulated/0/test.mp4通過ClipData.Item暴露超過應用.getUri()

在Android牛軋糖,你將需要使用供應商:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    Uri contentUri = FileProvider.getUriForFile(getContext(), "com.your.package.fileProvider", newFile); 
    intent.setDataAndType(contentUri, type); 
} 

參見:android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

1

這似乎是一個FileUriExposedException。如果您的targetSdkVersion爲24或更高,則不能在Intent或其他地方(例如,'通知'上的setSound())使用Uri.fromFile()或其他fileUri值。

使用FileProvider通過ContentProvider服務您的文件。