It always changes into another activity when speech recognition is done
This is my code. What must be the problem?
I can get the result from speech recog.when it is done but it automatically changes to CropActivity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE_SPEECH_INPUT) {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
m_edtInputText.setText(result.get(0));
m_mic.setVisibility(View.VISIBLE);
sttProgress.setVisibility(View.INVISIBLE);
}
}
if (resultCode == Activity.RESULT_OK) {
Uri imageUri = getPickImageResultUri(data);
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_in_right);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == Activity.RESULT_OK) {
Uri resultUri = result.getUri();
Intent intent = new Intent(this, CropActivity.class);
intent.putExtra("imageUri", resultUri);
startActivity(intent);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
if(requestCode == MY_CHECK_DATA){
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
m_TTS = new TextToSpeech(this,this);
}
else
{
Intent m_installTTSIntent = new Intent();
m_installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(m_installTTSIntent);
}
}
}
Related
I am recording/selecting a video in my RecordVideo.java activity. Once the video is recorded/selected the I press the upload button and go to the PostActivity.java file. But once I'm in there for some reason onActivityResult isn't being called. I tried to toast and Log.d for some type of error or info but nothing came up.
I checked the answer on here to the same problem I'm having but none of them worked for me.
Can someone please help ?
RecordVideo.java:
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if (requestCode == REQUEST_CODE_VIDEO_CAPTURE && resultCode == RESULT_OK && data.getData() != null) {
videoUri = data.getData();
videoView.setVideoURI(videoUri);
videoView.start();
} else if (requestCode == 5 && resultCode == RESULT_OK && data != null && data.getData() != null) {
videoUri = data.getData();
videoView.setVideoURI(videoUri);
videoView.start();
}
super.onActivityResult(requestCode, resultCode, data);
}
private void uploadUserVideo(Uri videoUri) {
if (videoUri != null) {
Intent intent = new Intent(RecordVideo.this, PostActivity.class);
intent.putExtra("videoUri", videoUri.toString());
startActivity(intent);
finish();
} else {
Toast.makeText(this, "It's null", Toast.LENGTH_SHORT).show();
}
}
PostActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
Bundle extras = getIntent().getExtras();
if (extras != null) {
//videoUri = extras.getInt(videoUri);
videoUri = Uri.parse(extras.getString("videoUri"));
//Toast.makeText(this, "It's not null", Toast.LENGTH_SHORT).show();
} else {
// handle case
Toast.makeText(this, "Post null", Toast.LENGTH_SHORT).show();
}
videoView = findViewById(R.id.video_added);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
close = findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(PostActivity.this, MainActivity.class));
finish();
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
Log.d("TAG3", "I'm here." + requestCode);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
videoUri = data.getData();
videoView.setVideoURI(videoUri);
videoView.start();
Toast.makeText(this, "No problem.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "A problem.", Toast.LENGTH_SHORT).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
i'm creating an image cropping application and i want to delete the image automatically in the gallery after the camera intent photo taken.
my goal is to delete automatically the image taken from the camera app after cropping the image.
this is the code for opening camera
private void pickCamera() {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "NewPic");
values.put(MediaStore.Images.Media.DESCRIPTION,"Image to Text");
image_uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,image_uri);
startActivityForResult(cameraIntent,IMAGE_PICK_CAMERA_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == IMAGE_PICK_GALLERY_CODE) {
CropImage.activity(data.getData()).setGuidelines(CropImageView.Guidelines.ON).start(this);
}
if (requestCode == IMAGE_PICK_CAMERA_CODE){
CropImage.activity(image_uri).setGuidelines(CropImageView.Guidelines.ON).start(this);
}
}
if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
mPreviewIv.setImageURI(resultUri);
BitmapDrawable bitmapDrawable = (BitmapDrawable)mPreviewIv.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
TextRecognizer recognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if(!recognizer.isOperational()){
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
}
Just trying to flatten out bugs..
Int can not be dereferenced (on the StartWith Line)
Cannot find symbol method parse(int)
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == BARCODE_READER_REQUEST_CODE) {
if (resultCode == CommonStatusCodes.SUCCESS) {
if (resultCode.Startswith("http://") || resultCode.startsWith("https://")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, URI.parse(resultCode));
startActivity(browserIntent);
}
Here is the solution:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == BARCODE_READER_REQUEST_CODE) {
if (resultCode == CommonStatusCodes.SUCCESS) {
if (data != null) {
Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
String value = barcode.displayValue;
if (value.startsWith("http://") || value.startsWith("https://")) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(value));
startActivity(i);
}
} else
{
Log.e("your_tag","no value captured");
}
} else Log.e("your_tag","barcode error ");
} else super.onActivityResult(requestCode, resultCode, data);
}
I want to upload multiple images in webview and i can select many file but when i chose file and tap open Webpage Input show no file.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
if(Build.VERSION.SDK_INT >= 21){
Uri[] results = null;
//Check if response is positive
if(resultCode== Activity.RESULT_OK){
if(requestCode == FCR){
if(null == mUMA){
return;
}
if(intent == null){
//Capture Photo if no image available
if(mCM != null){
results = new Uri[]{Uri.parse(mCM)};
}
}else{
String dataString = intent.getDataString();
if(dataString != null){
results = new Uri[]{Uri.parse(dataString)};
}
}
}
}
mUMA.onReceiveValue(results);
mUMA = null;
}else{
if(requestCode == FCR){
if(null == mUM) return;
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
mUM.onReceiveValue(result);
mUM = null;
}
}
}
and my onShowFileChooser code is
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onShowFileChooser(
WebView webView, ValueCallback<Uri[]> filePathCallback,
WebChromeClient.FileChooserParams fileChooserParams){
if(mUMA != null){
mUMA.onReceiveValue(null);
}
mUMA = filePathCallback;
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("*/*");
contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
startActivityForResult(chooserIntent, FCR);
return true;
}
i searched on internet but can't find any suitable answer.
I'm retriving image from a IO file manager (one's installed). Anyhow when I try to retrieve an image I'm not sure where it's gone? Or how to save it as a bitmap?
Code below:
public void onClick(View v)
{
if(v.getId() == R.id.facebook_icon || v.getId() == R.id.facebook_text)
{
//Facebook
}
if(v.getId() == R.id.camera_icon || v.getId() == R.id.camera_text)
{
//Camera
}
if(v.getId() == R.id.folder_icon || v.getId() == R.id.folder_text)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), MODE_WORLD_READABLE);
}
}
protected void onActivityForResult()
{
//Where is the image? How to get?
System.out.println("Image gotton");
}
First of all, you are not overriding onActivityResult. Note the method signature: http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)
You should be using #Override annotations so you know when something's wrong.
Try something like:
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
}
}