解决: FAILED BINDER TRANSACTION
(2014-10-11 17:06:08)
标签:
it |
分类: Android |
二维码扫描时,报: FAILED BINDER TRANSACTION ,
致使扫描的activity退不出去。查了下资料,是barcode这个bitmap太大造成的。
public
void handleDecode(Result result, Bitmap barcode) {
inactivityTimer.onActivity();
playBeepSoundAndVibrate();
String resultString = result.getText();
if (resultString.equals("") ||
resultString.length() < 11) {
Toast.makeText(LoginActivityCapture.this, "扫描失败请重试",
Toast.LENGTH_SHORT).show();
Intent
resultIntent = new Intent();
Bundle
bundle = new Bundle();
bundle.putString("result", "");
this.setResult(RESULT_OK, resultIntent);
LoginActivityCapture.this.finish();
} else {
MixLog.i(Macro.DEBUG_TAG, "*******scan code result:" +
resultString);
boolean
conUUid = resultString.contains("uuid=");
Intent
resultIntent = new Intent();
Bundle
bundle = new Bundle();
if
(conUUid) {
String resultTmp[] =
resultString.split("uuid=");
if (resultTmp.length > 1)
{
resultIntent.setAction(Macro.broadcast_scan_qc);
bundle.putString("result", resultTmp[1]);
resultIntent.putExtras(bundle);
this.sendBroadcast(resultIntent);
MixLog.i(Macro.DEBUG_TAG, "*******scan code
result:"
+ resultTmp[1]);
LoginActivityCapture.this.finish();
} else {// uuid为空
Toast.makeText(LoginActivityCapture.this,
"二维码无效请退出电视客户端重试",
Toast.LENGTH_SHORT).show();
LoginActivityCapture.this.finish();
}
} else
{
bundle.putString("result",
resultString);
bundle.putParcelable("bitmap", barcode);
resultIntent.putExtras(bundle);
this.setResult(RESULT_OK,
resultIntent);
String mobileNum =
resultString.substring(
resultString.length() - 11, resultString.length());
MixLog.i(Macro.DEBUG_TAG,
"*******scan code result:" + mobileNum);
// skip to san result
activity page
searchProfileByMobileNum(mobileNum);
// finish();
}
}
}
public void handleDecode(Result result,
Bitmap barcode) {
Bitmap tempCode =
barcode;
MixLog.d("Tomlog",
String.valueOf(barcode.getByteCount()));
MixLog.d("Tomlog",
String.valueOf(barcode.getWidth()));
MixLog.d("Tomlog",
String.valueOf(barcode.getHeight()));
barcode
=scaleDownBitmap(tempCode, 64, getApplicationContext());
MixLog.d("Tomlog",
String.valueOf(barcode.getByteCount()));
MixLog.d("Tomlog",
String.valueOf(barcode.getWidth()));
MixLog.d("Tomlog",
String.valueOf(barcode.getHeight()));
inactivityTimer.onActivity();
playBeepSoundAndVibrate();
String resultString = result.getText();
if (resultString.equals("") ||
resultString.length() < 11) {
Toast.makeText(LoginActivityCapture.this, "扫描失败请重试",
Toast.LENGTH_SHORT).show();
Intent
resultIntent = new Intent();
Bundle
bundle = new Bundle();
bundle.putString("result", "");
this.setResult(RESULT_OK, resultIntent);
LoginActivityCapture.this.finish();
} else {
MixLog.i(Macro.DEBUG_TAG, "*******scan code result:" +
resultString);
boolean
conUUid = resultString.contains("uuid=");
Intent
resultIntent = new Intent();
Bundle
bundle = new Bundle();
if
(conUUid) {
String resultTmp[] =
resultString.split("uuid=");
if (resultTmp.length > 1)
{
resultIntent.setAction(Macro.broadcast_scan_qc);
bundle.putString("result", resultTmp[1]);
resultIntent.putExtras(bundle);
this.sendBroadcast(resultIntent);
MixLog.i(Macro.DEBUG_TAG, "*******scan code
result:"
+ resultTmp[1]);
LoginActivityCapture.this.finish();
} else {// uuid为空
Toast.makeText(LoginActivityCapture.this,
"二维码无效请退出电视客户端重试",
Toast.LENGTH_SHORT).show();
LoginActivityCapture.this.finish();
}
} else
{
bundle.putString("result",
resultString);
bundle.putParcelable("bitmap", barcode);
resultIntent.putExtras(bundle);
this.setResult(RESULT_OK,
resultIntent);
String mobileNum =
resultString.substring(
resultString.length() - 11, resultString.length());
MixLog.i(Macro.DEBUG_TAG,
"*******scan code result:" + mobileNum);
// skip to san result
activity page
searchProfileByMobileNum(mobileNum);
// finish();
}
}
}
public static Bitmap
scaleDownBitmap(Bitmap photo, int newHeight, Context context)
{
final float
densityMultiplier =
context.getResources().getDisplayMetrics().density;
int h= (int)
(newHeight*densityMultiplier);
int w= (int) (h *
photo.getWidth()/((double) photo.getHeight()));
photo=Bitmap.createScaledBitmap(photo, w, h, true);
return photo;
}
引用:
今天在做一个widget的时候需要填充一个ImageView,图片来自与网络。 发现都会出现FAILED Binder
Transaction这个问题。 通过google得知,原来图片的size不能超过40k。
Activity中ImageView是不会出现这个问题, 但是Widget使用的是remoteViews。
Intent传输的bytes不能超过40k。
原来代码:
改后:
mark一下,留给有用的兄弟。