I have to retrieve the filename of the content from gmail app.
i get content uri some thing similar to
content://gmail-ls/messages/mymailid%40gmail.com/4/attachments/0.1/BEST/fa开发者_Python百科lse
i see some apps getting the file names from it like this app
Kindly help regarding this.
Thanks in advance.
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();
}
}
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.
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>
What you need to do is register for the different mime types. Something like this:
<intent-filter>
<action name="android.intent.action.VIEW">
<category name="android.intent.category.DEFAULT">
<data mimetype="text/xml">
</intent-filter>
Then Android will list your app as an option when trying to open attachements from Gmail. Then it will start your app with an intent that gives you the uri.
精彩评论