Last active
January 26, 2019 04:20
-
-
Save anta40/02485e49ea648a86855419012a73f037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Intent; | |
import android.support.annotation.Nullable; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import com.google.zxing.integration.android.IntentIntegrator; | |
import com.google.zxing.integration.android.IntentResult; | |
public class ScanActivity extends AppCompatActivity { | |
private DatabaseHelper db; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_scan); | |
db = new DatabaseHelper(this); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
IntentIntegrator scanIntegrator = new IntentIntegrator(ScanActivity.this); | |
scanIntegrator.setOrientationLocked(false); | |
scanIntegrator.initiateScan(); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); | |
if (scanningResult != null){ | |
String scanContent = scanningResult.getContents(); | |
String[] data = parseContent(scanContent); | |
db.addItem(new Item(data[0], data[1], data[2]); | |
Intent iii = new Intent(ScanActivity.this, ScanResultActivity.class); | |
startActivity(iii); | |
} | |
} | |
@Override | |
public void onBackPressed() { | |
moveTaskToBack(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment