1

I am trying to change the screensaver on android phone using codenameone, so for that, I'm using native interface process,

I then create my main class and then after I create "MyNativeContent" that inherits from NativeInterface,

here is the content: package com.faugan.addscreen;

import com.codename1.system.NativeInterface;

/**
 *
 * @author ccpita
 */
public interface MyNativeContent extends NativeInterface{
    public void testAndroidNatif();
}

now I make a right click on my interface to generate native access for all platform,

then after I open MyNativeContentImpl.java from my android directory and I do this inside:

package com.faugan.addscreen;

public class MyNativeContentImpl {
    public void testAndroidNatif() {
        // code for screensaver on android
    }

    public boolean isSupported() {
        return true;
    }

}

Now when i compile this, it fails and i am having this errors:

java.lang.ClassNotFoundException: com.faugan.addscreen.MyNativeContentImpl at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.findSystemClass(ClassLoader.java:1001) at com.codename1.impl.javase.ClassPathLoader.findClass(ClassPathLoader.java:100) at com.codename1.impl.javase.ClassPathLoader.loadClass(ClassPathLoader.java:50) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.codename1.system.NativeLookup.create(NativeLookup.java:81) at com.faugan.addscreen.MyApplication.lambda$start$0(MyApplication.java:47) at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349) at com.codename1.ui.Component.pointerReleased(Component.java:3260) at com.codename1.ui.Form.pointerReleased(Form.java:2651) at com.codename1.ui.Component.pointerReleased(Component.java:3239) Rendering frame took too long 722 milliseconds at com.codename1.ui.Display.handleEvent(Display.java:2025) at com.codename1.ui.Display.edtLoopImpl(Display.java:1070) at com.codename1.ui.Display.mainEDTLoop(Display.java:999) at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176) java.lang.NullPointerException at com.faugan.addscreen.MyApplication.lambda$start$0(MyApplication.java:48) at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349) at com.codename1.ui.Component.pointerReleased(Component.java:3260) at com.codename1.ui.Form.pointerReleased(Form.java:2651) at com.codename1.ui.Component.pointerReleased(Component.java:3239) at com.codename1.ui.Display.handleEvent(Display.java:2025) at com.codename1.ui.Display.edtLoopImpl(Display.java:1070) at com.codename1.ui.Display.mainEDTLoop(Display.java:999) at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

Now my questions are:

1) while I am having these errors? is it because this is running in a simulator?

2) can you tell me what to put in the testAndroidNatif() method to change the screensaver on android phones?

Thanks

Diamond
  • 7,428
  • 22
  • 37
Faugan Bidi
  • 167
  • 6

1 Answers1

1

You should start by creating MyNativeContent interface that extends NativeInterface, then right-click on it and select Generate Native Access.

Switch to Files tab and expand the folder native -> android -> com -> faugan -> addscreen. Then open MyNativeContentImpl.java file, this is where all your Android native codes will be added.

You can add more android files in this folder and reference them in MyNativeContentImpl.java file. Remember to return true in the isSupported() method of MyNativeContentImpl.

As for your second question, this is Android specific which you have to do on your own or ask on StackOverflow with android and java tags or search around on sample codes to change screensaver from an Android App. Take a look at this question on SO for instance... android-screen-saver-sample-code

Community
  • 1
  • 1
Diamond
  • 7,428
  • 22
  • 37
  • For the first question, i am still having the error, but for the second one, the link you sent, i just see an xml content as code, how can i integrate that in codenameone? i don't know native android coding, can you please give an example in which you use codenameone and integrate android native code inside? Thanks – Faugan Bidi Mar 03 '17 at 07:01