Comments (22)
Can you try it with the current version and let me know?
from jetpack_compose_country_code_picker.
I have tried in many versions and I found this library best in case of country picker with jetpack compose. But I have lot of users and they are using android 8.1.0 and below and app is really badly crashing. Can you please check this problem in detail and help me in this case? It will be really helpful if you do. Thanks in advance.
from jetpack_compose_country_code_picker.
Can you share a code sample? That way I can control it more easily.
from jetpack_compose_country_code_picker.
I haven't edited the code, I just used the example code and It is working on my other devices and crashing on my Motorola G5 plus with Android version 8.1.0. I have fetched the Log error. Please check it and also I think it's occurring when we are trying to fetch default country code. I have done some research and also tried to catch the exception but it is not working.
from jetpack_compose_country_code_picker.
Hello @togisoft I think I found what is the problem. App is crashing In Lollipop and lower version and we have no protection for this.
please check this answer https://stackoverflow.com/questions/47152007/separating-country-code-from-mobile-number-if-present-android Can you please fix it so that I can use it in my all projects. I think we just need to add condition for Lollipop and lower devices. Thanks in advance.
from jetpack_compose_country_code_picker.
Same issue occurs in Android 12. If its okay with @togisoft I can take a look and submit a PR today.
from jetpack_compose_country_code_picker.
@adukugideon It will be really helpful if you can solve this issue. I hope It will be okay with @togisoft
from jetpack_compose_country_code_picker.
i will check today i will find a solution
from jetpack_compose_country_code_picker.
@deepbmv can you send me the build.gradle file
I tested in all versions, no problem
from jetpack_compose_country_code_picker.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.1.1'
kotlin_version = '1.6.10'
// Changed ActivityVersion inorder to solve the Preview problem
activityVersion = '1.5.0-beta01'
appCompatVersion = '1.4.1'
coroutines = '1.5.2'
lifecycleVersion = '2.4.1'
materialVersion = '1.4.0'
camerax_version = "1.1.0-beta03"
roomVersion = '2.4.2'
}
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.5"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
from jetpack_compose_country_code_picker.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdk 33
defaultConfig {
applicationId "com.myapp.android"
minSdk 21
targetSdk 33
versionCode 2
versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
useIR = true
}
//Support @JvmDefault
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=enable'] //enable or compatibility
jvmTarget = "1.8"
}
}
buildFeatures {
viewBinding true
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
dataBinding {
enabled = true
}
viewBinding {
enabled = true
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
debugImplementation "androidx.customview:customview:1.2.0-alpha01"
debugImplementation "androidx.customview:customview-poolingcontainer:1.0.0-alpha01"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation 'com.google.android.material:material:1.6.1'
implementation "androidx.compose.ui:ui:$compose_version"
// implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.ui:ui-viewbinding:1.1.1"
implementation("androidx.compose.animation:animation-core:$compose_version")
implementation("androidx.compose.animation:animation:$compose_version")
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.foundation:foundation:$compose_version")
implementation("androidx.compose.ui:ui-geometry:$compose_version")
implementation("androidx.compose.ui:ui-graphics:$compose_version")
implementation("androidx.compose.foundation:foundation-layout:$compose_version")
implementation("androidx.compose.runtime:runtime-livedata:$compose_version")
// implementation("androidx.compose.material:material:$compose_version")
implementation 'androidx.compose.material3:material3:1.0.0-rc01'
implementation("androidx.compose.material:material-icons-core:1.2.1")
implementation("androidx.compose.material:material-icons-extended:1.2.1")
implementation("androidx.compose.runtime:runtime-rxjava2:$compose_version")
implementation("androidx.compose.ui:ui-text:$compose_version")
implementation("androidx.compose.ui:ui-util:$compose_version")
implementation("androidx.compose.ui:ui-viewbinding:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation("androidx.activity:activity-compose:1.4.0")
//Compose Constraintlayout
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.0")
//Navigation
implementation "androidx.navigation:navigation-compose:2.5.0-alpha02"
//Firebase
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'com.google.firebase:firebase-database-ktx:20.0.4'
implementation 'com.google.firebase:firebase-messaging-ktx:23.0.7'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-auth:8.0.0'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.google.firebase:firebase-crashlytics:18.2.10'
//Kotlin
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"
// Kotlin components coroutines
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
//
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.camera:camera-view:1.1.0-beta03'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
//Worker
implementation "androidx.work:work-runtime-ktx:2.7.1"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "io.coil-kt:coil-compose:1.3.2"
implementation project(':NotesModule')
//
implementation "androidx.activity:activity-ktx:$activityVersion"
implementation 'androidx.fragment:fragment-ktx:1.4.1'
//
implementation "androidx.camera:camera-lifecycle:$camerax_version"
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-view:1.1.0-beta03"
implementation "com.google.code.gson:gson:2.8.9"
// Room components
implementation "com.google.accompanist:accompanist-pager:0.21.2-beta"
implementation "com.google.accompanist:accompanist-pager-indicators:0.21.2-beta"
//Swiping
implementation "com.google.accompanist:accompanist-swiperefresh:0.21.2-beta"
//billing
implementation 'com.android.billingclient:billing:4.1.0'
implementation 'com.anjlab.android.iab.v3:library:2.0.3'
// DataStore
implementation 'androidx.datastore:datastore-preferences:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
implementation 'com.github.togisoft:jetpack_compose_country_code_picker:1.1.3'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
implementation 'androidx.core:core-splashscreen:1.0.0'
// Dagger - Hilt
implementation 'com.google.dagger:hilt-android:2.38.1'
kapt "com.google.dagger:hilt-android-compiler:2.38.1"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
implementation 'com.google.android.play:core-ktx:1.8.1'
}
from jetpack_compose_country_code_picker.
Check it.
from jetpack_compose_country_code_picker.
I'm checking I'll let you know
from jetpack_compose_country_code_picker.
I have solved this issue by simply using try catch block in following functions.
fun checkPhoneNumber(phone: String, fullPhoneNumber: String, countryCode: String): Boolean {
Log.e("RONALDO","Comming here0")
val number: Phonenumber.PhoneNumber?
if (phone.length > 6) {
Log.e("RONALDO","Comming here1")
return try {
Log.e("RONALDO","Comming here2")
number = PhoneNumberUtil.getInstance().parse(
fullPhoneNumber,
Phonenumber.PhoneNumber.CountryCodeSource.UNSPECIFIED.name
)
!PhoneNumberUtil.getInstance().isValidNumberForRegion(number, countryCode.uppercase())
} catch (ex: Exception) {
Log.e("RONALDO","Comming here3")
true
}
}
return true
}
fun getDefaultPhoneCode(context: Context): String {
Log.e("RONALDO","Comming here")
try {
val defaultCountry = getDefaultLangCode(context)
Log.e("RONALDO","Comming here try $defaultCountry")
if (defaultCountry != "en"){
Log.e("RONALDO","Should not enter if it's motorola $defaultCountry")
val defaultCode: CountryData = getLibCountries.first { it.countryCode == defaultCountry }
Log.e("RONALDO","RETURNING .. ${defaultCode.countryPhoneCode.ifBlank { "+90" }}")
return defaultCode.countryPhoneCode.ifBlank { "+90" }
}else{
return "+90"
}
}catch (e:Exception){
Log.e("RONALDO","Comming here catch $e")
return "+90"
}
}
fun getDefaultLangCode(context: Context): String {
Log.e("RONALDO","2Comming here try ")
try {
val localeCode: TelephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
var countryCode = localeCode.networkCountryIso
if (countryCode == null || countryCode.isEmpty() || countryCode.isBlank()){
countryCode = "in"
}
val defaultLocale = Locale.current.language
Log.e("RONALDO","2Comming here values countryCode $countryCode defaultLocale $defaultLocale")
return countryCode.ifBlank { defaultLocale }
}catch (e:Exception){
return "in"
}
}
After doing this it will work on all android devices without crashing.
I hope this helps to someone.
from jetpack_compose_country_code_picker.
Thanks for those who helped me in it
from jetpack_compose_country_code_picker.
Okey Thanks for your help
from jetpack_compose_country_code_picker.
@deepbmv
I still getting this crash with the latest version!
fun getDefaultPhoneCode(context: Context): String { val defaultCountry = getDefaultLangCode(context) val defaultCode: CountryData = getLibCountries.first { it.countryCode == defaultCountry } return defaultCode.countryPhoneCode.ifBlank { "+90" } }
sometimes the phone doesn't have any default lang code, can you please take care of this edge case?
from jetpack_compose_country_code_picker.
from jetpack_compose_country_code_picker.
You can read the above code and try to figure it out what I am trying to say. you can paste the logs here if that does not solves your error.
from jetpack_compose_country_code_picker.
What's the problem? Has this bug been fixed? Can you give details
from jetpack_compose_country_code_picker.
yes, the issue is this function getDefaultLangCode
return an empty string as there is no Locale.current.language
, so this crash getLibCountries.first
in the function getDefaultPhoneCode
!
so I'm recommending that if I can pass the default value from outside ! it would be nice :) thanks for replying me
from jetpack_compose_country_code_picker.
from jetpack_compose_country_code_picker.
Related Issues (20)
- Support more customization of styling and colors, or split the code into smaller composables
- Upgrade to latest compose version and use material3
- Myanmar flag is wrong. HOT 2
- Why the hell you changed so much API from 1.3 to 1.4? HOT 3
- Can't override IME's onDone
- Why do return true if isPhoneNumber check fails? HOT 1
- CAnt change text color
- Problem with material3 HOT 2
- add text color implementation, cant be used with dark mode
- Get country code HOT 1
- Misleading hint for numbers. HOT 2
- wrong formatting in default string.xml file and adding hindi translations HOT 2
- Add night mode support HOT 1
- Add capability of only having Country code HOT 1
- Required an parameter to handle trailing icon visibility HOT 1
- South Korea Hint Error HOT 1
- remove default padding HOT 1
- error HOT 10
- APP crashed when i click on flag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jetpack_compose_country_code_picker.