use new String(byte[])
instead of toString()
:
Toast.makeText(getApplicationContext(),new String(pattern),
Toast.LENGTH_LONG).show();
Вопрос
I am using the android lock pattern library for a project of mine when I print the output pattern in a toast I get all garbage values like [C245faa3a8
I got the library and the code from https://code.google.com/p/android-lockpattern/
here is my code.
public class PatternTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// This is your preferred flag
Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN,
null, getBaseContext(), LockPatternActivity.class);
startActivityForResult(intent, REQ_CREATE_PATTERN);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
char[] pattern = null;
switch (requestCode) {
case REQ_CREATE_PATTERN: {
if (resultCode == RESULT_OK) {
pattern = data
.getCharArrayExtra(LockPatternActivity.EXTRA_PATTERN);
}
break;
}// REQ_CREATE_PATTERN
}
Toast.makeText(getApplicationContext(),pattern.toString(),
Toast.LENGTH_LONG).show();
}
}
Решение
use new String(byte[])
instead of toString()
:
Toast.makeText(getApplicationContext(),new String(pattern),
Toast.LENGTH_LONG).show();