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>