如何在android中创建音频验证码? 我想在android.But音频验证码我无法得到任何与audi验证码相关的代码。我正在使用recaptcha在我的Android应用程序中创建验证码。以类似的方式我也想要基于音频的验证码。但是无法获得基于音频的captcha ???或如何验证文本??
我尝试了以下代码:
public class CaptchaActivity extends ActionBarActivity implements OnClickListener, OnVerifyAnswerListener, OnShowChallengeListener{
private static final String PUBLIC_KEY = "6LcPWugSAAAAAC-MP5sg6wp_CQiyxHvPvkQvVlVf";
private static final String PRIVATE_KEY = "6LcPWugSAAAAALWMp-gg9QkykQQyO6ePBSUk-Hjg";
private ReCaptcha reCaptcha;
private ProgressBar progress;
private EditText answer;
private ActionBar actionbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_captcha);
getActionBarHeader();
speech();
this.reCaptcha = (ReCaptcha)this.findViewById(R.id.recaptcha);
this.progress = (ProgressBar)this.findViewById(R.id.progress);
this.answer = (EditText)this.findViewById(R.id.answer);
this.findViewById(R.id.imageView1).setOnClickListener(this);
this.findViewById(R.id.imageView2).setOnClickListener(this);
this.showChallenge();
}
private void getActionBarHeader() {
// TODO Auto-generated method stub
actionbar = getSupportActionBar();
actionbar.setDisplayShowHomeEnabled(false);
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setHomeButtonEnabled(true);
actionbar.setBackgroundDrawable(new ColorDrawable(getResources()
.getColor(R.color.blue)));
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.maintitle, null);
TextView header = (TextView) mCustomView.findViewById(R.id.apptitle);
header.setText(Html
.fromHtml("<font color=#ffffff>REGISTER</font>"));
actionbar.setCustomView(mCustomView);
actionbar.setDisplayShowCustomEnabled(true);
}
@Override
public void onChallengeShown(final boolean shown) {
this.progress.setVisibility(View.GONE);
if (shown) {
// If a CAPTCHA is shown successfully, displays it for the user to enter the words
this.reCaptcha.setVisibility(View.VISIBLE);
} else {
Toast.makeText(this, "error", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnswerVerified(final boolean success) {
if (success) {
Toast.makeText(this, "verification_success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,"verification_failed", Toast.LENGTH_SHORT).show();
}
// (Optional) Shows the next CAPTCHA
this.showChallenge();
}
private void showChallenge() {
// Displays a progress bar while downloading CAPTCHA
this.progress.setVisibility(View.VISIBLE);
this.reCaptcha.setVisibility(View.GONE);
this.reCaptcha.showChallengeAsync(CaptchaActivity.PUBLIC_KEY, this);
}
private void verifyAnswer() {
if (TextUtils.isEmpty(this.answer.getText())) {
Toast.makeText(this, "instruction", Toast.LENGTH_SHORT).show();
} else {
// Displays a progress bar while submitting the answer for verification
this.progress.setVisibility(View.VISIBLE);
this.reCaptcha.verifyAnswerAsync(CaptchaActivity.PRIVATE_KEY, this.answer.getText().toString(), this);
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.imageView2:
// this.verifyAnswer();
// speech();
if(result==TextToSpeech.LANG_NOT_SUPPORTED||result==TextToSpeech.LANG_MISSING_DATA){
Toast.makeText(CaptchaActivity.this, "device not suippporttedd", 500).show();
}
else{
speeches.speak("kallyani i am",TextToSpeech.QUEUE_FLUSH, null);
}
break;
case R.id.imageView1:
this.showChallenge();
break;
}
}
TextToSpeech speeches;
int result;
private void speech() {
// TODO Auto-generated method stub
speeches=new TextToSpeech(CaptchaActivity.this,new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status==TextToSpeech.SUCCESS){
result=speeches.setLanguage(Locale.ENGLISH);
}
else{
Toast.makeText(CaptchaActivity.this, "device not suippporttedd", 500).show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.captcha, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}