My QR reader app won't open Links - java

I made a QR reader APP for my school project, the app works very well but it has a little mistake. When I scan a QR code the app just shows me the text. However, when I created a QR code linked to "www.google.com" (a simple link), my app just shows me "www.google.com" and doesn't open it in the browser.
I use this video to make my app : https://youtu.be/Fe7F4Jx7rwo
He is a nice guy He said : "use intent to open it in a browser"
But as I said in previous posts : "in my school my teacher prefer to teach Visual Basic instead Java or C++" ... So I'm a 0 in Java or C++
Can anyone suggest what to do?

I suggest the following. When you get the text from the QR call the following code to either open the browser or show the text on the screen (your current implementation):
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
String text = resultCode.getContents();
if (Patterns.WEB_URL.matcher(text).matches()) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(text));
startActivity(browserIntent);
} else {
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
}
}

Related

Viewing PDF (from URL) in android app within a webview intent

I am trying to view a PDF file remotely located from my device/the emulator. I have been doing quite a lot of research and been looking around stackoverflow on how to do this without having to download the PDF and then viewing the file that way.
This is the relevant code snippet for trying to do this:
if (url.contains("CreateQuoteDocument")) {
webview.getSettings().setJavaScriptEnabled(true);
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url),"application/pdf");
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e("something went wrong", e.getMessage());
}
}
I am getting the following exception:
E/something went wrong: No Activity found to handle Intent { act=android.intent.action.VIEW ...
So having this said, I have two questions,
Why isn't this working?
Is there another way of doing this? (while not using google docs)
EDIT
The URL is properly formatted with http://www
Try this:
String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
Why isn't this working?
You have not installed an app that contains an activity that supports that Intent structure (e.g., application/pdf for whatever scheme happens to be used by url).
Is there another way of doing this?
You could install an app that contains an activity that supports that Intent structure. Of course, not all users will have such an app, but perhaps you are only intending to use your code personally, in which case there are no other users besides you.

Google glass voice recognition

I want to do a google glass application that can recognize the words said by others to you.
I tries to use the same Android code for voice recognition
#Override
public void onClick(View v) {
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(i, REQUEST_OK);
} catch (Exception e) {
Toast.makeText(this, "Error initializing speech to text engine.", Toast.LENGTH_LONG).show();
}
}
This didn't work because, this code recognizes only the speech the person putting the glass on his head is saying.
I need my application to also recognize the voice of others talks to me.
Anyone could help please?
Thanks
If the other person is close enough of the microphone, it should work.
The problem here is about the hardware not the code, the microphone is only receiving the voice of the person around it, if you are too far it won't work.

capture audio from google recognizer intent [duplicate]

I am working on application that will record the voice of the user and save the file on the SD card and then allow the user to listen to the audio again.
I am able to allow the user to record his voice using the RecognizerIntent, but I cant figure out how to save the audio file and allow the user to hear the audio. I would appreciate it if someone could help me out. I have displayed my code below:
// Setting up the onClickListener for Audio Button
attachVoice = (Button) findViewById(R.id.AttachVoice_questionandanswer);
attachVoice.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Please Speak");
startActivityForResult(voiceIntent, VOICE_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == VOICE_REQUEST && resultCode == RESULT_OK){
}
There is an example of how to do audio capture using MediaRecorder in the Android Developer Documentation.
I would recommend saving the files on the SD Card and then have your gallery code check the SD card to see which files to display. You can get the directory of the SD Card using the Environment.getExternalStorageDirectory() method. It would be best to save your files in a subdirectory of the SD Card root directory.
Make sure you give your applications the Permissions it will need. At the very least it will need RECORD_AUDIO and WRITE_EXTERNAL_STORAGE.
Also you have to see these tutorials:
http://www.androiddevblog.net/android/android-audio-recording-part-1
http://www.androiddevblog.net/android/android-audio-recording-part-2
If you really want to record audio via the speech recognition API then you could use the RecognitionService.Callback which has a method
void bufferReceived(byte[] buffer)
This gives you access to the recorded audio buffer as speech is being recorded and recognized. (No information is provided about the sample rate though.) You can then save the obtained buffers into a file for a later playback. I think keyboard apps use this call to display the waveform of the recorded speech. You have to implement the UI yourself.
The bare RecognizerIntent.ACTION_RECOGNIZE_SPEECH just returns a set of words/phrases without any audio.

