m programming a caregiver app that involves barcode and qr code scanning for android. the main focus of the app is that it should only scan medication products. after it scans the meds full information should show, its name, information and should be saved in a folder on your phone to any specified location like gallery or anywhere. this is my code i have:
package com.example.testing;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void scanBar(View v){
try{
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}catch (ActivityNotFoundException e){
showDialog(MainActivity.this, "No Scanner Found",
"Download a scanner code activity?", "Yes", "No").show();
}
}
public void scanQR(View v){
try{
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}catch (ActivityNotFoundException e){
showDialog(MainActivity.this, "No Scanner Found",
"Download a scanner code activity?", "Yes", "No").show();
}
}
private static AlertDialog showDialog(final Activity act,
CharSequence title, CharSequence message,
CharSequence buttonYes,
CharSequence buttonNo) {
AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);
dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
@override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse("market://search?q=pname:" +
"com.google.zxing.client.android");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try{
act.startActivity(intent);
} catch(ActivityNotFoundException e){
}
}
}).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
@override
public void onClick(DialogInterface dialog, int which) {
}
});
return dowloadDialog.show();
}
@override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
if(requestCode == 0){
if(resultCode == RESULT_OK){
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast.makeText(this, "Content:" + contents + "Format:" + format,
Toast.LENGTH_LONG).show();
}
}
}
}
this is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
androidrientation="vertical"
tools:context="com.javacodegeeks.androidstartactivityforresultexample.ActivityOne" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_margin="20dp"
android:text="Scan"
android:textColor="#000000"
android:textSize="30dp" />
<Button
android:id="@+id/scanner"
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
androidnClick="scanQR"
android:text="QR Code"
android:textSize="18dp" >
</Button>
<Button
android:id="@+id/scanner2"
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
androidnClick="scanBar"
android:text="Bar Code"
android:textSize="18dp" >
</Button>
</LinearLayout>
Can someone help me with the focus of scanning for one specific product which is medications and medications only. other products that are not medicines should say invalid. Thank you
package com.example.testing;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void scanBar(View v){
try{
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}catch (ActivityNotFoundException e){
showDialog(MainActivity.this, "No Scanner Found",
"Download a scanner code activity?", "Yes", "No").show();
}
}
public void scanQR(View v){
try{
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}catch (ActivityNotFoundException e){
showDialog(MainActivity.this, "No Scanner Found",
"Download a scanner code activity?", "Yes", "No").show();
}
}
private static AlertDialog showDialog(final Activity act,
CharSequence title, CharSequence message,
CharSequence buttonYes,
CharSequence buttonNo) {
AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);
dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
@override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse("market://search?q=pname:" +
"com.google.zxing.client.android");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try{
act.startActivity(intent);
} catch(ActivityNotFoundException e){
}
}
}).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
@override
public void onClick(DialogInterface dialog, int which) {
}
});
return dowloadDialog.show();
}
@override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
if(requestCode == 0){
if(resultCode == RESULT_OK){
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast.makeText(this, "Content:" + contents + "Format:" + format,
Toast.LENGTH_LONG).show();
}
}
}
}
this is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
androidrientation="vertical"
tools:context="com.javacodegeeks.androidstartactivityforresultexample.ActivityOne" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_margin="20dp"
android:text="Scan"
android:textColor="#000000"
android:textSize="30dp" />
<Button
android:id="@+id/scanner"
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
androidnClick="scanQR"
android:text="QR Code"
android:textSize="18dp" >
</Button>
<Button
android:id="@+id/scanner2"
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
androidnClick="scanBar"
android:text="Bar Code"
android:textSize="18dp" >
</Button>
</LinearLayout>
Can someone help me with the focus of scanning for one specific product which is medications and medications only. other products that are not medicines should say invalid. Thank you