So I'm following tutorials and below is my code. I'm stuck trying to figure out what I need to with the data path. Does anyone have an example or suggestion on how to take the bitmap photo I took and get it loaded into tesseract to analyze? All help appreciated.
package com.example.cameraocr;
import java.io.File;
import com.googlecode.tesseract.android.TessBaseAPI;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private static ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView)this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
photoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
protected static void identifyunicode() {
// DATA_PATH = Path to the storage
// lang for which the language data exists, usually "eng"
File myDir = getExternalFilesDir(Environment.MEDIA_MOUNTED);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(myDir, "eng");
}
}
take a look at my example:
https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/NoteEditorActivity.java
What I did was call the camera, take a photo, get the photo and pass it to my OCRTask class (an AsyncTask) which calls the TessBaseAPI
public void callCamera() {
Log.d(TAG, "Starting camera...");
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, REQUEST_OCR);
}
https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/OCRTask.java
(A bit long if I post the entire OCRTask class code here, so just read it in Github, maybe?)
And handled the result afterwards
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/* bunch of other codes */
if (requestCode == REQUEST_OCR) {
if (resultCode == RESULT_OK) {
Bitmap x = (Bitmap) data.getExtras().get("data");
new OCRTask(this, x, this).execute();
}
}
}
I just added the text it recognized to my EditText
#Override
public void onFinishRecognition(String recognizedText) {
noteView.setText(noteView.getText() + " " + recognizedText);
}
Here are the classes
NoteEditor (calls the Camera intent)
OCRTask (calls the TessBaseApi, this is your main concern)
OCRCallback (Adds the text to my EditText after OCRTask finishes)
FileManager (util method)
Hope it helps.
Related
I found that my function of the app is not working for certain android phone.
I think maybe is the problem of android version? My app is working fine on an other Android phone, so how can I solve this issue?
public class StartActivity extends AppCompatActivity {
private Button btnupload,btnchoose;
private ImageView imgprofile;
Uri filepath;
private static final int PICK_IMAGE_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
btnchoose = (Button)findViewById(R.id.btn_addphoto);
btnupload = (Button)findViewById(R.id.btn_upload);
imgprofile = (ImageView)findViewById(R.id.imageView);
btnchoose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
chooseimage();
}
});
btnupload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
private void chooseimage() {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK) {
filepath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),filepath);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
Toast.makeText(StartActivity.this, "YES!", Toast.LENGTH_SHORT).show();
bitmap = Bitmap.createScaledBitmap(bitmap, imgprofile.getWidth(),imgprofile.getHeight(),true);
imgprofile.setImageBitmap(bitmap);
} else {
Toast.makeText(StartActivity.this, "YES!!!!", Toast.LENGTH_SHORT).show();
imgprofile.setImageBitmap(bitmap);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
I run my app on the phone which is version 5.0.2 it does not show any response of toast.
This is the code works for me. I just change the position of the function, the code still the same.
package com.example.user8.letseat;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.io.IOException;
import java.util.UUID;
public class StartActivity extends AppCompatActivity {
private Button btnupload,btnchoose;
private ImageView imgprofile;
Uri filepath;
private static final int PICK_IMAGE_REQUEST = 1;
FirebaseStorage firebaseStorage;
StorageReference storageReference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
firebaseStorage = FirebaseStorage.getInstance();
storageReference = firebaseStorage.getReference();
btnchoose = (Button)findViewById(R.id.btn_addphoto);
btnupload = (Button)findViewById(R.id.btn_upload);
imgprofile = (ImageView)findViewById(R.id.imageView);
btnchoose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
}
});
btnupload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
uploadimage();
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK)
{
filepath = data.getData();
try
{
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),filepath);
imgprofile.setImageBitmap(bitmap);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
private void uploadimage() {
if (filepath != null)
{
final ProgressDialog pg = new ProgressDialog(this);
pg.setTitle("Uploading...");
pg.show();
StorageReference ref = storageReference.child("image/" + UUID.randomUUID().toString());
ref.putFile(filepath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
pg.dismiss();
DatabaseReference databaseReference ;
databaseReference= FirebaseDatabase.getInstance().getReference("Imageeee");
String ImageUploadId = databaseReference.push().getKey();
String imageurl = taskSnapshot.getDownloadUrl().toString();
// Adding image upload id s child element into databaseReference.
databaseReference.child(ImageUploadId).setValue(imageurl);
Toast.makeText(StartActivity.this, "FINISH", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
pg.dismiss();
Toast.makeText(StartActivity.this, "FAIL"+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
pg.setMessage("Uploaded" + (int)progress+"%");
}
});
}
}
}
MyActivity.xml
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_x="13dp"
android:layout_y="112dp" />
MainActivity.java
public class MainActivityextends Activity {
Button imageUpload;
ImageView imageView;
static final int PICTURE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView= (ImageView) findViewById(R.id.imageView);
imageUpload= (Button) findViewById(R.id.buttonImage);
imageUpload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,PICTURE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==PICTURE && resultCode==RESULT_OK && null !=data)
{
Uri uri = data.getData();
String[] prjection ={MediaStore.Images.Media.DATA};
Cursor cursor=getContentResolver().query(uri,prjection,null,null,null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(prjection[0]);
String path=cursor.getString(columnIndex);
cursor.close();
Bitmap selectFile = BitmapFactory.decodeFile(path);
Drawable d = new BitmapDrawable(selectFile);
imageView.setBackground(d);
// imageView.setImageBitmap(BitmapFactory.decodeFile(path));
}
}
}
Check Simple code of get image from gallery and display hopr this may help you.
Example
This is my document.java code. when i capture image its shown conformation. when i get conformation ,image showed in ImageView. Before conformation i want crop the image. And also i want crop option for image from gallery(import from internal storage).
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import java.io.IOException;
import static com.dk.deepan.salvador.R.id.img;
public class Document extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
private int PICK_IMAGE_REQUEST = 1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document);
//first edittext
EditText txtDate =(EditText)findViewById(R.id.issue);
txtDate.setOnClickListener (new View.OnClickListener () {
#Override
public void onClick(View v) {
DateDialog dialog=new DateDialog(v);
FragmentTransaction ft =getFragmentManager().beginTransaction();
dialog.show(ft, "DatePicker");
}
});
//second edittext
EditText txtDate2 =(EditText)findViewById(R.id.expiry);
txtDate2.setOnClickListener (new View.OnClickListener(){
#Override
public void onClick(View v) {
DateDialog dialog=new DateDialog(v);
FragmentTransaction ft =getFragmentManager().beginTransaction();
dialog.show(ft, "DatePicker");
}
});
//take a photo
this.imageView = (ImageView)this.findViewById(img);
Button photoButton = (Button) this.findViewById(R.id.camera);
photoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
//Attach file
Button imageView = (Button) findViewById(R.id.attachfile);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
//spinner for select document
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.document_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//take photo
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
} else if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
// Log.d(TAG, String.valueOf(bitmap));
ImageView imageView = (ImageView) findViewById(R.id.img);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
https://github.com/jdamcd/android-crop
please follow above url for crop
I have a problem. I got a simple clicker here, but the "upgraded clicks per tap" are not transferred to the other activity. I don't know why it is not working.
Code as below :
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
public static final int REQUEST_CODE_CURRENTCLICKS = 10;
public int amountClicks = 0;
public int incrementAmount = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnClick = (Button) findViewById(R.id.btnClick);
final TextView tvAmountClicks = (TextView) findViewById(R.id.tvAmoutClicks);
Button btnShop = (Button) findViewById(R.id.btnShop);
amountClicks = getIntent().getIntExtra("currentClicks", 0);
incrementAmount = getIntent().getIntExtra("upgradedClicks", 1);
tvAmountClicks.setText(""+amountClicks);
btnClick.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
amountClicks += incrementAmount;
tvAmountClicks.setText(""+amountClicks);
}
});
btnShop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),ShopActivity.class);
intent.putExtra("currentClicks",amountClicks);
startActivityForResult(intent, REQUEST_CODE_CURRENTCLICKS);
}
});
}
}
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ShopActivity extends AppCompatActivity {
public int currentClicks;
public int incrementAmount;
public int upgradedClicks;
public int upgradeCost = 10;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop);
currentClicks = getIntent().getIntExtra("currentClicks",0);
final TextView tvCurrentClicks = (TextView) findViewById(R.id.tvCurrentClicks);
tvCurrentClicks.setText(""+currentClicks);
Button btnUpgrade = (Button) findViewById(R.id.btnUpgrade);
btnUpgrade.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(upgradeCost > currentClicks)
{
Context context = getApplicationContext();
CharSequence text = "You don't have enough Clicks";
int duration = Toast.LENGTH_SHORT;
Toast cantUpgrade = Toast.makeText(context, text,duration);
cantUpgrade.show();
}
else
{
currentClicks -= upgradeCost;
upgradedClicks++;
tvCurrentClicks.setText(""+ currentClicks);
}
Intent intent = new Intent();
intent.putExtra("currentClicks",currentClicks);
intent.putExtra("upgradedClicks",upgradedClicks);
setResult(RESULT_OK, intent);
}
});
}
}
If I return back to the main activity, it doesnt return the "upgraded clicks" nor the "current clicks".
You have startActivityForResult therefore you need to implement onActivityResult
So, you have this code
Intent intent = new Intent();
intent.putExtra("currentClicks",currentClicks);
intent.putExtra("upgradedClicks",upgradedClicks);
setResult(RESULT_OK, intent);
finish(); // Add finish() to end this Activity
And that would go back to the calling Activity where you check the request code.
public class MainActivity extends AppCompatActivity {
public static final int REQUEST_CODE_CURRENTCLICKS = 10;
public int amountClicks = 0;
private TextView tvAmountClicks;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == REQUEST_CODE_CURRENTCLICKS) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
amountClicks = data.getIntExtra("currentClicks", 0);
int upgradedClicks = data.getIntExtra("upgradedClicks", 1);
tvAmountClicks.setText(""+amountClicks);
}
}
}
Android | Getting the result of an Activity
You should override the MainActivity's onResume() method to refresh your data.
EDIT try this one
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if(resultCode == RESULT_OK){
amountClicks = getIntent().getIntExtra("currentClicks", 0);
incrementAmount = getIntent().getIntExtra("upgradedClicks", 1);
tvAmountClicks.setText(""+amountClicks);
}
}
}
I am trying to create an Android App that can listen to various commands and respond to it accordingly. for e.g, if i press mic and say "open whatsapp", it does it.
Question is How do i open Various apps with limited coding?
following code is to open whatsapp, but if i had to open other various app, Do i need to write same IF Statement for various apps?? wont it be too lenghty?
please provide a better solution.
package example.bot;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;
public class MainActivity extends Activity {
private TextView txtSpeechInput;
private ImageButton btnSpeak;
private final int REQ_CODE_SPEECH_INPUT = 1234;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeechInput = (TextView) findViewById(R.id.txtSpeechInput);
btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
promptSpeechInput();
}
});
}
/**
* Showing google speech input dialog
* */
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
/**
* Receiving speech input
* */
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (result.size() == 0) {
} else {
String mostLikelyThingHeard = result.get(0);
// toUpperCase() used to make string comparison equal
if (mostLikelyThingHeard.toUpperCase().equals("OPEN WHATSAPP")) {
//informationMenu();
txtSpeechInput.setText(result.get(0));
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.whatsapp");
//if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
} //else if()
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
//private void informationMenu() {
// Intent intent = new Intent(this, open_app.class);
// startActivity(intent);
//}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
So using suggestions from the last question I asked, I figured out how to call BarCodeScanner, and return the value to a field. so now, I have a toast that says "successful scan" and then I want to pass the result to a new activity. when I comment out my intent, everything works (minus the passing of data/switching of screen, obviously) but when I run my project as is, it FC's... no errors reported by eclipse in code or XML. Any insights?
package com.mhe.test.scan;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class main extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button myScanButton = (Button) findViewById(R.id.myScanButton);
totalbox = (EditText) findViewById(R.id.tBox);
myScanButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}
});
}
private EditText totalbox;
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
final String contents = intent.getStringExtra("SCAN_RESULT");
if ( totalbox != null )
totalbox.setText(contents);
Context context = getApplicationContext();
CharSequence text = "Successful Scan";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Intent i = new Intent(main.this, Result.class);
i.putExtra("SNARP", "SCAN_RESULT");
startActivityForResult(i, 0);
} else if (resultCode == RESULT_CANCELED) {
if ( totalbox != null )
totalbox.setText("bummer");
}
}
}
}
And then to handle the data being passed, in the new activity:
package com.mhe.test.scan;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Result extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Intent i = getIntent();
Bundle b = i.getExtras();
String foosh = b.getString("SNARP");
EditText box1 = (EditText) findViewById(R.id.tBox1);
box1.setText(foosh);
Try sending a Bundle object when calling the new intent.
Intent i = new Intent(main.this, Result.class);
Bundle b = new Bundle();
b.putString("SNARP", "SCAN_RESULT")
i.putExtras(b);
Try getting string in the child Activity this way.
public class Result extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Intent i = getIntent();
String foosh = i.getStringExtra("SNARP");