2016-02-19 29 views
2

我試圖使用Intent.createChooser和從我的Android應用程序共享圖像。圖像被保存到由activity.getExternalMediaDirs()返回的第一個結果。然後我用:Android 6.0.1 - 通過Messenger和Intent.ACTION_SEND共享圖像導致安全異常

mediaScannerConnection.scanFile(imageFilename, "image/png"); 

這種成功,給人一種URI,如以下到onScanCompleted

content://media/external/images/media/27578 

我再試試這個URI傳遞給系統選擇對話框:

@Override 
public void onScanCompleted(String path, Uri uri) { 
    mediaScannerConnection.disconnect(); 

    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text); 
    shareIntent.putExtra("sms_body", text); 
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
    shareIntent.setClipData(ClipData.newUri(activity.getContentResolver(), "Screenshot", uri)); 
    shareIntent.setType("image/png"); 
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    activity.startActivity(Intent.createChooser(shareIntent, chooserTitle)); 
} 

這似乎適用於大多數選定的目標應用,包括環聊。選擇Messenger時,默認的MMS應用程序似乎什麼也沒有發生。然而有在日誌中的消息:

02-19 12:17:58.714 26143 26354 I iu.UploadsManager: storage changed; old: -1, new: -1 
02-19 12:17:58.773 26143 3554 I iu.UploadsManager: End new media; added: 0, uploading: 0, time: 50 ms 
02-19 12:17:58.804 782 4995 I ActivityManager: START u0 {act=android.intent.action.CHOOSER flg=0x1 cmp=android/com.android.internal.app.ChooserActivity clip={image/png text/uri-list U:content://media/external/images/media/27578} (has extras)} from uid 10289 on display 0 
02-19 12:17:58.851 782 21004 I ActivityManager: Start proc 3569:android:ui/1000 for activity android/com.android.internal.app.ChooserActivity 
02-19 12:17:59.000 3569 3569 W ResourceType: ResTable_typeSpec entry count inconsistent: given 1, previously 1266 
02-19 12:17:59.479 3569 3569 W ResourceType: ResTable_typeSpec entry count inconsistent: given 1, previously 1266 
02-19 12:17:59.495 782 4995 I ActivityManager: Start proc 3591:com.google.android.apps.messaging/u0a120 for service com.google.android.apps.messaging/.shared.datamodel.BugleChooserTargetService 
02-19 12:17:59.519 782 957 I ActivityManager: Start proc 3604:com.google.android.apps.docs:UploadToFolder/u0a37 for service com.google.android.apps.docs/.drive.directsharing.ChooserTargetService 
02-19 12:17:59.568 3569 3617 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
02-19 12:17:59.617 3569 3617 I Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb 
02-19 12:17:59.620 3569 3617 I OpenGLRenderer: Initialized EGL, version 1.4 
02-19 12:17:59.880 1280 1280 I Keyboard.Facilitator: onFinishInput() 
02-19 12:17:59.901 782 803 I ActivityManager: Displayed android/com.android.internal.app.ChooserActivity: +1s61ms 
02-19 12:17:59.947 3591 3605 D BugleServices: onGetChooserTargets called() 
02-19 12:17:59.952 3591 3652 I art  : Note: end time exceeds epoch: 
02-19 12:17:59.959 3591 3591 I Bugle : Carrier config changed. Reloading MMS config. 
02-19 12:18:00.011 782 4995 I ActivityManager: Killing 2966:com.android.keychain/1000 (adj 15): empty #17 
02-19 12:18:00.016 3604 3604 E ActivityThread: Service com.google.android.apps.docs.drive.directsharing.ChooserTargetService has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
02-19 12:18:00.016 3604 3604 E ActivityThread: android.app.IntentReceiverLeaked: Service com.google.android.apps.docs.drive.directsharing.ChooserTargetService has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:918) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:719) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1172) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1152) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1146) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.accounts.AccountManager.addOnAccountsUpdatedListener(AccountManager.java:2549) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at dah.<init>(PG:1135) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at daz.<init>(PG:10223) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at com.google.android.apps.docs.preferences.UploadHistoryReader.<init>(PG:124) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at com.google.android.apps.docs.drive.directsharing.ChooserTargetService.onCreate(PG:49) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ActivityThread.-wrap4(ActivityThread.java) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.os.Handler.dispatchMessage(Handler.java:102) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.os.Looper.loop(Looper.java:148) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at android.app.ActivityThread.main(ActivityThread.java:5417) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at java.lang.reflect.Method.invoke(Native Method) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
02-19 12:18:00.016 3604 3604 E ActivityThread:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
02-19 12:18:00.062 3591 3650 I BugleDataModel: Fixup: Send failed - 0 Download failed - 0 
02-19 12:18:00.099 3591 3655 W Bugle : canonicalizeMccMnc: invalid mccmnc:null ,null 
02-19 12:18:00.109 1898 1898 V GLSActivity: AuthDelegateWrapperCreated with selected intent: Intent { cmp=com.google.android.gms/.auth.DefaultAuthDelegateService } 
02-19 12:18:00.113 1898 1898 V GLSActivity: AuthDelegateWrapperCreated with selected intent: Intent { cmp=com.google.android.gms/.auth.DefaultAuthDelegateService } 
02-19 12:18:00.120 782 954 D MmsServiceBroker: getCarrierConfigValues() by com.google.android.apps.messaging 
02-19 12:18:00.120 1397 1421 D MmsService: getCarrierConfigValues 
02-19 12:18:00.120 1397 1421 I MmsService: mms config for sub 1: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] 
02-19 12:18:00.121 3591 3655 I Bugle : Carrier configs loaded: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] from resources+system for subId=1 
02-19 12:18:00.113 3591 3647 I Bugle : ApnsOta: OTA version -1 
02-19 12:18:00.158 1898 1898 V GLSActivity: AuthDelegateWrapperCreated with selected intent: Intent { cmp=com.google.android.gms/.auth.DefaultAuthDelegateService } 
02-19 12:18:00.164 3591 3657 W Bugle : canonicalizeMccMnc: invalid mccmnc:null ,null 
02-19 12:18:00.186 782 3714 D MmsServiceBroker: getCarrierConfigValues() by com.google.android.apps.messaging 
02-19 12:18:00.186 1397 1631 D MmsService: getCarrierConfigValues 
02-19 12:18:00.186 1397 1631 I MmsService: mms config for sub 1: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] 
02-19 12:18:00.187 3591 3657 I Bugle : Carrier configs loaded: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] from resources+system for subId=1 
02-19 12:18:00.223 3591 3665 I BugleDataModel: SyncMessagesAction: Starting batch for messages from 1455894395560 to 1455902279886 (message update limit = 80, message scan limit = 4000) 
02-19 12:18:00.224 3591 3647 W Bugle : canonicalizeMccMnc: invalid mccmnc:null ,null 
02-19 12:18:00.243 782 3714 D MmsServiceBroker: getCarrierConfigValues() by com.google.android.apps.messaging 
02-19 12:18:00.243 1397 2593 D MmsService: getCarrierConfigValues 
02-19 12:18:00.243 1397 2593 I MmsService: mms config for sub 1: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] 
02-19 12:18:00.244 3591 3647 I Bugle : Carrier configs loaded: Bundle[{httpSocketTimeout=60000, aliasMinChars=2, smsToMmsTextThreshold=8, enableSMSDeliveryReports=true, maxMessageTextSize=-1, supportMmsContentDisposition=true, enabledTransID=false, aliasEnabled=false, supportHttpCharsetHeader=false, allowAttachAudio=true, smsToMmsTextLengthThreshold=-1, recipientLimit=20, uaProfTagName=x-wap-profile, aliasMaxChars=48, maxImageHeight=1944, enableMMSDeliveryReports=false, userAgent=, config_cellBroadcastAppLinks=false, maxSubjectLength=80, httpParams=, enableGroupMms=false, emailGatewayNumber=6245, maxMessageSize=614400, naiSuffix=, enableMMSReadReports=false, maxImageWidth=2592, uaProfUrl=, enabledMMS=true, enabledNotifyWapMMSC=false, sendMultipartSmsAsSeparateMessages=false, enableMultipartSMS=true}] from resources+system for subId=1 
02-19 12:18:00.464 3591 3650 I BugleDataModel: SyncMessagesAction: All messages now in sync 
02-19 12:18:00.468 782 793 I ActivityManager: Killing 3132:com.google.android.partnersetup/u0a11 (adj 15): empty #17 
02-19 12:18:00.812 782 791 I art  : Background partial concurrent mark sweep GC freed 20139(1248KB) AllocSpace objects, 2(40KB) LOS objects, 31% free, 35MB/51MB, paused 1.523ms total 132.014ms 
02-19 12:18:01.554 782 889 D ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [WIFI() - 101] 
02-19 12:18:01.918 201 814 D audio_hw_primary: disable_audio_route: reset and update mixer path: low-latency-playback 
02-19 12:18:01.918 201 814 D audio_hw_primary: disable_snd_device: snd_device(2: speaker) 
02-19 12:18:03.597 782 4881 I ActivityManager: START u0 {act=android.intent.action.SEND typ=image/png flg=0xb080001 cmp=com.google.android.apps.messaging/.ui.conversationlist.ShareIntentActivity clip={image/png text/uri-list U:content://media/external/images/media/27578} (has extras)} from uid 10289 on display 0 
02-19 12:18:03.601 201 814 D audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2 
02-19 12:18:03.622 201 814 D audio_hw_primary: select_devices: out_snd_device(2: speaker) in_snd_device(0: none) 
02-19 12:18:03.622 201 814 D msm8974_platform: platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15) 
02-19 12:18:03.622 201 814 D audio_hw_primary: enable_snd_device: snd_device(2: speaker) 
02-19 12:18:03.624 201 814 D audio_hw_primary: enable_audio_route: apply and update mixer path: low-latency-playback 
02-19 12:18:03.646 3569 3569 E ResolverActivity: Unable to launch as uid 10289 package com.package.product, while running in android:ui 
02-19 12:18:03.646 3569 3569 E ResolverActivity: java.lang.SecurityException: Uid 10289 does not have permission to uri 0 @ content://media/external/images/media/27578 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.os.Parcel.readException(Parcel.java:1620) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.os.Parcel.readException(Parcel.java:1573) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.app.ActivityManagerProxy.startActivityAsCaller(ActivityManagerNative.java:2730) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.app.Instrumentation.execStartActivityAsCaller(Instrumentation.java:1725) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.app.Activity.startActivityAsCaller(Activity.java:4060) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ChooserActivity$ChooserTargetInfo.startAsCaller(ChooserActivity.java:659) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ResolverActivity.safelyStartActivity(ResolverActivity.java:790) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ResolverActivity.onTargetSelected(ResolverActivity.java:772) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ChooserActivity.onTargetSelected(ChooserActivity.java:338) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ResolverActivity.startSelected(ResolverActivity.java:621) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ChooserActivity.startSelected(ChooserActivity.java:343) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.app.ChooserActivity$ChooserRowAdapter$2.onClick(ChooserActivity.java:1117) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.view.View.performClick(View.java:5204) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.view.View$PerformClick.run(View.java:21153) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.os.Handler.handleCallback(Handler.java:739) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.os.Handler.dispatchMessage(Handler.java:95) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.os.Looper.loop(Looper.java:148) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at android.app.ActivityThread.main(ActivityThread.java:5417) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at java.lang.reflect.Method.invoke(Native Method) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
02-19 12:18:03.646 3569 3569 E ResolverActivity:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

爲什麼Messenger應用似乎沒有權限訪問該URI?

java.lang.SecurityException: Uid 10289 does not have permission to uri 0 @ content://media/external/images/media/27578 

我使用的設備是運行Android 6.0.1的Nexus 5。

回答

0

您是否在清單文件中設置了權限? 如果沒有,那麼複製並粘貼此

<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAG"/> 

希望這有助於..

+0

我沒有MEDIA_CONTENT_CONTROL,但它似乎是無關的共享:http://developer.android.com/reference /android/Manifest.permission.html#MEDIA_CONTENT_CONTROL和「由於媒體消費的隱私而不適用於第三方應用程序」。無論如何,我試着添加這個 - 沒有效果。 –

相關問題