How to execute BarCode scanner from ZXing sources on Java, Android?

I have just made application using BarCode scanner (ZXing 1.7). User doesn't use bar code scanner on his phone, therefore I can't add external Bar Code scanner into my application. I have added ZXing sources for into my project, but I don't know how I can execute it without intents. Please, help me.
Update: or how can I make that external bar code scanner will be installed automatically with my application?
You can't install the external barcode scanner to be installed automatically. What you could do is to check if it is installed, and if not show a dialog asking the user wether they want to install it (this will take the user to the app market link).
If you want to avoid this, you can integrate directly the ZXing library but it requires more work. The barcode scanner app is open source so you can see how to do it from there.
If the zxing barcode scanner is installed in the mobile, its very easy:
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
startActivityForResult(intent, 0);
and in OnActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents =
data.getStringExtra("SCAN_RESULT"); //this is the result
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
If its not installed: u can put this code in try-catch block and catching the exception, u can do this:
Uri marketUri = Uri
.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
marketUri);
startActivity(marketIntent);
So it redirects the app to android market and ur app continues running once if the barcode scanner is installed.
If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: http://code.google.com/p/zxing/wiki/GettingStarted
Just use the provided Intent-based integration code. It's very easy. It will send the user to Market to download the app. This is much better than trying to automatically install it for at least three reasons. First, I do not think users expect apps to install other apps and probably don't like it. Second it will only possibly work if the user has set the device to allow third-party apps from outside Market. Finally, you will be installing a potentially old version.

How to create barcode scanner (Android)?

Can someone tell me if creating barcode scanner app (for Android) is difficult? Is OpenCV library good start? Where can I find algorithm which clearly explains how to read barcodes? I will appreciate all good materials about this topic!
Thanks in advance!
The ZXing project provides a standalone barcode reader application which — via Android's intent mechanism — can be called by other applications who wish to integrate barcode scanning.
The easiest way to do this is to call the ZXing SCAN Intent from your application, like this:
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public 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");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Pressing the button linked to mScan would launch directly into the ZXing barcode scanner screen (or crash if ZXing isn't installed). Once a barcode has been recognised, you'll receive the result in your Activity, here in the contents variable.
To avoid the crashing and simplify things for you, ZXing have provided a utility class which you could integrate into your application to make the installation of ZXing smoother, by redirecting the user to the Android Market if they don't have it installed already.
Finally, if you want to integrate barcode scanning directly into your application without relying on having the separate ZXing application installed, well then it's an open source project and you can do so! :)
You can use the existing Zebra Crossing barcode scanner for Android, available at: http://code.google.com/p/zxing/. Typically the idea is that you would invoke it via intents, like in the example here: http://code.google.com/p/zxing/wiki/ScanningViaIntent.
Zebra Crossing is the best documented java 1D or 2D barcode decoder or encoder around. Lots of people use it, and it's become the de facto standard for android. There's a healthy buzz about it on here too.
RedLaser has an api, but you'll have to pay if you use it in production. When I tried it out, I didn't find it to be a spectacular improvement over Zebra Crossing. Certainly not for the price.
jjil does barcodes but there are only 3 committers on the project, and I've never used it myself so I don't know what to tell you about it. Its source is certainly readable.
Once you start reading, you'll find readers are tricky things to implement due to blurry images, noise, distortion, weird angles, and so forth. So if you want something reliable, you probably want to go with a community-maintained library.
You can use zbar library. Download it from:
http://sourceforge.net/projects/zbar/files/AndroidSDK/
I think this is more fast and accurate than zxing.

Categories

Resources