tum*_*udu 11 permissions gmail android single-instance
当我将启动模式设置为"singleInstance"时,我在MYApp中打开电子邮件时遇到问题.
我附加了示例Android项目,它从电子邮件附件中读取文件名并在屏幕上显示.在onCreate的情况下工作正常但在应用程序启动模式为singleInstance时在onNewIntent中抛出错误.
Launchmode.java
package your.namespace.launchmode;
public class LaunchModeActivity extends Activity {
private static final int OPEN_ACT = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String name = getAttachmetName(getIntent());
if(null != name)
{
TextView textv = (TextView) findViewById(R.id.attachmentnm);
textv.setText(name);
}
}
@Override
protected void onNewIntent(Intent savedInstanceState)
{
super.onNewIntent(savedInstanceState);
String name = getAttachmetName(savedInstanceState);
if(null != name)
{
TextView textv = (TextView) findViewById(R.id.attachmentnm);
textv.setText(name);
}
}
private String getAttachmetName(Intent intent) {
final Uri documentUri = intent.getData();
if(null != documentUri){
final String uriString = documentUri.toString();
String documentFilename = null;
final int mailIndexPos = uriString.lastIndexOf("/attachments");
if (mailIndexPos != -1) {
final Uri curi = documentUri;
final String [] projection = new String[] {OpenableColumns.DISPLAY_NAME};
final Cursor cursor = getApplicationContext().getContentResolver().query(curi, projection, null, null, null);
if (cursor != null) {
final int attIdx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (attIdx != -1) {
cursor.moveToFirst();
documentFilename = cursor.getString(attIdx);
}
cursor.close();
}
}
return documentFilename;
}
return null;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if((resultCode == RESULT_OK) && (requestCode == OPEN_ACT))
{
Log.d("LaunchMode", "Second activity returned");
}
}
Run Code Online (Sandbox Code Playgroud)
}
AndroidManifest
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.namespace.launchmode"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.gm.permission.WRITE_GMAIL"/>
<uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.providers.gmail.permission.WRITE_GMAIL"/>
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:launchMode="singleInstance"
android:name=".LaunchModeActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<!-- docx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
<!-- xlsx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<!-- pptx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" />
<data android:mimeType="application/vnd.ms-excel" />
<data android:mimeType="application/msword" />
<data android:mimeType="application/vnd.ms-powerpoint" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
重现的步骤1)在设备上安装apk.2)转到设备上的gmail本机应用程序,打开任何附件(office文档)进行查看.3)选择LaunchMode应用程序以完成操作.4)LaunchMode应用程序将在屏幕上显示文件名.
这个第一次工作正常(onCreate flow)但是当这个应用程序在后台切换时我再次尝试2,3,4步... app崩溃有错误
E/DatabaseUtils(30615): java.lang.SecurityException: Permission Denial: reading com.google.android.gm.provider.MailProvider uri content://gmail-ls/qoconnect@gmail.com/messages/5/attachments/0.2/BEST/false from pid=32657, uid=10058 requires com.google.android.gm.permission.READ_GMAIL
E/DatabaseUtils(30615): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:309)
E/DatabaseUtils(30615): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:178)
E/DatabaseUtils(30615): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)
E/DatabaseUtils(30615): at android.os.Binder.execTransact(Binder.java:339)
E/DatabaseUtils(30615): at dalvik.system.NativeStart.run(Native Method)
D/AndroidRuntime(32657): Shutting down VM
Run Code Online (Sandbox Code Playgroud)
我需要解决这个问题,我需要有单个Application实例,并且还应该获得电子邮件附件名称.请告诉我如果我在这里遗漏了什么.
我的问题是为什么它在onCreate的流程中起作用,并且在onNewIntent的情况下它不起作用
注意:1)与2.x手机一起使用2)在单顶启动模式下工作正常.3)Gmail应用程序的一些更新.链接到这里:
当您收到意图并且未使用您请求的权限(READ_GMAIL和WRITE_GMAIL)时,您可能获得了读取文件名的URI权限.URI权限仅在您的应用程序使用之前有效finish(),因此当您尝试恢复时,您将无法获得该权限.
这与你的经历是一致的 - 当意图是新鲜的,但不是旧的时,它会起作用.我认为这WRITE_GMAIL是签名许可,我猜这READ_GMAIL也是.在那种情况下,你无能为力. READ_ATTACHMENT可能是您要求的更合适的许可.
有关URI权限的更多信息:http://developer.android.com/guide/topics/security/permissions.html#uri
尝试uses-permission从清单中删除标记,看看您是否有相同的体验.您还intent可以通过检查其标志来尝试检查何时收到它.
checkCallingOrSelfUriPermission(documentUri , Intent.FLAG_GRANT_READ_URI_PERMISSION)
Run Code Online (Sandbox Code Playgroud)
如果返回0,则表示您一直使用URI权限.
| 归档时间: |
|
| 查看次数: |
6331 次 |
| 最近记录: |