当我尝试从onActivityResult启动套接字时,它总是超时...我试图做的是启动从onActivityResult启动套接字连接的Activity但没有成功,但是当套接字从某处开始没有问题时否则不会从onActivityResult调用。这是我调用startActivityForResult和onActivityResult的代码。我很确定我做错了......任何推动正确的方向?
public void scanNow(View view){
Intent intent = new Intent("com.blah.Blah.client.android.SCAN");
intent.putExtra("com.blah.Blah.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
Log.d("debug tag", "started activity");
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
Log.d("debug tag", "inside onActivityResult");
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("debug tag", "contents: "+contents+" format: "+format);
Intent myIntent = new Intent(com.blah.Blah.Ads);
startActivity(myIntent);
// Handle successful scan
}
else if (resultCode == RESULT_CANCELED)
{
// Handle cancel
Log.i("debug tag", "Cancelled from main");
}
}
}
答案 0 :(得分:0)
如果您发布的实际代码不起作用,也许有人可以帮助您。 连接有效的“其他地方”是什么?你在相同的设备,应用程序,活动中尝试过吗?这两个地方的代码完全相同吗?
检查这些: