Key Features :
- Request camera & location permission callback by itself.
- CameraX api support.
- Show location and address.
- Show Lat Longs.
- Show author name.
- Show app name.
- Show Google map snapshot.
- Set Image Quality.
- Set Image Extension Type.
- Set Custom Typeface.
- Control the features of GTI.
- Set text size.
Add repository in your settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url "https://jitpack.io" }
}
}
in your settings.gradle.kts
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven( url = "https://jitpack.io")
}
}
Updated
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
maven( url = "https://jitpack.io")
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven( url = "https://jitpack.io")
}
}
Add dependency in your build.gradle
(module-level) file :
dependencies{
implementation 'com.github.dangiashish:GeoTagImage:1.1.8'
}
Add dependency in your build.gradle.kts
(module-level) file :
dependencies{
implementation("com.github.dangiashish:GeoTagImage:1.1.8")
}
Add file provider in AndroidManifest.xml
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
Create an xml file for path provider @xml/provider_path.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Go to here --> activity_main.xml
Kotlin : MainActivity.kt
import com.dangiashish.GeoTagImage
import com.dangiashish.PermissionCallback
class MainActivity : AppCompatActivity(), PermissionCallback{
// create global variables
private var gtiUri: Uri? = null
private lateinit var geoTagImage: GeoTagImage
private lateinit var cameraLauncher: ActivityResultLauncher<Uri>
private lateinit var permissionLauncher: ActivityResultLauncher<Array<String>>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
}
}
permissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
val allGranted = permissions.all { it.value }
if (allGranted) {
onPermissionGranted()
} else {
onPermissionDenied()
}
}
// cameraLauncher callback is required to capture the image from system camera.
cameraLauncher =
registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
if (success) {
gtiUri = geoTagImage.processCapturedImage() // if captured via system camera
previewCapturedImage()
} else {
Toast.makeText(mContext, "Image capture failed", Toast.LENGTH_SHORT).show()
}
}
// initialize the GeoTagImage class object with context and callback
// use try/catch block to handle exceptions.
geoTagImage = GeoTagImage(this, permissionLauncher, cameraLauncher) // this || context || requireContext() || requireActivity()
geoTagImage.requestCameraAndLocationPermissions()
// setOnClickListener on camera button.
binding.ivCamera.setOnClickListener {
geoTagImage.launchCamera(
onImageCaptured = { uri -> // if captured via CameraX api
if (uri != null) {
gtiUri = uri
previewCapturedImage()
} else {
Toast.makeText(mContext, "Failed to capture photo", Toast.LENGTH_SHORT).show()
}
},
onFailure = {
Toast.makeText(mContext, it, Toast.LENGTH_SHORT).show()
}
)
}
// set all the customizations for geotagging as per your requirements after initialization.
geoTagImage.enableGTIService(false) // Enable/Disable GTI Features
geoTagImage.setTextSize(30f)
geoTagImage.setBackgroundRadius(5f)
geoTagImage.setBackgroundColor(Color.parseColor("#66000000"))
geoTagImage.setTextColor(Color.WHITE)
geoTagImage.setAuthorName("Ashish")
geoTagImage.showAuthorName(true)
geoTagImage.showAppName(true)
geoTagImage.setImageQuality(ImageQuality.LOW) // Deprecated
geoTagImage.setImageExtension(PNG)
geoTagImage.setLabel("Clicked By") // Upload By || Author || Captured By
// preview of the original image
private fun previewCapturedImage() {
gtiUri?.let { uri ->
binding.ivImage.let { imageView ->
try {
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, uri))
} else {
@Suppress("DEPRECATION")
MediaStore.Images.Media.getBitmap(contentResolver, uri)
}
imageView.setImageBitmap(bitmap)
imageView.visibility = View.VISIBLE
} catch (e: Exception) {
Log.e(TAG, "Error loading image: ${e.message}")
}
}
}
}
override fun onPermissionGranted() {
}
override fun onPermissionDenied() {
geoTagImage.requestCameraAndLocationPermissions()
}
MIT License
Copyright (c) 2023 Ashish Dangi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.