2017-03-16 66 views
0

我用我的應用程序斑馬線庫...下面的代碼工作的片段罰款並顯示在開展活動的片段添加我下面的代碼result..problem .. 對時間它不顯示掃描result..can誰能告訴我斑馬線庫不顯示在片段活動掃描結果

button = (Button) view.findViewById(R.id.zing); 

    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent("com.journeyapps.barcodescanner.CaptureActivity"); 
      intent.putExtra("SCAN_MODE", "PRODUCT_MODE"); 
      startActivityForResult(intent,0); 


     } 
    }); 

    public void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if (requestCode == 0) { 
     if (resultCode == Activity.RESULT_OK) { 
      String contents = data.getStringExtra("SCAN_RESULT"); 


      // Handle successful scan 
      Toast toast = Toast.makeText(getActivity(), "Content:" + contents, Toast.LENGTH_LONG); 
      toast.show(); 

     } else if (resultCode == Activity.RESULT_CANCELED) { 
      // Handle cancel 
      Toast toast = Toast.makeText(getActivity(), " Cancelled", Toast.LENGTH_SHORT); 
      toast.show(); 

     } 
     } 
    else 
    super.onActivityResult(requestCode, resultCode, data); 
} 
+0

片段添加此代碼不甲肝e onActivityResult,因此您可以在其中創建或附加片段,並在其中添加onActivityResult和其他句柄。 – CrazyMind

回答

1

試試這個,對我的工作

在主要活動

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     try { 
       for (Fragment fragment : getSupportFragmentManager().getFragments()) { 
       fragment.onActivityResult(requestCode, resultCode, data); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    }