I followed instructions from the official zxing website and created an application using the following code. I tried to send the signed .apk file to my Samsung GSII for testing. The program stopped immediately after I clicked on the application's icon.
I am really sorry for my poor description and wordings.
Instead of using the embedded method,I finally used the IntentIntegrator for the program, as embedded one is too hard for me to understand.
Now I am facing another issue. I have wrote an onClick Method with the following statements:
public void Button1(View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
EditText editText2 = (EditText) findViewById(R.id.editText2);
editText2.setText(a);
}
How can I change the code so that it waits until the initiateScan() method finished before the setText() method operate? Actually I would like to use the returned result from initiateScan() as a condition.
Thanks again!
You don't wait for initiateScan() to finish. This function invokes the Barcode Scanner application. You wait for the result instead by implementing onActivityResult() in your app. This is documented in the wiki and in the javadoc. Did you read any of that, at all?
Related
How do I make my Text-To-Speech stop speaking? Right now, my TTS will start speaking when I launch my application, but I'm trying to make it stop speaking when a button on my Main Activity is pressed.
I have tried creating an onStop() method and using .stop, but to no avail.
May I please get some help on this issue?
You could do something along the lines of this ...
stopSpeakingButton.setOnClickListener(new
View.OnClickListener() {
String toSpeak = " ";
textToSpeech.speak(
toSpeaks,TextToSpeech.QUEUE_FLUSH,null);
});
As you gave us no code this a concept , not the most beautiful solution but will work if you adjust for your use case, the idea is to make it read string with onny a space in it!
We noticed the Pin It button is no longer working within our application. Pressing it doesn't result in anything occurring.
The PinItListener doesn't get any exception callbacks, but it returns false for whether it was pinned in onComplete.
Trying out the PinItDemo project bundled with the SDK, nothing occurs on click either. I tried it with our client ID and a new client ID I set up.
Since it stopped functioning between releases of our application, I'm assuming it's a Pinterest change. Did a Pinterest update break the PinItSDK? Is there something we can do to fix it?
I'm not sure if PinItSDK doesn't work anymore or what the problem is. But there is another way you can pin the content. You can use the base url to open Create Pin form like
http://www.pinterest.com/pin/create/button/?media=http://www.ournorthstar.com/wp-content/uploads/2013/10/test1.jpg&title=Sample&description=This+is+a+test+description
and pass it as an intent and start the activity.
Eg:
String shareUrl = "http://www.pinterest.com/pin/create/button/?media=http://www.ournorthstar.com/wp-content/uploads/2013/10/test1.jpg&title=Sample&description=This+is+a+test+description"
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(shareUrl));
startActivity(myIntent);
This issue was fixed in Pinterest for Android 2.1.4
I want to use zxing in an android project. I have download the code and the example app is running now (ZXingTestActivity). For your information, i am not very familiar with coding native android.
I want to use zxing to scan qr-codes to configurate an application. To avoid confusion between normal qrcodes and configuration qrcodes i want to print inverted/negative qrcodes on screen or paper.
To be able to scan these inverted/negative qrcodes, the camera must be in negative mode. How can i do this? I am not sure where to start, however....
In the ZXingTestActivity.java there is a clicklistener that specify some extra parameters to the IntentIntegrator, for example:
private final Button.OnClickListener scanProduct = new Button.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
integrator.addExtra("SCAN_WIDTH", 800);
integrator.addExtra("SCAN_HEIGHT", 200);
integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
}
};
Is it possible to add camera settings with addExtra and how do i format this? Is it possible? Or is there another way to configurate the camera to inverted/negative mode?
I do not know if it completely impossible with ZXing but with ZBar it is possible!
First download the ZBar android version on sourceforge:
http://sourceforge.net/projects/zbar/files/AndroidSDK/
Add project to eclipse
Open CameraPreview.java
Add a private var to the class:
private Camera.Parameters mCameraParams;
Add the following lines after the line: mCamera = camera; in the constructor CameraPreview:
mCameraParams = camera.getParameters();
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
mCamera.setParameters(mCameraParams);
That's it! (run the project)
Also think that ZBar is faster to detect damaged barcodes. Is the same as the PC-version i have used in another project and does the job very well. Blink with your eyes and the code is there. No fancy things at all, just good!
#Erwinus, here's the code. I hope it's now clear why it is something you have already been completely given in previous comments. More homework and fewer accusations makes SO a happy place.
mCameraParams = camera.getParameters();
if (mCameraParams.getSupportedColorEffects().contains(Camera.Parameters.EFFECT_NEGATIVE) {
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
}
mCamera.setParameters(mCameraParams);
Sorry there's not a way to do this via Intent. A clean patch adding this as an option would be attractive to commit. The only gotcha is that the camera must support the "negative" mode. Then it's trivial (you can see this behavior as a selectable option in Barcode Scanner+). Otherwise you have to flip the image yourself. Not hard, but takes a bit of code and CPU cycles.
I have an application in which if you click a button, it opens the Android Gallery application. The user can then select an image for my application. The thing is, if I click that button in JUnit, it opens up the Gallery and then just sits there. I have to manually choose a picture. I just want to be able to open the Gallery and then go back or if possible select an image.
I tried several options such as -
sendKeys(KeyEvent.KEYCODE_BACK)
Robotiums goBack(), goBackToActivity(), sendKey() functions
Robotiums clickOnScreen() function to click and select an image
but none of these seem to work. So what do I do?
I had the same problem. You can't do this, as the Android Gallery is another application running in its own sandbox which you cannot reach from your testing code.
However, I came up with the following solution. You can build your own dummy application that provides an Intent filter for opening images. In this application you simply return the intent with an ok.
Now you only have to select your application as the default application when first opening your image from your test application. Afterwards, everything should work automatically.
Once you're done with testing, you can reset the default intent filter in your Android device's settings.
The code for my solution can be found in this discussion: How to provide content for Intent.ACTION_GET_CONTENT
It is possible to simulate response returned from gallery.
The code snippet below do all the work.
final Intent data = new Intent();
data.setData(Uri.parse("content://media/external/images/media/458")); // put here URI that you want select in gallery
Runnable runnable = new Runnable(){
#Override
public void run() {
getActivity().onActivityResult(3333,-1, data);
synchronized(this) {
this.notify();
}
}
};
synchronized(runnable) {
getActivity().runOnUiThread(runnable);
runnable.wait();
}
This method has two drawbacks:
onActivityResult method of your activity should be public which brakes encapsulation.
Test will not actually click button which opens gallery and onClick handler won't be executed.
But the benefit of such approach is that you don't need to build mock application and change any defaults in android settings.
I'm new to Robotium as well as Android. I have written some code to test an activity. and that activity is opening a dialogue box. and i'm not able to identify it. I tried solo.getCurrentActivity(), not workes. I tried solo.searchText(). But test is failing.
write code like this
if (solo.waitForActivity("HomePhone", 20000)) {
if(solo.waitForText("xxx*",1,10000)){
if(solo.waitForText("ok*",1,5000)){
solo.clickOnText("ok*");
}else{
solo.goBack();
}
}
wait for text is best method for your purpose