Skip to content

image_picker package : Issue getting GPS info from Exif data on Android device #134378

@Vavinci

Description

@Vavinci

Is there an existing issue for this?

What package does this bug report belong to?

image_picker

What target platforms are you seeing this bug on?

Android

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock

Steps to reproduce

I am using the image_picker package to pick a file from the image : gallery (source) and read the Exif data. But when i check the GPS Info the latitude and longitude are set to [0/0, 0/0, 0/0]. I have seen a similar issue reported in 2022 #99817 but that was closed and #132827 reports of a missing Exif Tags.

The image has the GPS data.

This issue is only on Android as it works as expected on IOS.

image_picker package version : '1.0.4'.

Expected results

flutter: GPS GPSLatitudeRef: N
flutter: GPS GPSLatitude: [37, 39, 1324/25]
flutter: GPS GPSLongitudeRef: W
flutter: GPS GPSLongitude: [61, 22, 241/100]
flutter: GPS GPSAltitudeRef: 0
flutter: GPS GPSAltitude: 18859/100
flutter: GPS GPSImgDirectionRef: M
flutter: GPS GPSImgDirection: 340

Actual results

I/flutter ( 6114): GPS GPSLatitudeRef:
I/flutter ( 6114): GPS GPSLatitude: [0/0, 0/0, 0/0]
I/flutter ( 6114): GPS GPSLongitudeRef:
I/flutter ( 6114): GPS GPSLongitude: [0/0, 0/0, 0/0]
I/flutter ( 6114): GPS GPSAltitudeRef: 0
I/flutter ( 6114): GPS GPSAltitude: 0/0
I/flutter ( 6114): GPS GPSTimeStamp: [0/0, 0/0, 0/0]
I/flutter ( 6114): GPS GPSImgDirectionRef:
I/flutter ( 6114): GPS GPSImgDirection: 0/0
I/flutter ( 6114): GPS GPSDate:

Code sample

Code sample
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter EXIF Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const ExifDemo(),
    );
  }
}

XFile? _image;

class ExifDemo extends StatefulWidget {
  const ExifDemo({Key? key}) : super(key: key);

  @override
  _ExifDemoState createState() => _ExifDemoState();
}

class _ExifDemoState extends State<ExifDemo> {
  Future<void> getImage({required bool isGallery}) async {
    ImagePicker picker = ImagePicker();
    XFile? pickedFile;

    try {
      pickedFile = isGallery
          ? await picker.pickImage(source: ImageSource.gallery)
          : await picker.pickImage(source: ImageSource.camera);
    } on PlatformException catch (error) {
      switch (error.code.toLowerCase()) {
        case 'photo_access_denied':
          print(error.code);
          break;
        case 'camera_access_denied':
          print(error.code);
          break;
        default:
          print(error.code);
          break;
      }
    } catch (error) {
      print(error);
    }

    if (pickedFile != null) {
      setState(() {
        _image = pickedFile;
      });
      readExifData();
    }
  }

