關鍵代碼以下: ide
//語音錄入 調用谷歌語音程序, 用戶說完話後,將提交到雲端搜索,在雲端搜索完成後,返回打印數據。
//缺點:必須聯網
imgVoice.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// //語言模式和自由模式的語音識別
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "請說話");
startActivityForResult(intent, 0);//這個地方不能用startActivity()
}
}); get
//語音錄入的返回結果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode==0&&resultCode==RESULT_OK)
{
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String resultString="";
for(int i=0;i<results.size();i++)
{
//resultString+=results.get(i);
editContent.setText(results.get(i));
}
}
super.onActivityResult(requestCode, resultCode, data);
} it
//發送郵件
btnSend.setOnClickListener(new OnClickListener()
{
@Override public void onClick(View v)
{ //發送Email: 郵箱地址,內容
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setType("text/plain");//模擬器,呵呵!這個真機上也是能夠的,不影響運行效果,可是會有一大堆的警告
intent.setType("message/rfc822"); //收件人:
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{editEmail.getText().toString()});
//EXTRA_CC(抄送)、EXTRA_BCC(密送)。
//intent.putExtra(Intent.EXTRA_CC, new String[]{"b@qq.com"});
// intent.putExtra(Intent.EXTRA_BCC, new String[]{"c@qq.com"});
//郵件標題:
intent.putExtra(Intent.EXTRA_SUBJECT, editTitle.getText().toString());
//郵件內容:
intent.putExtra(intent.EXTRA_TEXT, editContent.getText().toString());
//調用系統的郵件系統,能夠彈出全部的郵件系統供用戶選擇
startActivity(Intent.createChooser(intent, "請選擇郵件發送"));
}
}); List