开发者

Android - Send Email from App crashes Email - Force Close

开发者 https://www.devze.com 2023-03-31 17:03 出处:网络
I have an app that triggers an email from Javascript through Java which then attaches a file. I get the chooser which has \"Email\" or \"Gmail\" as my options.

I have an app that triggers an email from Javascript through Java which then attaches a file.

I get the chooser which has "Email" or "Gmail" as my options.

If I select Gmail then the Gmail client opens as expeceted with subject, body, and attachement all there.

But if I choose Email I get: "The application Email (process com.google.android.email) has stopped unexpectedly. Force close." I need it to use corporate email so this is no good.

Log shows: "Caused by: java.lang.illegalArgumentException"

Any ideas why this is happening?

Here's my code:

MainActivity:

public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setIntegerProperty( "splashscreen", R.drawable.splash );
    super.loadUrl("file:///android_asset/www/index.html", 1000);
    JavaScriptInterface jsi = new JavaScriptInterface(this, appView);
    appView.addJavascriptInterface(jsi, "Android");
    }
} 

JavaScriptInterface

public class JavaScr开发者_StackOverflow社区iptInterface {
private WebView mAppView;
private DroidGap mGap;
public JavaScriptInterface (DroidGap gap, WebView view)
{
    mAppView = view;
    mGap = gap;
    }
public void doEmail(){

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/html");
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"test text");
    sendIntent.putExtra(Intent.EXTRA_SUBJECT,"test subject");
    sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("sdcard/test co.html"));
    mGap.startActivity(Intent.createChooser(sendIntent, "Send email..."));
    }
} 


You need to put "file://" in front of your filename.

0

精彩评论

暂无评论...
验证码 换一张
取 消