
目前,他们使用ES文件浏览器移动或关闭,或者手机制造商的行为类似于USB驱动器的转移实用程序.笨重.我想要的是能够将文件通过电子邮件发送到手机,然后从gmail中打开文件作为附件,这应该启动应用程序,然后将应用程序保存到相应的SD卡文件夹中.
我发现了一些关于设置意图的东西 – 希望 – 在gmail(特别是Open custom Gmail attachment in my Android app)中单击“预览”启动应用程序,但我完全不确定如何访问文件数据!我想它必须与Intent.get … Extra()函数之一,但是哪个,以及如何使用它?
解决方法 找到了怎么做.希望这可以帮助别人.派对矿,部分来自其他职位.它的目标是处理.gcsb文件附件.意图过滤器是
<intent-filter> <action androID:name="androID.intent.action.VIEW" /> <category androID:name="androID.intent.category.DEFAulT" /> <category androID:name="androID.intent.category.broWSABLE" /> <data androID:mimeType="application/octet-stream" /></intent-filter>
并且活动onCreate()/ onRestart()中的代码是
Intent intent = getIntent();inputStream is = null;fileOutputStream os = null;String fullPath = null;try { String action = intent.getAction(); if (!Intent.ACTION_VIEW.equals(action)) { return; } Uri uri = intent.getData(); String scheme = uri.getScheme(); String name = null; if (scheme.equals("file")) { List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() > 0) { name = pathSegments.get(pathSegments.size() - 1); } } else if (scheme.equals("content")) { Cursor cursor = getContentResolver().query(uri,new String[] { MediaStore.MediaColumns.disPLAY_name },null,null); cursor.movetoFirst(); int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.disPLAY_name); if (nameIndex >= 0) { name = cursor.getString(nameIndex); } } else { return; } if (name == null) { return; } int n = name.lastIndexOf("."); String filename,fileExt; if (n == -1) { return; } else { filename = name.substring(0,n); fileExt = name.substring(n); if (!fileExt.equals(".gcsb")) { return; } } fullPath = ""/* create full path to where the file is to go,including name/ext */; is = getContentResolver().openinputStream(uri); os = new fileOutputStream(fullPath); byte[] buffer = new byte[4096]; int count; while ((count = is.read(buffer)) > 0) { os.write(buffer,count); } os.close(); is.close();} catch (Exception e) { if (is != null) { try { is.close(); } catch (Exception e1) { } } if (os != null) { try { os.close(); } catch (Exception e1) { } } if (fullPath != null) { file f = new file(fullPath); f.delete(); }} 它似乎适用于标准的AndroID gmail和邮件应用程序.根据是否在gmail中按下“下载”(方案文件)或“预览”(方案内容),可以获得两种不同的文件名.
请注意,将活动设置为单个实例非常重要.
总结以上是内存溢出为你收集整理的android – 如何在我的应用程序中访问gmail附件数据全部内容,希望文章能够帮你解决android – 如何在我的应用程序中访问gmail附件数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)