Как изменить язык распознавания(Java/android studio/Text Recognition)?

Я написал(Частично украл) код.Всё отлично работает с английским языком.Но когда сканирую кириллицу он выдаёт за место кириллицы, латинские символы.Я совсем новичёк в этом деле(неделю).Пытаюсь поменять:

data.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ru-RU"); 

Но ничего не получается.Буду рад любой помощи.

Манифест

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="kz.healthcity.ocrapp"> 
    <uses-permission android:name="android.permission.CAMERA"/> 
 
 
 
    <application 
        android:allowBackup="true" 
        android:icon="@mipmap/ic_launcher" 
        android:label="@string/app_name" 
        android:roundIcon="@mipmap/ic_launcher_round" 
        android:supportsRtl="true" 
        android:theme="@style/Theme.Ocrapp"> 
        <activity 
            android:name=".MainActivity" 
            android:exported="true"> 
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
 
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter> 
        </activity> 
        <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"/> 
    </application> 
</manifest>

build.gradle

plugins { 
    id 'com.android.application' 
} 
 
android { 
    compileSdk 31 
 
    defaultConfig { 
        applicationId "kz.healthcity.ocrapp" 
        minSdk 16 
        targetSdk 31 
        versionCode 1 
        versionName "1.0" 
 
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 
    } 
 
    buildTypes { 
        release { 
            minifyEnabled false 
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 
        } 
    } 
    compileOptions { 
        sourceCompatibility JavaVersion.VERSION_1_8 
        targetCompatibility JavaVersion.VERSION_1_8 
    } 
} 
 
dependencies { 
 
    implementation 'androidx.appcompat:appcompat:1.3.1' 
    implementation 'com.google.android.material:material:1.4.0' 
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1' 
    testImplementation 'junit:junit:4.+' 
    androidTestImplementation 'androidx.test.ext:junit:1.1.3' 
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 
 
    implementation 'com.google.android.gms:play-services-vision:19.0.0' 
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' 
}

MainActivity

public class MainActivity extends AppCompatActivity { 
    Button button_capture,button_copy; 
    TextView textView_data; 
    Bitmap bitmap; 
    private static final int REQUEST_CAMERA_CODE = 100; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        button_capture = findViewById(R.id.button_capture); 
        button_copy = findViewById(R.id.button_copy); 
        textView_data = findViewById(R.id.text_data); 
 
        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED){ 
            ActivityCompat.requestPermissions(MainActivity.this,new String[]{ 
                    Manifest.permission.CAMERA 
            },REQUEST_CAMERA_CODE); 
        } 
 
        button_capture.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                CropImage.activity().setGuidelines(CropImageView.Guidelines.ON).start(MainActivity.this); 
            } 
        }); 
 
        button_copy.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                String scanned_text = textView_data.getText().toString(); 
                copyToClipBoard(scanned_text); 
            } 
        }); 
 
    } 
 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode,Intent data) { 
        super.onActivityResult(requestCode, resultCode, data); 
        data.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ru-RU"); 
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){ 
            CropImage.ActivityResult result = CropImage.getActivityResult(data); 
            if (resultCode == RESULT_OK){ 
                Uri resultUri = result.getUri(); 
                try { 
                    bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),resultUri); 
                    getTextFromImage(bitmap); 
                } catch (IOException e) { 
                    e.printStackTrace(); 
                } 
            } 
        } 
    } 
 
    private void getTextFromImage(Bitmap bitmap){ 
        TextRecognizer recognizer = new TextRecognizer.Builder(this).build(); 
        if (!recognizer.isOperational()){ 
            Toast.makeText(MainActivity.this,"ERROR Occured",Toast.LENGTH_LONG).show(); 
        }else { 
            Frame frame = new Frame.Builder().setBitmap(bitmap).build(); 
            SparseArray<TextBlock>  textBlockSparseArray = recognizer.detect(frame); 
            StringBuilder stringBuilder = new StringBuilder(); 
            for (int i = 0; i <textBlockSparseArray.size() ; i++) { 
                TextBlock textBlock = textBlockSparseArray.valueAt(i); 
                stringBuilder.append(textBlock.getValue()); 
                stringBuilder.append("\n"); 
            } 
 
            textView_data.setText(stringBuilder.toString());
            button_capture.setText("Retake"); 
            button_copy.setVisibility(View.VISIBLE); 
        } 
    } 
 
    private void copyToClipBoard(String text){ 
        ClipboardManager clopBoar = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 
        ClipData clip = ClipData.newPlainText("Copued data",text); 
        clopBoar.setPrimaryClip(clip); 
        Toast.makeText(MainActivity.this, "Copied to clipboard", Toast.LENGTH_SHORT).show(); 
    } 
}

Ответы (0 шт):