当我尝试从 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");
}
}
}