我想在我的應用程序中執行驗證碼。在我最初的分析後,我發現他們大多數人推薦使用'Simplcaptcha'。我給了它一個鏡頭。但我的努力是徒勞的。 'simplecaptcha'的輸出是一個AWT組件。所以它不能用於Android。有什麼方法可以通過任何轉換的方式在Android中使用它,或者是否有任何其他可用的良好庫?如果有的話,任何人都可以指導我一個很好的文檔或例子。這對我來說是一個很大的幫助。如何在Android中實現驗證碼
0
A
回答
0
一個非常容易使用,最少的選項,設備上的驗證碼Android應用程序系統REFER
1
您可以使用下面的自定義視圖顯示了根據您的需求captcha
(調一樣,如果你想有alphanumeric captcha
或你想要一個skewed captcha
)
public class CaptchaView extends ImageView {
private Paint mPaint;
private static String mCaptchaAsText;
public CaptchaView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public CaptchaView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CaptchaView(Context context) {
super(context);
init();
}
private void init() {
mPaint = new Paint();
mPaint.setColor(Color.BLACK);
initCaptcha();
}
private static void initCaptcha() {
mCaptchaAsText = "";
for (int i = 0; i < 4; i++) {
int number = (int) (Math.random() * 10);
mCaptchaAsText += number;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int desiredWidth = 300;
int desiredHeight = 80;
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int width;
int height;
// Measure Width
if (widthMode == MeasureSpec.EXACTLY) {
// Must be this size
width = widthSize;
} else if (widthMode == MeasureSpec.AT_MOST) {
// Can't be bigger than...
width = Math.min(desiredWidth, widthSize);
} else {
// Be whatever you want
width = desiredWidth;
}
// Measure Height
if (heightMode == MeasureSpec.EXACTLY) {
// Must be this size
height = heightSize;
} else if (heightMode == MeasureSpec.AT_MOST) {
// Can't be bigger than...
height = Math.min(desiredHeight, heightSize);
} else {
// Be whatever you want
height = desiredHeight;
}
// MUST CALL THIS
setMeasuredDimension(width, height);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setTextSize(getMeasuredHeight());
canvas.drawText(mCaptchaAsText,
((canvas.getWidth() - mPaint.measureText(mCaptchaAsText))/2),
getMeasuredHeight(), mPaint);
}
public static boolean match(String value) {
if (value.equals(mCaptchaAsText)) {
return true;
} else {
if (value != null && value.length() > 0)
initCaptcha();
return false;
}
}
}
相關問題
- 1. 如何實現鍵值編碼驗證
- 2. 在Flash中實現驗證碼
- 3. 在ipad中實現驗證碼
- 4. 在GWT-Ext 2.0.3中實現驗證碼
- 5. 如何在AngularJS中實現驗證
- 6. 如何在iphone中實現驗證碼變化sdk
- 7. 如何在CakePHP 2.0中實現驗證碼?
- 8. 如何在android中實現電子郵件驗證功能
- 9. 在MVC中實現驗證
- 10. 在PORO中實現驗證
- 11. Angular JS中的驗證碼實現
- 12. 錯誤在asp.net驗證碼實現
- 13. 如何在android中實現jsp代碼?
- 14. 如何在joomla管理員面板上實現驗證碼?
- 15. 首先在實體框架代碼中實現數據驗證
- 16. 谷歌驗證碼V2實現VB.net
- 17. 自定義IUser實現 - 驗證密碼
- 18. 易於使用codeigniter實現驗證碼?
- 19. 爲zf2實現密碼驗證器
- 20. 如何實現ASP.Net Forms身份驗證
- 21. 如何驗證python的IOBase的實現?
- 22. 如何實現身份驗證?
- 23. 如何實現短信驗證註冊?
- 24. 如何實現MVC3模型URL驗證?
- 25. 如何實現WebServiceHost身份驗證?
- 26. wcf如何實現其身份驗證?
- 27. 如何使用ASP.Net WebForm(bassistance.de表單驗證)在MasterPage中實現表單驗證
- 28. Ember驗證如何實現延遲驗證
- 29. 如何在android studio上實現代碼?
- 30. 如何在驗證出現
我怎樣才能重新加載此驗證碼?我怎樣才能使用它作爲字母數字captcha? –
檢查此http://stackoverflow.com/a/41218856/6295668 –