Prashant Rahate
Prashant Rahate

Reputation: 163

Native implementation not working

Trying native Android code with codename one, but same is not working on device. When i try on simulator it is not work also no any message / error. But when same is tried on actual device then got Message "NO Support". It means in NativeCall nt = NativeLookup.create(NativeCall.class); through device nt is null. Is there any mistake in my code ?

NativeImpl code :

public class NativeCallImpl extends Activity implements userclasses.NativeCall{

public void setNative(String param) {
    Intent intent = new Intent(this, UploadData.class);  
    PendingIntent pendingIntent = PendingIntent.getBroadcast(  
                                  this.getApplicationContext(), 234324243, intent, 0);  
     AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
     alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()  
                                  + (10 * 1000), pendingIntent);
     Toast.makeText(getApplicationContext(), "Native call", Toast.LENGTH_LONG).show();
}

public boolean isSupported() {
    return true;
}
}

Interface :

public interface NativeCall extends NativeInterface{
public void setNative(String mobileNumber);
//public boolean isSupported();
}

Call:

private void autoUpdate(){
    NativeCall nt= NativeLookup.create(NativeCall.class);
    if(nt!=null){
        nt.setNative(getMobileNumber());
    }else{
        Dialog.show("NO Support", "No Native Support", "OK", null);
    }
}

Screenshot of device : enter image description here

Upvotes: 1

Views: 83

Answers (2)

Shai Almog
Shai Almog

Reputation: 52760

You are probably getting an exception in the console which you will see if you connect the device cable and run DDMS.

Do not extend Activity in the native interface implementation. If you need an Activity add a separate class.

Don't implement the native interface in the impl class. Specifically remove this: implements userclasses.NativeCall. It will create issues if you work with peer components...

For more details check out the developer guide section on native interfaces.

Upvotes: 1

James H
James H

Reputation: 1116

I don't know if there's a problem with your code, but you can't test native functionality on the simulator. You can use the include sources build option and download the source code and the compile it in Android Studio or XCode and test it in those environments, though.

Upvotes: 1

Related Questions