对于默认的 android电子邮件客户端一切正常,但面向gmail应用程序
java.lang.SecurityException: Permission Denial: opening provider com.google.android.gm.provider.MailProvider from ProcessRecord (pid=11298,uid=10068) requires com.google.android.gm.permission.READ_GMAIL or com.google.android.gm.permission.WRITE_GMAIL
甚至尝试过授予Gmail读写权限但无效.
观察是
It is working fine for Nexus but for samsung devices 4.2 and 4.1,working fine initially if activity is created for first time,but if activity is in background throwing above said exceptions.
尝试使用下面的代码获取附件文件名.
Cursor cursor = getContentResolver().query(openIntent.getData(),new String[] { MediaStore.MediaColumns.DISPLAY_NAME },null,null); cursor.moveToFirst(); int nameIndex = cursor .getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); if (nameIndex >= 0) { NCUtil.clickedImageTitle = cursor.getString(nameIndex); path = cursor.getString(nameIndex); } cursor.close();
我的清单文件
<activity android:name="com.ncomputing.vspacemobile.NCMainActivity" android:configChanges="orientation|keyboard|keyboardHidden|screenSize" android:excludeFromRecents="true" android:launchMode="singleTask" android:screenOrientation="sensorPortait" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan" > <!-- For email attachments --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/pdf" /> <data android:mimeType="application/msword" /> <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" /> <data android:mimeType="application/vnd.ms-excel" /> <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" /> <data android:mimeType="application/vnd.ms-powerpoint" /> <data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" /> <data android:mimeType="text/plain" /> <data android:mimeType="text/comma-separated-values" /> <data android:mimeType="application/rtf" /> </intent-filter> </activity>
用户权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
请告诉我们如何使其工作,我需要将活动启动模式作为singleTask并访问附件.
解决方法
<intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="file" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/> <data android:scheme="content" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/>
根据Android文档,“如果没有为intent过滤器指定方案,则忽略所有其他URI属性.”删除了scheme和URI属性后,过滤意图的唯一方法是使用Mime类型,我们都知道自定义文件扩展名没有注册的mime类型.
作为参考,URI的形式如下:
scheme://host:port/path pathPrefix pathPattern
所以没有方案,所有这些都会下降.在发现上述内容之后,我尝试了显而易见的 – 使用“*”作为方案,甚至尝试了“.*”.这些都没有奏效.我希望其他人可以继承我的考验.但我认为这与选择正确的方案有关.不幸的是,我所知道的唯一方案是http https内容和文件,以上都不是神奇的子弹.
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/*" host="*" android:pathPattern=".*.ext" android:scheme="content" /> </intent-filter>
此意图将导致gmail显示“下载/预览”按钮.实际上,当.ext文件作为附件发送到常规电子邮件客户端时,这也会导致您的应用程序打开.
资源:
Android get attached filename from gmail app
Intent filter to download attachment from gmail apps on Android
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。