安卓得到重视,从Gmail应用程序的文件名 [英] Android get attached filename from gmail app
问题描述
我要检索Gmail应用程序内容的文件名。
I have to retrieve the filename of the content from gmail app.
我得到的内容URI的一些东西类似于
i get content uri some thing similar to
内容://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。至少这是我与Gmail得到我的Desire HD的。仅仅通过operning在Gmail中的邮件,打了preVIEW按钮尝试上面的code。
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>
这篇关于安卓得到重视,从Gmail应用程序的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!