需要幫助...我正在研究Android中的音譯,它需要API_KEY,但由於我是Android新手,我不知道如何獲取API_KEY,任何人都可以告訴我,我必須做些什麼才能獲得API_KEY ...?提前致謝...!! 以下是我的代碼片斷---如何在Android中獲取API_KEY音譯
public class MainActivity extends Activity
{
EditText myInputText;
Button myTranslateButton;
TextView myOutputText;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myInputText = (EditText)findViewById(R.id.inputText);
myTranslateButton = (Button)findViewById(R.id.translateButton);
myOutputText = (TextView)findViewById(R.id.outputText);
myTranslateButton.setOnClickListener(MyTranslateButtonOnClickListener);
}
private Button.OnClickListener MyTranslateButtonOnClickListener
= new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
String InputString;
String OutputString = null;
InputString = myInputText.getText().toString();
try
{
GoogleAPI.setHttpReferrer("http:\\www.google.com");
**// Here I need API_KEY**
**GoogleAPI.setKey(" API KEY");**
OutputString = Translate.DEFAULT.execute(InputString,Language.ENGLISH, Language.HINDI);
}
catch (Exception ex)
{
ex.printStackTrace();
OutputString = "Error";
}
Typeface customF = Typeface.createFromAsset(getAssets(), "akshar.ttf");
//final TextView textV = (TextView) findViewById(...);
myOutputText.setTypeface(customF);
myOutputText.setText(OutputString);
}
};
}
非常感謝@Swapneel Kondgule ..很不錯的答案。再次謝謝..! – 2013-05-03 11:04:19