Android : Android unable to open Gmail attachments

on Thursday, September 25, 2014


I would like to open pdfs attachments with my app.


I have set up the intent-filter



<intent-filter android:label="@string/label" >
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/pdf" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter android:label="@string/label" >
<action android:name="android.intent.action.SHARE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/pdf" />
<data android:mimeType="image/*" />
</intent-filter>


and it works well on Android 4.4 devices but on 4.2.2 I get the following exception:



java.lang.SecurityException: Permission Denial: opening provider com.google.android.gm.provider.MailProvider from ProcessRecord{2120ac60 21661:com.some.app.package/u0a10113} (pid=21661, uid=10113) requires com.google.android.gm.permission.READ_GMAIL or com.google.android.gm.permission.WRITE_GMAIL


I have tried adding all these permissions:



<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.android.email.permission.READ_ATTACHMENT"/>
<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.gm.permission.READ_CONTENT_PROVIDER"/>


Strangely if I try loading the same attachment but instead of using gmail I use default mail app, with same account, I get no errors.


but still get the same exception what can I do? thanks


EDIT:


I have also added these 2:



<uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.providers.gmail.permission.WRITE_GMAIL"/>


still no luck


EDIT2:


This is how I get the exception triggered:



public static byte[] getBytesFromUri(Uri uri, Context appCtx) {

ByteArrayOutputStream byteBuffer = null;
InputStream inputStream = null;

try {
inputStream = appCtx.getContentResolver().openInputStream(uri); //crash here
byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
inputStream.close();
inputStream=null;
return byteBuffer.toByteArray();
} catch (IOException e) {
log.e(TAG, "error retrieving bytearray from uri "+uri);
e.printStackTrace();
}

return null;
}

0 comments:

Post a Comment