本机实现不起作用

Native implementation not working

正在尝试代号为 1 的本机 Android 代码,但同样无法在设备上运行。当我在模拟器上尝试时,它不起作用也没有任何消息/错误。但是当在实际设备上尝试相同时,会收到消息 "NO Support"。这意味着在 NativeCall nt = NativeLookup.create(NativeCall.class); 中通过设备 ntnull。我的代码有什么错误吗?

NativeImpl 代码:

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;
}
}

接口:

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

致电:

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);
    }
}

设备截图:

我不知道你的代码是不是有问题,但是你不能在模拟器上测试原生功能。不过,您可以使用 include sources 构建选项并下载源代码并在 Android Studio 或 XCode 中编译它并在这些环境中进行测试。

您可能在控制台中遇到异常,如果您连接设备电缆和 运行 DDMS,您将看到该异常。

不要在本机接口实现中扩展 Activity。如果您需要 Activity 添加单独的 class.

不要在 impl class 中实现本机接口。具体删除:implements userclasses.NativeCall。如果您使用对等组件,它会产生问题...

有关详细信息,请查看 developer guide section on native interfaces