hello i am currently developing an app named Clear Up where it is suppose to detect…
- User
hello i am currently developing an app named Clear Up where it is suppose to detect written text or text in the camera just like the google lens and this app is design to help people with dyslexia. so basically the text will be detected and then it will say the word using text to speech feature but i am no longer near there because i am stuck here in making a simple button that activates the camera. after running the program in my phone it just doesnt work and i think its in my MainActivity.kt that is wrong because i noticed that when running my main_activity.xml it just says Hello Android when i did not configured the MainActivity.kt yet. just provide me the explanations and when i ask you to give me or revise the code just do what i tell you okay? because im sure its gonna crash this site when too much token.
here is my MainActivity.kt: package com.androidstudio.clearup
import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import android.os.Environment import android.widget.Button import android.widget.ImageView import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.registerForActivityResult import androidx.appcompat.app.AppCompatActivity import androidx.core.content.FileProvider import com.clearup.android.clearup.R import java.io.File import java.io.IOException import java.text.SimpleDateFormat import java.util.Date import java.util.Locale
open class MainActivity : AppCompatActivity() { private val requestImageCapture = 1
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.main_activity) setupTakePictureIntent() val captureButton: Button = findViewById(R.id.captureButton) // Replace with your button’s ID captureButton.setOnClickListener { dispatchTakePictureIntent() } } private fun dispatchTakePictureIntent() { val photoFile: File = createImageFile() photoFile.also { imageUri = FileProvider.getUriForFile( this, "com.android.clearup.fileProvider", it ) getImage.launch(imageUri) } } @SuppressLint("QueryPermissionsNeeded") private fun setupTakePictureIntent() { getImage = registerForActivityResult(ActivityResultContracts.TakePicture()) { success: Boolean -> if (success) { val imageView: ImageView = findViewById(R.id.image_layout) imageView.setImageURI(imageUri) } } } @Throws(IOException::class) private fun createImageFile(): File{ val timestamp: String = SimpleDateFormat("yyyMMdd_HHms", Locale.getDefault()).format(Date()) val storageDir: File = getExternalFilesDir(Environment.DIRECTORY_PICTURES)!! return File.createTempFile( "JPEG_${timestamp}_", ".jpg", storageDir ).apply { currentPhotoPath = absolutePath } } @Suppress("DEPRECATION") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == requestImageCapture && resultCode == Activity.RESULT_OK) { val extras = data?.extras val imageBitmap: Bitmap? = extras?.getParcelable("data") imageBitmap?.let { val imageView: ImageView = findViewById(R.id.image_layout) imageView.setImageBitmap(it) } } } private lateinit var getImage: ActivityResultLauncher<Uri> private lateinit var imageUri: Uri private var currentPhotoPath: String = "" - Assistant
- User
after removing the whole override fun onActivityResult it gave me this error Property "requestImageCapture" is never used and in the file creation permission i dont know where to put it, i will provide you a 75 line of code and just put the coordination or position on where i should put it. example (:#) # = number
- Assistant
- User
Unresolved reference: CAMERA :30 Unresolved reference: CAMERA :32 Unresolved reference: YOUR_REQUEST_CODE :32 Type mismatch: inferred type is File? but File was expected :54
- Assistant
- User
When i hover over the project errors in Android studio it told me i have a lot of errors but in the file there is none.
- Assistant
- User
import com.clearup.android.clearup.R
Unresolved reference: clearup
- Assistant
- User
all the issues are fixed and the applications keeps stopping in my phone... theres no problem or any error tho?
- Assistant
- User
- Assistant
- User
The item's text contrast ratio is 2.62. This ratio is based on an estimated foreground color of #B07FF6 and an estimated background color of #6200EE. Consider increasing this item's text contrast ratio to 3.00 or greater.
button_background
<solid android:color="@color/purple_500"/> <size android:height="30dp" android:width="100dp"/> <corners android:radius="10dp"/> - Assistant
The warning about text contrast ratio you're seeing concerns accessibility standards, particularly aiming to ensure that text within your app is easily readable by people with visual impairments. The contrast ratio between the text color and its background color should ideally meet the minimum requirements set by the Web Content Accessibility Guidelines (WCAG), aiming for a ratio of 4.5:1 for normal text and 3:1 for large text to enhance readability.
- User
- Assistant