Android get attached filename from gmail app(Android从gmail应用程序获取附加文件名)
问题描述
我必须从 gmail 应用程序中检索内容的文件名.
I have to retrieve the filename of the content from gmail app.
我得到的内容 uri 类似于
i get content uri some thing similar to
content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/false
content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/false
我看到一些应用程序从中获取文件名,例如 这个应用程序
i see some apps getting the file names from it like this app
请对此提供帮助.
提前致谢.
推荐答案
基本上,你需要获取文件系统,并获取存储信息的游标:
Basically, you need to acquire the file system and get a cursor where the info is stored:
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Toast;
public class CheckIt extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent theIntent = getIntent();
String attachmentFileName = "No file name found";
if (theIntent != null && theIntent.getData() != null) {
Cursor c = getContentResolver().query(
theIntent.getData(), null, null, null, null);
c.moveToFirst();
final int fileNameColumnId = c.getColumnIndex(
MediaStore.MediaColumns.DISPLAY_NAME);
if (fileNameColumnId >= 0)
attachmentFileName = c.getString(fileNameColumnId);
}
Toast.makeText(this, attachmentFileName, Toast.LENGTH_LONG).show();
}
}
在返回的光标中还有另一列 - MediaStore.MediaColumns.SIZE.至少这是我在我的 Desire HD 上使用 GMail 所得到的.只需通过在 GMail 中操作邮件并点击预览按钮来尝试上述代码.
In the cursor returned there is another column - MediaStore.MediaColumns.SIZE. At least that's what I get with GMail on my Desire HD. Just try the above code by operning a mail in GMail and hitting the preview button.
当然,不要忘记将以下内容添加到 Manifest.xml 中的活动部分(不要从活动中删除 android.intent.category.LAUNCHER 意图过滤器部分,否则将无法通过启动器查看):
Of course, do not forget to add the following to the activity section in the Manifest.xml (do not drop the android.intent.category.LAUNCHER intent-filter section from the activity otherwise it will not be viewable through the launcher):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
这篇关于Android从gmail应用程序获取附加文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android从gmail应用程序获取附加文件名


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01