  readExifData() async {
    if (_image != null) {
      final fileBytes = File(_image!.path).readAsBytesSync();
      final data = await readExifFromBytes(fileBytes);

      if (data.isEmpty) {
        print("No EXIF information found");
        return;
      }

      print('Path : ${_image!.path}');
      for (final entry in data.entries) {
        print("${entry.key}: ${entry.value}");
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.only(
            left: 10.0,
            top: 10.0,
            right: 10.0,
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Visibility(
                  visible: _image != null,
                  child: ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _image = null;
                      });
                    },
                    child: const Text('CLEAR'),
                  )),
              if (_image != null)
                Card(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(0.0),
                  ),
                  elevation: 5,
                  margin: const EdgeInsets.all(10),
                  child: Stack(children: [
                    Image.file(
                      File(_image!.path),
                      fit: BoxFit.fill,
                    ),
                  ]),
                ),
              Visibility(
                visible: _image == null,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    RawMaterialButton(
                      fillColor: Theme.of(context).primaryColor,
                      elevation: 8,
                      onPressed: () {
                        getImage(isGallery: false);
                      },
                      padding: const EdgeInsets.all(10),
                      shape: const CircleBorder(),
                      child: const Icon(
                        Icons.camera,
                        color: Colors.white,
                        size: 25,
                      ),
                    ),
                    RawMaterialButton(
                      fillColor: Theme.of(context).primaryColor,
                      elevation: 8,
                      onPressed: () {
                        getImage(isGallery: true);
                      },
                      padding: const EdgeInsets.all(10),
                      shape: const CircleBorder(),
                      child: const Icon(
                        Icons.photo_library_rounded,
                        color: Colors.white,
                        size: 25,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Screenshots or Videos

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
I/flutter (16418): Path : /data/user/0/exif_demo/cache/c5d20b6a-29fa-4b6f-9e7f-c099a4f03366/1000014685.jpg
I/flutter (16418): Image ImageWidth: 3072
I/flutter (16418): Image ImageLength: 4080
I/flutter (16418): Image Make: Google
I/flutter (16418): Image Model: Pixel 7
I/flutter (16418): Image Orientation: Horizontal (normal)
I/flutter (16418): Image XResolution: 72
I/flutter (16418): Image YResolution: 72
I/flutter (16418): Image ResolutionUnit: Pixels/Inch
I/flutter (16418): Image Software: HDR+ 1.0.540104767zd
I/flutter (16418): Image DateTime: 2023:09:05 14:39:22
I/flutter (16418): Image YCbCrPositioning: Centered
I/flutter (16418): Image ExifOffset: 242
I/flutter (16418): GPS GPSLatitudeRef: 
I/flutter (16418): GPS GPSLatitude: [0/0, 0/0, 0/0]
I/flutter (16418): GPS GPSLongitudeRef: 
I/flutter (16418): GPS GPSLongitude: [0/0, 0/0, 0/0]
I/flutter (16418): GPS GPSAltitudeRef: 0
I/flutter (16418): GPS GPSAltitude: 0/0
I/flutter (16418): GPS GPSTimeStamp: [0/0, 0/0, 0/0]
I/flutter (16418): GPS GPSImgDirectionRef: 
I/flutter (16418): GPS GPSImgDirection: 0/0
I/flutter (16418): GPS GPSDate: 
I/flutter (16418): Image GPSInfo: 976
I/flutter (16418): Thumbnail ImageWidth: 241
I/flutter (16418): Thumbnail ImageLength: 321
I/flutter (16418): Thumbnail Compression: JPEG (old-style)
I/flutter (16418): Thumbnail Orientation: Horizontal (normal)
I/flutter (16418): Thumbnail XResolution: 72
I/flutter (16418): Thumbnail YResolution: 72
I/flutter (16418): Thumbnail ResolutionUnit: Pixels/Inch
I/flutter (16418): Thumbnail JPEGInterchangeFormat: 1331
I/flutter (16418): Thumbnail JPEGInterchangeFormatLength: 12955
I/flutter (16418): EXIF ExposureTime: 15393/500000
I/flutter (16418): EXIF FNumber: 37/20
I/flutter (16418): EXIF ExposureProgram: Program Normal
I/flutter (16418): EXIF ISOSpeedRatings: 47
I/flutter (16418): EXIF ExifVersion: 0232
I/flutter (16418): EXIF DateTimeOriginal: 2023:09:05 14:39:22
I/flutter (16418): EXIF DateTimeDigitized: 2023:09:05 14:39:22
I/flutter (16418): EXIF OffsetTime: -04:00
I/flutter (16418): EXIF OffsetTimeOriginal: -04:00
I/flutter (16418): EXIF OffsetTimeDigitized: -04:00
I/flutter (16418): EXIF ComponentsConfiguration: YCbCr
I/flutter (16418): EXIF ShutterSpeedValue: 251/50
I/flutter (16418): EXIF ApertureValue: 89/50
I/flutter (16418): EXIF BrightnessValue: 289/100
I/flutter (16418): EXIF ExposureBiasValue: 0
I/flutter (16418): EXIF MaxApertureValue: 89/50
I/flutter (16418): EXIF SubjectDistance: 723/500
I/flutter (16418): EXIF MeteringMode: CenterWeightedAverage
I/flutter (16418): EXIF Flash: Flash did not fire, compulsory flash mode
I/flutter (16418): EXIF FocalLength: 681/100
I/flutter (16418): EXIF SubSecTime: 480
I/flutter (16418): EXIF SubSecTimeOriginal: 480
I/flutter (16418): EXIF SubSecTimeDigitized: 480
I/flutter (16418): EXIF FlashPixVersion: 0100
I/flutter (16418): EXIF ColorSpace: sRGB
I/flutter (16418): EXIF ExifImageWidth: 3072
I/flutter (16418): EXIF ExifImageLength: 4080
I/flutter (16418): Interoperability InteroperabilityIndex: R98
I/flutter (16418): Interoperability InteroperabilityVersion: [48, 49, 48, 48]
I/flutter (16418): EXIF InteroperabilityOffset: 946
I/flutter (16418): EXIF SensingMethod: One-chip color area
I/flutter (16418): EXIF SceneType: Directly Photographed
I/flutter (16418): EXIF CustomRendered: Custom
I/flutter (16418): EXIF ExposureMode: Auto Exposure
I/flutter (16418): EXIF WhiteBalance: Auto
I/flutter (16418): EXIF DigitalZoomRatio: 159/100
I/flutter (16418): EXIF FocalLengthIn35mmFilm: 24
I/flutter (16418): EXIF SceneCaptureType: Standard
I/flutter (16418): EXIF Contrast: Normal
I/flutter (16418): EXIF Saturation: Normal
I/flutter (16418): EXIF Sharpness: Normal
I/flutter (16418): EXIF SubjectDistanceRange: 2
I/flutter (16418): EXIF LensMake: Google
I/flutter (16418): EXIF LensModel: Pixel 7 back camera 6.81mm f/1.85
I/flutter (16418): EXIF Tag 0xA460: 3
I/flutter (16418): JPEGThumbnail:

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.3, on macOS 13.3.1 22E261 darwin-arm64, locale en-US)
    • Flutter version 3.13.3 on channel stable at /Users/davinci/dev_lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2524052335 (4 days ago), 2023-09-06 14:32:31 -0700
    • Engine revision b8d35810e9
    • Dart version 3.1.1
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/xyz/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.81.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • Pixel 7 (mobile) • 2A201FDH2001EX • android-arm64  • Android 13 (API 33)
    • macOS (desktop)  • macos          • darwin-arm64   • macOS 13.3.1 22E261 darwin-arm64
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 116.0.5845.179

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

Bot is counting down the days until it unassigns the issueP2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions