2015-11-28 116 views
0

如何在android中使用小部件發送電子郵件?在我onUpdate()方法我已經寫了以下內容:android,發送電子郵件,部件

Intent intent3 = new Intent(Intent.ACTION_SEND); 
      intent3.setData(Uri.parse("mailto:")); 
      intent3.setType("text/plain"); 
      intent3.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
      intent3.putExtra(Intent.EXTRA_SUBJECT,"Temat"); 
      intent3.putExtra(Intent.EXTRA_TEXT, "Tekst wiadomości"); 

      PendingIntent pendingEmailIntent = PendingIntent.getActivity(context,0,intent3,0); 

      RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout); 

      remoteViews.setOnClickPendingIntent(R.id.email_button,pendingEmailIntent); 

其他操作,如打開新的活動或瀏覽器,工作爲疑似,但是這一次不是。我究竟做錯了什麼?

+0

:''Uri',使用'ACTION_SENDTO',不'ACTION_SEND'

然後,我已經改變了我的代碼。 – CommonsWare

+0

我已經改變了那個,但仍然沒有工作。 –

+0

檢查LogCat,看看是否有堆棧跟蹤或其他消息,可能在警告嚴重性。例如,您可能需要將'FLAG_ACTIVITY_NEW_TASK'添加到'Intent',並且這應該顯示在LogCat中。 – CommonsWare

回答

0

我想通了。代碼中沒有錯誤,但顯然,電子郵件應用程序應以不同的方式運行。我在很多帖子中已經注意到它被稱爲startActivity(Intent.createChooser(intentname,"OptionalTitle"))。順便提一句,ACTION_SENDTO不需要,它現在可以與ACTION_SEND一起使用。如果你想用一個'的mailto

Intent intent3 = new Intent(Intent.ACTION_SEND); 
      intent3.setData(Uri.parse("mailto:")); 
      intent3.setType("text/plain"); 
      intent3.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
      intent3.putExtra(Intent.EXTRA_SUBJECT,"Temat"); 
      intent3.putExtra(Intent.EXTRA_TEXT, "Tekst wiadomości"); 

      PendingIntent pendingEmailIntent = PendingIntent.getActivity(context,0,Intent.createChooser(intent3,"Choose"),0); 

      RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout); 

      remoteViews.setOnClickPendingIntent(R.id.email_button,pendingEmailIntent);