-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ashish Choudhary
committed
Jun 10, 2023
1 parent
d334837
commit afad2ac
Showing
16 changed files
with
537 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.CAMERA"/> | ||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/> | ||
|
||
<uses-feature android:name="android.hardware.camera" | ||
android:required="false" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" | ||
android:maxSdkVersion="32" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" | ||
android:maxSdkVersion="32" | ||
tools:ignore="ScopedStorage" /> | ||
|
||
</manifest> |
29 changes: 29 additions & 0 deletions
29
GeoTagImage/src/main/java/com/codebyashish/geotagimage/GTIException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.codebyashish.geotagimage; | ||
|
||
/** | ||
* 2023, Copyright by Ashish Dangi, | ||
* <a href="https://github.com/dangiashish">github.com/dangiashish</a>, | ||
* India | ||
*/ | ||
public class GTIException extends Exception { | ||
|
||
public GTIException(String message) { | ||
super(message); | ||
} | ||
|
||
public GTIException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
private int errorCode; | ||
|
||
public GTIException(String message, int errorCode) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
|
||
public int getErrorCode() { | ||
return errorCode; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
GeoTagImage/src/main/java/com/codebyashish/geotagimage/GTIPermissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.codebyashish.geotagimage; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
|
||
|
||
/** | ||
* 2023, Copyright by Ashish Dangi, | ||
* <a href="https://github.com/dangiashish">github.com/dangiashish</a>, | ||
* India | ||
*/ | ||
|
||
public class GTIPermissions { | ||
|
||
/** | ||
* Check Camera & Location Permission | ||
*/ | ||
public static boolean checkCameraLocationPermission(Context context) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
return ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; | ||
} else { | ||
return ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED | ||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Request Camera & Location Permission | ||
*/ | ||
public static void requestCameraLocationPermission(Context context, int requestCode) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES, | ||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, requestCode); | ||
} else { | ||
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, requestCode); | ||
} | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
GeoTagImage/src/main/java/com/codebyashish/geotagimage/GTIUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.codebyashish.geotagimage; | ||
|
||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.media.MediaScannerConnection; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
|
||
import androidx.core.content.FileProvider; | ||
import androidx.fragment.app.FragmentActivity; | ||
|
||
import java.io.File; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
|
||
/** | ||
* 2023, Copyright by Ashish Dangi, | ||
* <a href="https://github.com/dangiashish">github.com/dangiashish</a>, | ||
* India*/ | ||
public class GTIUtility { | ||
|
||
/** Check for Map SDK Integration*/ | ||
public static boolean isGoogleMapsLinked(Context context) { | ||
PackageManager packageManager = context.getPackageManager(); | ||
String apiKey = null; | ||
|
||
try { | ||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); | ||
Bundle metaData = applicationInfo.metaData; | ||
|
||
if (metaData != null && metaData.containsKey("com.google.android.geo.API_KEY")) { | ||
apiKey = metaData.getString("com.google.android.geo.API_KEY"); | ||
} | ||
} catch (PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return (apiKey != null); | ||
} | ||
|
||
/** Check for google map api key (if Map SDK is integrated)*/ | ||
public static String getMapKey(Context context) { | ||
PackageManager packageManager = context.getPackageManager(); | ||
String apiKey = null; | ||
|
||
try { | ||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); | ||
Bundle metaData = applicationInfo.metaData; | ||
|
||
if (metaData != null && metaData.containsKey("com.google.android.geo.API_KEY")) { | ||
apiKey = metaData.getString("com.google.android.geo.API_KEY"); | ||
} | ||
} catch (PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return apiKey; | ||
} | ||
|
||
/** To get application name*/ | ||
public static String getApplicationName(Context context) { | ||
final PackageManager packageManager = context.getPackageManager(); | ||
ApplicationInfo applicationInfo; | ||
try { | ||
applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0); | ||
} catch (final PackageManager.NameNotFoundException e) { | ||
applicationInfo = null; | ||
} | ||
|
||
return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown"); | ||
} | ||
|
||
/** Save original image in camera directory */ | ||
public static File generateOriginalFile(FragmentActivity mContext, String IMAGE_EXTENSION) { | ||
File file = null; | ||
try { | ||
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Camera"); | ||
if (!mediaStorageDir.exists()) { | ||
if (!mediaStorageDir.mkdirs()) { | ||
return null; | ||
} | ||
|
||
} | ||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); | ||
file = new File(mediaStorageDir.getPath() + File.separator + "ORG_" + timeStamp + IMAGE_EXTENSION); | ||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
|
||
} | ||
|
||
if (file != null) { | ||
scanMediaFIle(mContext, file); | ||
} | ||
|
||
return file; | ||
} | ||
|
||
private static void scanMediaFIle(FragmentActivity mContext, File file) { | ||
MediaScannerConnection.scanFile( | ||
mContext, | ||
new String[]{file.getAbsolutePath()}, | ||
null, | ||
new MediaScannerConnection.OnScanCompletedListener() { | ||
@Override | ||
public void onScanCompleted(String path, Uri uri) { | ||
|
||
} | ||
} | ||
); | ||
} | ||
|
||
|
||
/** Optimize bitmap to prevent OutOfMemory Exception*/ | ||
public static Bitmap optimizeBitmap(String filePath) { | ||
|
||
BitmapFactory.Options options = new BitmapFactory.Options(); | ||
options.inSampleSize = 4; | ||
|
||
return BitmapFactory.decodeFile(filePath, options); | ||
} | ||
|
||
/** get File Uri from application provider*/ | ||
public static Uri getFileUri(Context context, File file) { | ||
return FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file); | ||
} | ||
|
||
} |
Oops, something went wrong.