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.
Related
I am knew to Android Studio. I want to create folder in external storage through android app. I tried using getExternalStorageDir() but it is not implemented for API level above 23. Please guide me to create folder and file in android app. Ignore any grammatical mistake if present. And I also want this process to be done in background without going anywhere from mainactivity.
The user can choose to make a new folder while using the SAF picker, but you can't programmatically create a folder in external storage without any user interaction.
For instance, add a Button to your layout and give it an OnClickListener. Then have it run this code when clicked:
int OPEN_REQUEST_CODE = 41;
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "Notes");
startActivityForResult(intent, OPEN_REQUEST_CODE);
This will prompt the user to create a document titled "Notes", but the user can choose where the document is stored and can even rename it if they so choose. Within the picker, there's an option named "New folder" that the user can select.
Part of the idea by Scoped Storage is that they don't want us devs to just be polluting the external storage with all sorts of files and folders. So this puts the user more in control.
You can make a subfolder once the user chooses a folder, but this still requires prompting the user to grant one-time access to a chosen folder:
https://stackoverflow.com/a/36547137/7434090
Also, this tutorial was very helpful to me while learning SAF:
https://en.proft.me/2018/05/24/using-android-storage-access-framework/
Put this in public void
Intent intent = new
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, NEW_FOLDER_REQUEST_CODE);
This on Activity Result
if (_resultCode == Activity.RESULT_OK) { if (_requestCode ==
NEW_FOLDER_REQUEST_CODE)
{ if (_data != null) { Uri currentUri = _data.getData();
DocumentFile pickedDir =
DocumentFile.fromTreeUri(this, currentUri);
DocumentFile newDir =
pickedDir.createDirectory("MyFolder"); } } }
This is another public void on oncreate
}
private static final int NEW_FOLDER_REQUEST_CODE = 43;
}
I am trying to add a button in my application that starts Google Voice Typing (or the default speech recognition). I have tried following this tutorial. This tutorial is incredibly confusing to me. I imported the .jar, and added the necessary permissions, services, and activities to my Manifest. But I can't seem to figure out how to "put it all together". I'm wondering:
Am I supposed to call the inputMethodService from my button click in my Main Activity? Or does my inputMethodService essentially become my Main Activity?
What does IME mean? I tried to Google it, but the definitions it gave me didn't help my understanding.
When I try to copy and paste the whole DemoInputMethodService code into my current activity, I get an error saying I cannot extend InputMethodService inside of this activity. (Which leads back to to ask question one.)
How can I get this to work?
If you want to follow the tutorial that you mention then you need to implement an IME (input method editor) first, see http://developer.android.com/guide/topics/text/creating-input-method.html
This IME can have a regular keyboard look-and-feel or contain just a microphone button.
The user of your app will first have to click on a text field to launch the IME. (Note that there can be several IMEs installed on the device and they have to be explicitly enabled in the Settings.) Then the user will have to click on the microphone button to trigger the speech recognition.
The tutorial provides a jar that lets you directly call Google's recognizer. It would be nicer if instead you called the recognizer via the SpeechRecognizer-interface (http://developer.android.com/reference/android/speech/SpeechRecognizer.html), this way the user can decide whether to use Google's or something else.
The SpeechRecognizer is given a listener which supports the method onPartialResults, which allows you to monitor the recognition hypotheses while the user is speaking. It's up to you how you display them. Note however that the specification of SpeechRecognizer does not promise that this method gets called. This depends on the implementation of the recognizer service. Regarding Google's implementation: what it supports keeps changing unannounced, it does not have a public API nor even release notes.
You might be able to reuse my project Kõnele (http://kaljurand.github.io/K6nele/about/), which contains two implementations of SpeechRecognizer and an IME that uses them. One of the implementations offers continuous recognition of arbitrarily long audio input, using the Kaldi GStreamer server (https://github.com/alumae/kaldi-gstreamer-server). You would need to set up your own instance of the server porting it to the language that you want to recognize (unless you want to use the Estonian server that Kõnele uses by default).
Voice recognition samples are found where you have the android SDK..
example:
$ find $SDK_ROOT/samples -name *recogni*
./android-19/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-19/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-19/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-18/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-18/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-18/legacy/ApiDemos/res/layout/voice_recognition.xml
./android-21/legacy/VoiceRecognitionService/res/xml/recognizer.xml
./android-21/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
./android-21/legacy/ApiDemos/res/layout/voice_recognition.xml
any one of the services should help show how to do a RecognizerIntent
The "APIDemo" seems to include use of a RecognizerIntent. check the source for that one. Otherwise look into the services and carve them up into an intent.
I had the same issue, but after a long time looking for continuous voice dictation on an activity, I solved that problem using pocketsphinx.
I couldn't find the way to integrate Google Voice Typing on an activity, just on an input method by following that tutorial. If it confuse you, just download this demo and modify it.
Good Luck!
You can trigger an intent from a button listener
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
And the result can be get from
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
Refer this link for more info.
how can I navigate to the applications page on my phone by a button click from my app? is it possible?
UPDATE
The question was not not ver clear earlier. I don't think it's possible. I have worked extensively on Android Launcher code and there's no standard or undocumented Intent to open that page directly.
Nova Launcher has a shortcut provider which lets you choose any activity. Simply call this shortcut provider from you code and select the activity you want, and then simple record the returned Intent.
Though this intent not be universal for all android versions. It will have package name and component name (and not an action string).
Use this code in an Activity in a test project. Make sure you have Nova launcher installed (you can uninstall it later on)
public void onTestButtonClicked(View v) {
startActivityForResult(Intent.createChooser(new Intent(Intent.ACTION_CREATE_SHORTCUT), "Select Activities"), 10);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10 && resultCode == RESULT_OK) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
Log.e("Intent", intent.toUri(Intent.URI_INTENT_SCHEME));
}
}
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.
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.