Codenameone associating mimetype(PNG) to my App

Viewed 106

i have a problem with associating a mime/file type (PNG) to my App i followed this guide: https://www.codenameone.com/blog/associating-your-app-with-file-extension-mime-types-iphone-android-windows.html i set these build hints (for Android)

android.activity.launchMode=singleTask

and android.xintent_filter like this (i tried image/png and image/* as mimetype)-->

<intent-filter>       <action android:name="android.intent.action.SEND" />       <category android:name="android.intent.category.DEFAULT" />     <data android:mimeType="image/*" />   </intent-filter>   <intent-filter >       <action android:name="android.intent.action.VIEW" />       <category android:name="android.intent.category.DEFAULT" />       <data android:mimeType="image/*" />  </intent-filter>  <intent-filter >       <action android:name="android.intent.action.PICK" />       <category android:name="android.intent.category.DEFAULT" />       <data android:mimeType="image/*" />  </intent-filter>

here my Build Hints as a ScreenShot

my App shows up in the "open with" or "share" Dialog, but the Display.getInstance().getProperty("AppArg", null) returns nothing (null) at start. I created a Dialog after form.show() like this to check...

if i use the Simulator with the argument --> "file://home/pic.png" everything works fine..

i don't know if it matters... i have a OnePlus 8 Pro with Android 11 that i use for testing

here a few Screenshots from the "open with" and "share" Dialog

     public void start() 
    {
        String arg = Display.getInstance().getProperty("AppArg", null);
        if(arg != null)
        {
            System.out.println("opend with arg");
            
            MainForm m = new MainForm();
            Display.getInstance().createThread(new Runnable() 
            {
//              @Override
                public void run() 
                {
                    System.out.println(arg);
                    m.do_something(arg);
                    
                    
                }}, "open from Outside Thread").start();
            
            current = m.create(false);
            current.revalidate();  
            
        }else 
        {
            if(current == null)
            {
                current = new MainForm().create(true);
                Display.getInstance().scheduleBackgroundTask(new Runnable() 
                {
                        @Override
                    public void run() 
                    {
                        if(!Display.getInstance().isSimulator()) 
                        {
                            Storage.getInstance().clearStorage();
                            Storage.getInstance().clearCache();
                        }
                    }
                    
                });
                current.revalidate(); 
            }
        }
        
        current.show();
        if(arg != null)
        {
            Dialog.show("Test", arg + " - " + arg.length(), "OK", "Cancel"); 
        }else 
        {
            Dialog.show("Test", "AppArg = null ", "OK", "Cancel");
        }
//      disp.setProperty("AppArg", null);
        
    }

here my second attempt, with only the necessary code to start the app.

      public void start() 
    {
        arg = Display.getInstance().getProperty("AppArg", null);
        
        if(arg != null) 
        {
            Storage.getInstance().writeObject("Arg", arg);
            Log.p(arg);
        }
//          if(arg != null) 
//          {
//     
            
            
//              MainForm m = new MainForm();
//              Display.getInstance().createThread(new Runnable() 
//              {
////                @Override
//              public void run() 
//              {
//                  System.out.println(arg);
//                  m.do_something(arg);
//                  
//                  
//              }}, "open from Outside Thread").start();
//              
//              current = m.create(false);
//              current.revalidate();  
            
//          }else 
//          {
            if(current == null)
            {
                current = new MainForm().create(true);
//                  Display.getInstance().scheduleBackgroundTask(new Runnable() 
//                  {
//                      @Override
//                      public void run() 
//                      {
//                          if(!Display.getInstance().isSimulator()) 
//                          {
//                              Storage.getInstance().clearStorage();
//                              Storage.getInstance().clearCache();
//                          }
//                      }
//                      
//                  });
                current.revalidate(); 
            }
//          }
        
        current.show();
        if(arg != null)
        {
            
            Dialog.show("Test", arg + " - " + arg.length(), "OK", "Cancel"); 
        }else 
        {
            Dialog.show("Test","" + Storage.getInstance().readObject("Arg") + Log.getLogContent(), "OK", "Cancel");
        }
//      disp.setProperty("AppArg", null);
        
    }

    06-04 13:50:49.618  8269 16651 W System.err: java.io.FileNotFoundException: file:/data/user/0/de.marcus.myapp/files/IMG_20210601_201624_pic.png: open failed: ENOENT (No such file or directory)
06-04 13:50:49.618  8269 16651 W System.err:    at libcore.io.IoBridge.open(IoBridge.java:492)
06-04 13:50:49.618  8269 16651 W System.err:    at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
06-04 13:50:49.618  8269 16651 W System.err:    at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.impl.android.AndroidImplementation.createFileOuputStream(AndroidImplementation.java:6530)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.impl.android.AndroidImplementation.getAppArg(AndroidImplementation.java:2731)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.getProperty(Display.java:3361)
06-04 13:50:49.618  8269 16651 W System.err:    at de.marcus.myapp.MyApplication.start(Unknown Source:8)
06-04 13:50:49.618  8269 16651 W System.err:    at de.marcus.myapp.MyApplicationStub.run(MyApplicationStub.java:163)
06-04 13:50:49.618  8269 16651 W System.err:    at de.marcus.myapp.MyApplicationStub$1.run(MyApplicationStub.java:107)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.processSerialCalls(Display.java:1365)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.edtLoopImpl(Display.java:1307)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.invokeAndBlock(Display.java:1480)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.invokeAndBlock(Display.java:1519)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.impl.android.AndroidImplementation$3.run(AndroidImplementation.java:1147)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.processSerialCalls(Display.java:1365)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.edtLoopImpl(Display.java:1307)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.Display.mainEDTLoop(Display.java:1189)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
06-04 13:50:49.618  8269 16651 W System.err:    at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
06-04 13:50:49.618  8269 16651 W System.err:    at java.lang.Thread.run(Thread.java:923)
06-04 13:50:49.619  8269 16651 W System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
06-04 13:50:49.619  8269 16651 W System.err:    at libcore.io.Linux.open(Native Method)
06-04 13:50:49.619  8269 16651 W System.err:    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
06-04 13:50:49.619  8269 16651 W System.err:    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
06-04 13:50:49.619  8269 16651 W System.err:    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
06-04 13:50:49.619  8269 16651 W System.err:    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7871)
06-04 13:50:49.619  8269 16651 W System.err:    at libcore.io.IoBridge.open(IoBridge.java:478)
06-04 13:50:49.619  8269 16651 W System.err:    ... 19 more

Thanks for every help

Marcus

1 Answers

This might be related to Android launch mode. Try add the build hint:

android.activity.launchMode=singleTask
Related