Refer links:
http://stackoverflow.com/questions/3497350/android-launching-an-application-chooser-with-appropriate-list-of-applications
http://stackoverflow.com/questions/11295961/how-to-return-workable-filepath
http://stackoverflow.com/questions/12426020/how-do-i-stop-xml-email-attachment-translating-to-html-in-the-gmail-app
http://stackoverflow.com/questions/2037551/how-to-open-email-attachment-in-my-app-on-android
OptionsInMailAttachmntsOpenActivity.java:-
package org.dharani.mailAttacmntOpen;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.os.Bundle;
public class OptionsInMailAttachmntsOpenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = getIntent();
if(i == null) return;
Uri u = i.getData();
if(u == null) return;
String scheme = u.getScheme();
System.out.println("******my application-1***********");
if(ContentResolver.SCHEME_CONTENT.equals(scheme))
{
try
{
ContentResolver cr = getContentResolver();
AssetFileDescriptor afd = cr.openAssetFileDescriptor(u, "r");
long length = afd.getLength();
byte[] filedata = new byte[(int) length];
InputStream is = cr.openInputStream(u);
if(is == null) return;
try
{
is.read(filedata, 0, (int) length);
/*Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(chosenFile));
intent.putExtra(Intent.ACTION_VIEW, uri);
Intent chooser = Intent.createChooser(intent, "Prashant");
startActivity(chooser);*/
//Util.loadOTDRFileFromByteArray(filedata);
}
catch(IOException e)
{
return;
}
}
catch(FileNotFoundException e)
{
return;
}
}
else
{
System.out.println("******my application-2***********");
String filePath = u.getEncodedPath();
if(filePath == null) return;
//Util.loadOTDRFileFromPath(filePath);
}
}
}
AndroidManifest.xml:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dharani.mailAttacmntOpen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".OptionsInMailAttachmntsOpenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:scheme="file" />
<data android:host="*" />
<data android:port="*" />
<data android:pathPattern=".*..*..*..*..*..*.trc" />
<data android:pathPattern=".*..*..*..*..*.trc" />
<data android:pathPattern=".*..*..*..*.trc" />
<data android:pathPattern=".*..*..*.trc" />
<data android:pathPattern=".*..*.trc" />
<data android:pathPattern=".*.trc" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xyz" />
</intent-filter>
</activity>
</application>
</manifest>
Note: Procedure To execute this project,first run this project,
-> after open ur Gmail a/c ->goto Inbox..
-> open any mail having attachment
-> click preview
Then u can see ur project in options menu
Comments
Post a Comment