2017-09-26 25 views
0

안녕하세요. 내 첫 번째 질문입니다. 여기 상황 : 바코드를 스캔하기 위해 특정 버튼이있는 의상 softkeyboard를 작업 중이며, 바코드 스캐너를 엽니 다. 스캔을하면 클립 또는 공유 미리보기의 결과와 함께 이전 화면으로 돌아갑니다 (메시징 앱). 첫 번째 활동이 결과를 얻었을 때 (바코드 스캐너 활동을 시작하기 전에) 스캔이 완료되지 않았기 때문에 EditText의 결과가 새 것이 아닌 이전 스캔의 결과라는 사실을 제외하고는 모두 훌륭하고 멋쟁이입니다. 완료 스캔을 기다릴 부울 테스트와 주요 기능에에 handler.postDelayed를 만들려고 노력하지만 내가 키 기능에 오류 응답하지 얻을 결과로 스캔을 시작하기 전에 활동을 동결하는 것입니다 :바코드를 스캔하여 결과를 EditText에 삽입하는 사용자 정의 키보드

case 2017: 
      //Toast.makeText(FloatingViewService.this, "NormalScan.", Toast.LENGTH_LONG).show(); 
      test=true; 
      InputConnection ic = getCurrentInputConnection(); 
      ic.deleteSurroundingText(100, 100); //pour vider le champs de saisair 
      Intent dialogIntent = new Intent(SimpleIME.this, NormalScan.class); 
      dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(dialogIntent); 
      ic.commitText(String.valueOf(pref.getString("code", null)),1); 
바코드를 스캔 할 수

NormalScan.class은 다음과 같습니다 활동 WI

public class NormalScan extends AppCompatActivity { 

    private ClipboardManager myClipboard; 
    private ClipData myClip; 

    @Override 

    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 


     IntentIntegrator integrator = new IntentIntegrator(this); 
     // integrator.setOrientationLocked(false); 
     integrator.setPrompt("Scan a barcode or QRcode"); 
     integrator.initiateScan(); 


     // integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES); 
//  Use this for more customization 
//integrator.setOrientationLocked(true); 
//  IntentIntegrator integrator = new IntentIntegrator(this); 

//  integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES); 

//  integrator.setPrompt("Scan a barcode"); 

//  integrator.setCameraId(0); // Use a specific camera of the device 

//  integrator.setBeepEnabled(false); 

//  integrator.setBarcodeImageEnabled(true); 

//  integrator.initiateScan(); 

    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
     Iconify 
       .with(new FontAwesomeModule()) 
       .with(new EntypoModule()) 
       .with(new TypiconsModule()) 
       .with(new MaterialModule()) 
       .with(new MaterialCommunityModule()) 
       .with(new MeteoconsModule()) 
       .with(new WeathericonsModule()) 
       .with(new SimpleLineIconsModule()) 
       .with(new IoniconsModule());//// toast library 

     SharedPreferences prefs = getSharedPreferences("my_prefs", MODE_WORLD_READABLE); 
     SharedPreferences.Editor editor = prefs.edit(); 

     if (result != null) { 
      if (result.getContents() == null) { 
       // Toast.makeText(this, "Opération annulée", Toast.LENGTH_LONG).show(); 
       //PrettyToast.showError(getApplicationContext(), "Opération annulée"); 
       new PrettyToast.Builder(getApplicationContext()) 
         .withMessage(" Opération annulée ✘ ") // ☑ ☒ ☓ ✓ ✓ ✕ ✖ ✗ ✘ 
         .withDuration(Toast.LENGTH_SHORT) 
         .withGravity(new PrettyToast.Gravity(Gravity.BOTTOM, 15, 0)) 
         .withTextSize(24) 
         .withBackgroundResource(R.drawable.background_toast_red) 
         .withTextColor(R.color.white) 
         .build() 
         .show(); 
       //myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE); 
       //String a = new String(); 
       //a=result.getContents(); 
       // myClip = ClipData.newPlainText("text","Scan Echouer"); 
       // myClipboard.setPrimaryClip(myClip); 
       final Handler handler = new Handler(); 
       handler.postDelayed(new Runnable() { 
        @Override 
        public void run() { 
         //Do something after 100ms 

         handler.postDelayed(this, 2000); 
        } 
       }, 1500); 
       finish(); 
       setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
       //editor.putString("message", "annulée"); 
       //editor.putString("code", a); 
       //editor.commit(); 
      } else { 
       myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
       String a = new String(); 
       a = result.getContents(); 
       myClip = ClipData.newPlainText("text", a); 
       myClipboard.setPrimaryClip(myClip); 
       //PrettyToast.showSuccess(getApplicationContext(), "Le codebar sauvegarder dans la presse papier","",""); 
       new PrettyToast.Builder(getApplicationContext()) 
         .withMessage(" Scanned ✓ ") //☑ ✓ 
         .withDuration(Toast.LENGTH_SHORT) 
         .withGravity(new PrettyToast.Gravity(Gravity.BOTTOM, 15, 0)) 
         .withTextSize(24) 
         .withBackgroundResource(R.drawable.background_toast_green) 
         .withTextColor(R.color.white) 
         .build() 
         .show(); 
       //Toast.makeText(getApplicationContext(), "Le codebar sauvegarder dans la presse papier",Toast.LENGTH_SHORT).show(); 


       finish(); 
       editor.putString("message", "codebarre"); 
       editor.putString("code", a); 
       editor.putBoolean("testscan", true); 
       editor.commit(); 
       // show keybord 

        // InputMethodManager imm = (InputMethodManager) getSystemService(SimpleIME.INPUT_METHOD_SERVICE); 
        // imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); 


      } 
     } 
     else { 
      // This is important, otherwise the result will not be passed to the fragment 
      super.onActivityResult(requestCode, resultCode, data); 

      finish(); 
     } 

    } 
} 

답변

1

시작 startActivityForResult입니다. onActivityResult가 호출되면 바코드를 저장합니다. inputConnection가 확정되는 다음 번에이 그냥 코드를 조금 수정 글고

Intent intent = new Intent(getBaseContext(), SignoutActivity.class); 
intent.putExtra("EXTRA_SESSION_ID", sessionId); 
startActivity(intent); 
Access that intent on next activity 

String s = getIntent().getStringExtra("EXTRA_SESSION_ID"); 

같은 주요