这个应用程序如何访问GMail?

时间:2012-03-27 18:25:51

标签: android gmail

我正在编写一个需要访问GMail的Android应用程序,我想通过向用户显示(Google托管?)提示登录其Google帐户,以与SwiftKey相同的方式执行此操作,像这样:

enter image description here

您知道他们使用什么API来获取此提示吗?此API是否提供对GMail的直接访问,还是我仍然必须使用IMAP?

提前致谢...

2 个答案:

答案 0 :(得分:1)

似乎oauth是通过webview处理的,它被构造成看起来像对话框。

答案 1 :(得分:0)

您需要使用Intent来满足您的要求。以下是相同的代码。

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{ "target@gmail.com"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "subject"); 
i.putExtra(Intent.EXTRA_TEXT   , "body part"); 

try 
{     
   startActivity(Intent.createChooser(i, "Sending  Email...")); 
} 
catch (android.content.ActivityNotFoundException ex) 
{     
   Toast.makeText(MyActivity.this, "No Email clients",Toast.LENGTH_SHORT ).show(); 
} 

此代码允许您通过Gmail服务器进行通信。