eslamelmeniawy / image-picker Goto Github PK
View Code? Open in Web Editor NEWAndroid 10's Scoped Storage Image Picker (Gallery/Camera) using Kotlin and MVVM
Android 10's Scoped Storage Image Picker (Gallery/Camera) using Kotlin and MVVM
error logcat:
2021-05-28 14:41:56.847 13260-13260/elmeniawy.eslam.imagepicker E/AndroidRuntime: FATAL EXCEPTION: main
Process: elmeniawy.eslam.imagepicker, PID: 13260
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at androidx.activity.ComponentActivity$2.onLaunch(ComponentActivity.java:169)
at androidx.activity.result.ActivityResultRegistry$3.launch(ActivityResultRegistry.java:224)
at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:47)
at androidx.fragment.app.FragmentManager.launchStartActivityForResult(FragmentManager.java:3000)
at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1424)
at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1398)
at elmeniawy.eslam.imagepicker.ui.main.MainFragment.observeShowPicker$lambda-5(MainFragment.kt:127)
at elmeniawy.eslam.imagepicker.ui.main.MainFragment.lambda$oaDPbCrAXyQtdwDoGezvBCBwR6w(Unknown Source:0)
at elmeniawy.eslam.imagepicker.ui.main.-$$Lambda$MainFragment$oaDPbCrAXyQtdwDoGezvBCBwR6w.onChanged(Unknown Source:4)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
at elmeniawy.eslam.imagepicker.ui.main.MainViewModel.gotCameraPermissionStatus(MainViewModel.kt:43)
at elmeniawy.eslam.imagepicker.ui.main.MainFragment.observeCheckCameraPermission$lambda-1(MainFragment.kt:96)
at elmeniawy.eslam.imagepicker.ui.main.MainFragment.lambda$_0C_YrSYLCpwsTsYeNFaDyca8kI(Unknown Source:0)
at elmeniawy.eslam.imagepicker.ui.main.-$$Lambda$MainFragment$_0C_YrSYLCpwsTsYeNFaDyca8kI.onChanged(Unknown Source:4)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
at elmeniawy.eslam.imagepicker.ui.main.MainViewModel.addClicked(MainViewModel.kt:38)
at elmeniawy.eslam.imagepicker.databinding.FragmentMainBindingImpl._internalCallbackOnClick(FragmentMainBindingImpl.java:155)
at elmeniawy.eslam.imagepicker.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
updated app module gradle:
dependencies {
// Libraries and jars.
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Kotlin.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// Coroutines.
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
// Androidx.
implementation 'androidx.core:core-ktx:1.6.0-beta01'
implementation 'androidx.appcompat:appcompat:1.4.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
// LiveData & ViewModel.
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.3.1'
// implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
//implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
implementation "android.arch.lifecycle:common-java8:1.1.1"
// Navigation.
// The Navigation Architecture Component.
// Simplifies the implementation of navigation between destinations in your app.
implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"
// Timber.
// Logger with a small, extensible API
// which provides utility on top of Android's normal Log class.
implementation 'com.jakewharton.timber:timber:4.7.1'
// Koin.
// Dependency injector.
// latest unstable
def koin_version = '2.2.0-alpha-1'
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
implementation "org.koin:koin-androidx-fragment:$koin_version"
// implementation 'org.koin:koin-androidx-viewmodel:2.1.2'
// Retrofit.
// Type-safe HTTP client.
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
// Moshi Kotlin.
// Required by reflection adapter to add adapters to moshi.
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
// Moshi Adapters.
// For adding custom adapters to be used with moshi.
implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
// OkHttp Logging Interceptor.
// For HTTP logging.
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
// Shape Image View.
// Custom shaped android image view components.
implementation 'com.github.siyamed:android-shape-imageview:0.9.3'
// Glide.
// Glide is a fast and efficient open source media management and image loading framework for Android
// that wraps media decoding, memory and disk caching,
// and resource pooling into a simple and easy to use interface.
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
}
project gradle:
buildscript {
ext.kotlin_version = '1.5.10'
ext.coroutines_version = '1.4.2'
ext.lifecycle_version = '2.3.1'
ext.navigation_version = '1.0.0'
ext.retrofit_version = '2.9.0'
ext.moshi_version = '1.12.0'
ext.glide_version = '4.11.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.