Send output of android app on localserver - java

I am building an application using android speech recognition intent. I have build the application, now I want to send the recognized outputs to local server so that I can view the output of the recognizer from any device connected to the same network. Below is my code:
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);
mTextFromSpeech.setText(result.get(0));
String finalResult = result.get(0);
System.out.println("Detected Command Is: " + finalResult);
}
break;
}
}
}
I want to send the result from finalresult on local server, please help.

Related

How to croping image with source just from camera with Canhub Android Image Cropper with Java

I want to croping image from other activity to another activity with Canhub Android Image Cropper library. This is my code :
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
mCropImageUri = result.getOriginalUri();
createImage();
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
AppLogger.e(result.getError().getMessage());
}
}
if (requestCode == PermissionCheckUtils.LOCATION_PERMISSION_REQUEST_CODE && resultCode == RESULT_OK) {
getLocation();
}
}
and this when i access the camera :
private void openCropImage() {
Intent intent = CropImage.activity().setGuidelines(CropImageView.Guidelines.ON).getIntent(this);
startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}
with these code, i open camera but source include galery. My question is how to open the croper with source just from camera. I already read the documentation but I'm confused : https://github.com/CanHub/Android-Image-Cropper
It is very simple !!
In Your openCropImage() Function set following code :
Intent intent = CropImage
.activity()
.setImageSource(includeGallery = false, includeCamera = true)
.setGuidelines(CropImageView.Guidelines.ON)
.getIntent(this);
startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
That's it !! Happy Coding :-)

Convert an internal Uri to a File in Android?

I have an app that allows the user to select a file from the file chooser. The problem lies when I try to turn that Uri to a File, it creates something that I can't use (/document/raw:/storage/emulated/0/Download/CBTJourney-Backup/EntriesBackup1570487830108) I would like to get rid of everything before raw: but the right way. Where ever I try to copy from that file using InputStream, it doesn't copy anything. It's like the file doesn't exist. Any ideas?
public void chooseDatabaseFile() {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Set your required file type
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Choose Database to Import"),GET_FILE_PATH);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GET_FILE_PATH && data != null) {
if(resultCode == RESULT_OK){
Uri currFileURI = data.getData();
if(currFileURI == null) {
return;
}
else{
String databasePath = currFileURI.getPath();
// TODO: Determine if actual database
importDatabase(new File(databasePath));
// File produces "/document/raw:/storage/emulated/0/Download/CBTJourney-Backup/EntriesBackup1570487830108"
}
}
}
}
Have you tried changing your mimetype?
Otherwise take a look at:
Convert file: Uri to File in Android

How to read USSD Message response in android

i want to store my balance in sqlite database i am successfully dial the USSD
String balance_check="*444";
String encodedHash = Uri.encode("#");
String ussd = balance_check + encodedHash;
startActivityForResult(new Intent("android.intent.action.CALL",Uri.parse("tel:" + ussd)), 1);
Here is onActivityResult function
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
String dd = data.toString();
Log.d("myussdmessage", data.toString());}}
but I cannot get the string exactly how to do it.I want to store the balance form the dialogue to my database.Can any one suggest me how to do it.
You need to build an AccessibilityService in order to do that you need to read the documentation of AccessibilityService in below link
https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html
and also this question helped me
Prevent USSD dialog and read USSD response?

Picture File on RESULT_CANCELED

I want to be able to track image file names when a picture has been taken with the default Camera Glassware. This is so I can delete them when finished. I have the following code:
...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE_REQUEST && resultCode == RESULT_OK) {
String imgPath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
mService.addToImageQueue(imgPath);
}
else if (requestCode == TAKE_PICTURE_REQUEST && resultCode == RESULT_CANCELED) {
...
}
}
If I tap, the resultCode returns RESULT_OK. When I dismiss (swipe down), I get the resultCode RESULT_CANCELED. This is how I intended it to work, except it still generates the image file even if the resultCode is RESULT_CANCELED... I honestly feel like this might be a bug since I tried to use data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH); and got a NullPointerException. Am I doing something wrong? Is there a way to get this file name even on RESULT_CANCELED?
You could create a temporary file first (look at the createImageFile() method in this tutorial). If successfully created, do two things:
Save the path of this file to a String.
Include this file's URI in the intent extra (putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile))).
If resultCode is RESULT_CANCELED, you can now trace back to the path of the temporary file and call delete() on it.
Here is some sample code:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Log.v("MainActivity", "Result successful.");
} else if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_CANCELED) {
Log.v(TAG, "Result canceled. Uri of file is " + mCurrentPhotoPath);
File file = new File(mCurrentPhotoPath);
if (file.exists()) {
Log.v(TAG, "File exists.");
if(file.delete()) {
Log.v(TAG, "File was successfully deleted!");
} else {
Log.v(TAG, "File not successfully deleted.");
}
} else {
Log.v(TAG, "File does not exist!");
}
}
}
Note: For new File(mCurrentPhotoPath) to work, remove "file:" from the beginning of mCurrentPhotoPath.

integrating with intents for ocr and zxing

I have an app, i used this code to integrate zxing
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
}
}
I have both zxing scanner as well as google goggles installed in my mobile phone. When i start the app and try to scan, I get the option to choose either the barcode scanner or the goggle app. I thought, hey let's try and use the goggle app for doing other stuff as well like OCR. I select the goggle option but the app does not have the take picture option within it. How do I integrate goggles also with my app? with full functionality?
I have no idea about how to integrate your app with Google Goggles. However, if you looking for an app that provide OCR function, you may use my app:
https://play.google.com/store/apps/details?id=sunbulmh.ocr
Here is a sample code that you can use in your app to get OCR service:
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("sunbulmh.ocr", PackageManager.GET_ACTIVITIES);
Intent LaunchIntent = pm.getLaunchIntentForPackage("sunbulmh.ocr");
LaunchIntent.setFlags(0);
startActivityForResult(LaunchIntent,5);
} catch (NameNotFoundException e) {
Uri URLURI = Uri.parse("http://play.google.com/store/apps/details?id=sunbulmh.ocr");
Intent intent = new Intent(Intent.ACTION_VIEW,URLURI);
startActivity(intent);
}
Then, get the result in onActivityResult():
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if(requestCode == 5){
String ocr_txt = data.getStringExtra(Intent.EXTRA_TEXT);
// ocr_txt contains the recognized text.
}
}
}

Categories

Resources