I have this app which consists of three tabs. The first tab has a button to scan QRcode. I didn't use an intent to call the barcode scanner here. I integrated all com.google... into my src. It works smoothly. The issue here, is when I scan for a Qrcode that has a website. The result I get back is the URL itself because of the textView. How do I get this URL to be clickable and redirected to the browser? Or simply show the content of the website in my app. Here is the Result Activity:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == ACTIVITY_REQUEST_CODE_QRCODE) {
if (txtQRcodeResult == null) {
txtQRcodeResult = (TextView) findViewById(R.id.textView1);
}
txtQRcodeResult.setText(data.getStringExtra("SCAN_RESULT"));
}
}
If you want the user to have to click you can use Linkify:
Linkify.addLinks(txtQRcodeResult, Linkify.WEB_URLS);
if you want to just jump into the browser and load the page, you can fire an intent:
Intent browserIntent = new Intent(Intent.VIEW_ACTION,ContentURI.create(data.getStringExtra("SCAN_RESULT")));
startActivity(browserIntent );
Related
I am new in xamarin, and I was wondering if it is possible to implement this kind of speech recognition:
First the user inputs "Hello" but the text output will be "Hi"?
I have found this link: Android speech recognition pass data back to Xamarin Forms
but it only outputs the speech "Hello" as a text "Hello".
Speech recognition usually involves translating what you say into text.If you need to change its content, perhaps you can try to make some judgments directly after the transformation and make changes according to your requirements like change the result in the link above :
in MainActivity OnActivityResult:
const int VOICE = 10;
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == VOICE)
{
if (resultCode == Result.Ok)
{
var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
if (matches.Count != 0)
{
var textInput = matches[0];
if (textInput.Length > 500)
textInput = textInput.Substring(0, 500);
//make a judgment and change the value
if(textInput.Eques("hello")){
textInput = "Hi";
}
SpeechToText_Android.SpeechText = textInput;
}
}
SpeechToText_Android.autoEvent.Set();
}
}
I have an app where a user can find an image from the gallery and it will be shown on the screen through a button click. The user can exit the app and the image they chose can be saved, so when they click the button again, it will also be shown. The image is shown the first time when it is picked, but the saving functionality does not seem to be working since the image is not being shown after the user closes and reopens the app.
I have tried looking up what camera permissions I may need, but I have not had any luck. I don't know what I would need since the app is able to load the image the first time.
//This is the method that shows the image
public void showImage(View view)
{
LinearLayout scroll = findViewById(R.id.imageViewer);
for(String i: imgDataList){
ImageView image = new ImageView(this);
image.setImageURI(Uri.parse(i));
scroll.addView(image);
}
}
//This is the method that works with the image that is gotten from the gallery
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
String imgData = data.getDataString();
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
imgDataList.add(imgData);
}
break;
case 1:
if(resultCode == RESULT_OK){
imgDataList.add(imgData);
}
break;
}
you may use sharedPreferences to store you image uri
please read more here about sharedPreferences and Save key-value data
I am trying to make a barcode scanning app. I am stuck at the point where I am able to scan the barcode but now I want to show the barcode image along with decoded barcode number and other details on the screen and then provide a button to proceed to next screen. How should I go about it? I am unable to understand should I call an intent to new activity or the layout view. If I call the new activity, how do I pass the barcode that's decoded and other details to new activity?
Help.
Want something like this after scanning a barcode:
you can get and use that barcode anywhere, as:
uid is a textview where i have added the result from ZXing (Zebra Crossing) library activity.:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
Log.e("test 1",String.valueOf(requestCode));
if (resultCode == RESULT_OK) {
Log.e("test 2",intent.getStringExtra("SCAN_RESULT_FORMAT"));
Log.e("test 3",intent.getStringExtra("SCAN_RESULT"));
Toast.makeText(getApplicationContext(), intent.getStringExtra("SCAN_RESULT"), Toast.LENGTH_LONG).show();
uid.setText(intent.getStringExtra("SCAN_RESULT")) ;
} else if (resultCode == RESULT_CANCELED) {
Log.e("test 4",String.valueOf(requestCode));
}
}
}
Over Image you are seeing in sample image is a generated barcode not a actual picture captured from the camera.
For this you can use iText is a great Java PDF library. They also have an API for creating barcodes. You don't need to be creating a PDF to use it.
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
I've implementing voice-search on my Android-TV app using the following small code
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
#Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == -1) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
Toast.makeText(getActivity(), spokenText, Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
This is all working well and I get the result back for further processing.
The problem is that I also want to give the user the possibility to enter the search-string manually with the virtual keyboard.
In Googles own apps you do this be simply pressing RIGHT on the remote to give focus to the textbox after pressing the voice-search icon.
In my example above I can see the "built-in-textbox" when I press the search icon but if I try to navigate to it the search is interrupted and closed.
How do I access the search-textbox? This should cancel voice-input and bring up the keyboard instead, just like Play Store app.
Are you using Leanback support library for your Android TV app design?
I guess "Google Play Store app" and "YouTube app" are using BrowseFragment & SearchFragment for search. These Fragments are providing build-in search UI.
For the implementation, see Google's sample source code or SearchFragment – Android TV app Tutorial 12.
The Android platform have a number of "ready easy use" dialog such as
ProgressDialog, DatePickerDialog and TimePickerDialog, these are fire and wait
boxes, that is, they handle UI, right data and return something.
Is there a similar dialogbox for the mediastorage ?
I want something like "AudioFilePickerDialog" which shows a UI to the user
where the user pick a audio file and return the path/uri to the audio file.
Do I need to build this dialog box up myself or does it exists somewhere ?
One of the few examples I have found is
Given an Android music playlist name, how can one find the songs in the playlist?
but this handles playlists.
/Stefan
I found a tutorial for something like a FileChooser here. You should be able to make it only show Music-Files (like .mp3).
Also, to browser the SDcard of your Android Device, you can use the standard Java File-class, like in normal Java.
Try this
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_MEDIA);//REQUEST_MEDIA is some const int to operate with in onActivityResult
here you'll be brought a dialog (activity tbh) to choose an audio from mediastore.
Handle the result in onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_MEDIA && resultCode == RESULT_OK) {
String audioID = data.getDataString();
...
}
}