ExifInterface Xamarin.Android SystemError?

Hello
I would like to add GPS information to JPEG images.
bat SystemError Occurred
Could'nt rename to /storage/emulated/0/DCIM/Camera/images.jpg.tmp
Help me!

Xamarin.Android Source
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Android.Media;
using System.IO;
using Android.Graphics;
using Java.IO;

namespace AndroidAA
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);

        try
        {

            ExifInterface exif = new ExifInterface("/storage/emulated/0/DCIM/Camera/images.jpg");
            exif.SetAttribute(ExifInterface.TagGpsLatitude, "35/1,37/1,5538936/100000");
            string a = exif.GetAttribute(ExifInterface.TagGpsLatitude);
        }
        catch (IOException e)
        {
            Toast.MakeText(Android.App.Application.Context, e.Message, ToastLength.Long);
        }
    }
}

}

Posts

  • nagayannnnagayannn Member ✭✭

    I wanted to run it with Xamarin.Foms, but it occurred as a result of executing with Naitive because the same error occurred.
    I do not know why this method can not be used.
    Because I am granting file permissions, I think that it is not amusing to create a new file.

    In the explanation of the SDK, it was said to rewrite the old file and create a new file, but I am trying to create a Temp for some reason.
    If you want to do this you need two arguments: oldFile and outFile.
    Did you release an unusable function?

  • nagayannnnagayannn Member ✭✭

    I confirmed that I can run it on Android studio.
    xamarin is abnormal.
    Please Tell Me Why?

    this Android Studio Source

    package com.nagayama.zac.locationwrite;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.media.ExifInterface;
    import android.widget.Toast;

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
             ExifInterface ex = new ExifInterface("/storage/emulated/0/DCIM/Camera/photo_f8330a06-6e74-4b04-8921-cc2edadbb34b.jpg");
            double test = 0;
            ex.getAltitude(test);
            ex.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "35/1,37/1,5538936/100000");
    
            ex.saveAttributes();
    
            Toast.makeText(this, ex.getAttribute(ExifInterface.TAG_GPS_LATITUDE).toString(), Toast.LENGTH_SHORT).show();
    
        }catch (Exception ex)
        {
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
    
    }
    

    }

  • nagayannnnagayannn Member ✭✭

    All SetAttribute?
    really?

    Save the tag data into the JPEG file. This is expensive because it involves copying
    all the JPG data from one file to another and deleting the old file and renaming
    the other. It's best to use Android.Media.ExifInterface.SetAttribute(System.String,
    System.String) to set all attributes to write and make a single call rather than
    multiple calls for each attribute.
    [Register("saveAttributes", "()V", "GetSaveAttributesHandler")]
    public virtual void SaveAttributes();

  • nagayannnnagayannn Member ✭✭

    ex.ToString Info

    Java.IO.IOException: Could'nt rename to /storage/emulated/0/DCIM/Camera/photo_f8330a06-6e74-4b04-8921-cc2edadbb34b.jpg.tmp
    at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <034d4a9852dd45bea9353cc7776c99f0>:0
    at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <034d4a9852dd45bea9353cc7776c99f0>:0
    at Android.Media.ExifInterface.SaveAttributes () [0x0000a] in :0
    at AndroidAA.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00065] in E:\AndroidAA\AndroidAA\MainActivity.cs:34
    --- End of managed Java.IO.IOException stack trace ---
    java.io.IOException: Could'nt rename to /storage/emulated/0/DCIM/Camera/photo_f8330a06-6e74-4b04-8921-cc2edadbb34b.jpg.tmp
    at android.media.ExifInterface.saveAttributes(ExifInterface.java:1789)
    at md5ef6e4e5ada8a9ad49434e59b236e8def.MainActivity.n_onCreate(Native Method)
    at md5ef6e4e5ada8a9ad49434e59b236e8def.MainActivity.onCreate(MainActivity.java:29)
    at android.app.Activity.performCreate(Activity.java:7016)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2941)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6644)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

  • nagayannnnagayannn Member ✭✭

    MycrosoftSample

    Although it was able to add GPS information to the image with the sample of Microsoft camera, it is very mysterious why the processing that operates with JAVA of MainActivity does not work.
    This is a mystery.
    I want Microsoft to fix it.
    Is there someone who knows the reason?

    Although it solved this time, the fundamental problem is not solved
    Whether the next implementation will work or not is unknown.

    <CustomRenderers\ContentPage\CameraPageRenderer.cs>

        async void TakePhotoButtonTapped(object sender, EventArgs e)
        {
            camera.StopPreview();
    
            var image = textureView.Bitmap;
    
            try
            {
                var absolutePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;
                var folderPath = absolutePath + "/Camera";
                var filePath = System.IO.Path.Combine(folderPath, string.Format("photo_{0}.jpg", Guid.NewGuid()));
    
                var fileStream = new FileStream(filePath, FileMode.Create);
                await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, fileStream);
    
    
                fileStream.Close();
                image.Recycle();
    
    
    
                var intent = new Android.Content.Intent(Android.Content.Intent.ActionMediaScannerScanFile);
                var file = new Java.IO.File(filePath);
                var uri = Android.Net.Uri.FromFile(file);
                intent.SetData(uri);
                MainActivity.Instance.SendBroadcast(intent);
    
                ExifInterface exif = new ExifInterface(filePath);
                exif.SetAttribute(ExifInterface.TagGpsLatitude, "35/1,37/1,5538936/100000");
                exif.SetAttribute(ExifInterface.TagGpsLongitude, "35/1,37/1,5538936/100000");
                //exif.SetAttribute(ExifInterface.TagGpsAltitude, "35/1,37/1,5538936/100000");
                exif.SaveAttributes();
    
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(@"               ", ex.Message);
            }
    
            camera.StartPreview();
        }
    
  • nagayannnnagayannn Member ✭✭
    edited December 2018

    Thank you
    I want you to answer

    You should register in the White House's Mystery Book
    This is an international issue.

Sign In or Register to comment.