У меня есть приложение, поддерживающее два языка, по умолчанию английский и второй - французский.Я тестирую его на устройстве Android, которое настроено на два языка, первый - испанский, а второй - французский.Когда я запускаю приложение, все в порядке, и начинается мое первое действие (потому что приложение не поддерживает испанский) на втором языке устройства, который является французским.К сожалению, когда я звоню
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
, приложение работает на английском языке, который является языком по умолчанию для моего приложения.
Когда я записываю результат Local.getDefault().getLanguage()
, я получаю «fr» или«en» в зависимости от вызова MobileAds.initialize(...)
или нет при запуске приложения.
Воспроизвести эту проблему очень легко - я создал приложение с нуля, добавил строковые ресурсы на двух языках и добавил com.google.firebase:firebase-ads
к зависимостям.Лучше всего воспроизвести проблему, расширив Application и добавив туда метод MobileAds.initialize(...)
к onCreate
.Когда MobileAds.initialize(...)
вызывается из onCreate
(первого) действия, проблема возникает после остановки запуска, обычно после поворота устройства.
Она была протестирована на Android 7.1.1 и 8.0 с тем же результатом.
Я пользуюсь последней com.google.firebase:firebase-ads:17.1.2
.
Кто-нибудь сталкивался с такой же проблемой?Любой совет?Спасибо.
Просто для полноты вот build.gradle приложения
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.languages"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en", "fr"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-ads:17.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
, а вот Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.languages">
<application
android:name=".MyApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity
android:name=".MainActivity"
android:label="@string/main_title">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>