Ways to utilize built-in features from a Java library that has been incorporated

I have embarked on a project to create a Nativescript wrapper for a Java library in order to harness its functionalities for a Nativescript application. Despite the lack of detailed articles on this topic, I have decided to turn this into a plugin wrapper as there doesn't seem to be a straightforward method within the Nativescript app itself.

The specific Java library I am integrating is Libsignal-protocol-java. Following the cloning of the Nativescript Plugin Seed, I have added this Java library as a dependency:

src/platforms/android/include.gradle

android {   
}

dependencies {
  compile 'org.whispersystems:signal-protocol-android:2.3.0+'
}

Identifying the package housing the method I wish to access within the Java source was my next step:

KeyHelper.generateRegistrationId();
(source). It was noted in an article that specifying the package during class and method instantiation is essential.

Following that, I configured my libsignal-protocol.common.ts like so in an attempt to utilize the native method:

src/libsignal-protocol.common.ts

import { Observable } from 'tns-core-modules/data/observable';

export class Common extends Observable {

    constructor() {
      // does not work
      let test1 = new org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();

      // does not work
      let test2 = org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();

      console.log(test1);
      console.log(test2);
    }
}

To my disappointment, the logger revealed the following error:

System.err: Error: java.lang.Exception: Failed resolving method generateRegistrationId on class org.whispersystems.libsignal.util.KeyHelper

At this point, I am uncertain about the next steps to take. Opting to create a wrapper for this impressive Java library seemed more secure and organized than attempting to use their JavaScript library via browserify, especially considering the required features not supported by Nativescript.

Any guidance or recommendations would be greatly appreciated! For reference, here are some articles I came across that have guided me to my current status on this matter.


Sources

  • Using libsodium in Android/Nativescript
  • How to use JAR file in Nativescript

Answer №1

Looking at the source code, the generateRegistrationId method requires a boolean argument.

public static int generateRegistrationId(boolean extendedRange) {
    try {
      SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
      if (extendedRange) return secureRandom.nextInt(Integer.MAX_VALUE - 1) + 1;
      else               return secureRandom.nextInt(16380) + 1;
    } catch (NoSuchAlgorithmException e) {
      throw new AssertionError(e);
    }
  }

Therefore, make sure to pass a boolean value when calling the method,

let test2 = org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId(false);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript code for the submit button to proceed or halt the form submission

Within my JSP file, I have the following code snippet: <input type="submit" value="Transfer ULD" onclick="doSomething();" name="_eventId_transferULDTransition"/> The doSomething() function mentioned above is a JavaScript method. function doSomethi ...

Converting JSON data into Java objects

{ "city" : "THAYNE", "loc" : [ -111.011354, 42.933026 ], "pop" : 505, "state" : "WY", "_id" : "83127" } I have been given some JSON syntax and I am looking to convert it into a Java object. Initially, I crea ...

Vue 2.0 custom filter not producing any output

I am attempting to create a customized filter that identifies and returns the items that correspond to a given input. It functions effectively with basic arrays like ['Apple', 'Banana', 'Cupple'], but encounters difficulty whe ...

Tips on obtaining the screen resolution and storing it in a PHP variable

Hey there! I've run into a bit of a roadblock that I'm struggling to overcome. I know that I need to incorporate some JavaScript to solve this issue, but I'm having trouble grasping how to do so. Here's the script I'm working with: ...

Sending a JavaScript variable to PHP in order to specify the timezone

I'm working on setting the timezone for every user in the navbar.php file that's included on all pages of my website. After finding a helpful js script, I am able to echo the variable 'Europe/Brussels' to identify my timezone correctly. ...

The Skeleton-Avatar and ImageButton components in MUI React have had their backgrounds reshaped into perfect ovals

I am facing an issue with the mui Stack where all the background shapes of the Skeleton Avatar and background area are turning into oval or ellipsoid shapes. I have tried setting equal width and height for Avatar but it has not solved the problem. Is ther ...

Guide to refining a JSON array using a pre-established list

I'm in need of assistance figuring out how to accomplish the following task: Below is the code snippet I am working with: public class Data { public string FirstName; public string LastName; public int Age; } var data = new Data { //this objec ...

Node.js seems to be having trouble with emitting events and catching them

I'm having trouble troubleshooting my code. // emitter.js var EventEmitter = require('events').EventEmitter; var util = require('util'); function Loadfun(param1, param2, db){ function __error(error, row){ if(error){ ...

What is the best way to align a modal with a layout when it appears far down the components hierarchy?

Struggling with creating a React modal and facing some issues. Let's consider the structure below: React structure <ComponentUsingModal> <Left> <ButtonToActivateModal> ... </ButtonToActivateModa ...

Why is there a node_modules folder present in the npm package I authored when using it as a dependency in another module?

After successfully launching my first npm package, I noticed something strange when installing it as a dependency in my project. Upon exploring the project folder in node_modules, I discovered an unexpected node_modules folder containing just one package ...

Is it possible to perform a GET request between a site using HTTPS and another using HTTP?

https://i.stack.imgur.com/AlWYJ.png I recently hosted my site on Shopify using HTTPS, and then I attempted to make a GET request via Angular to a site that uses HTTP. Angular <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.j ...

Tips for applying stroke and shadow effects specifically when the mouse is moving over a canvas:

How can we create a shadow and stroke effect for circles drawn using HTML canvas only during mouse hover? I have two circles and would like to add a shadow and stroke effect when the mouse hovers over them. However, the issue is that once the mouse moves ...

Obtaining the source code from a different domain website with the help of jQuery

Is there a way to extract part of the source code from a YouTube page without using server-side programming? I've tried cross-domain AJAX techniques like Yahoo YQL and JsonP. While Yahoo YQL allows me to grab part of the source code, I'm facing ...

Gson javax.json serializer/deserializer plugin

I'm currently developing a custom Gson serializer and deserializer for handling java.javax.JsonObjects: public static class JavaxJsonObjConverter implements JsonSerializer<JsonObject>, JsonDeserializer<JsonObject> { @Override public ...

Instructions for importing a CSV file into PostgreSQL with Node.js

Just dipping my toes into the world of node js. I've got a csv file sitting on my local system that I'm eager to upload to my local PostgreSQL Database using node js. Here's what I've been experimenting with: var csv = require(' ...

Sending a form using an AngularJS dropdown menu

I have recently started using angularjs and decided to switch out a traditional html <select> box for an angular modal select box. The select box successfully populates with data from a $http ajax request, but I am facing issues with form submission ...

Strip the pound symbol from the end of a URL during an AJAX request

When I click on the News tab in my Rails application (version 2.3.4 and Ruby 1.8.7), an Ajax call is triggered to load data. <a href="News" onclick="load_feed();"><u>Show More...</u></a> <script> function load_feed() { $.a ...

Error: Cannot execute products.map in React JS because it is not a function

I'm encountering a TypeError: products.map is not a function error while attempting to iterate or map through the objects in my current state. I am fetching products from an API and storing them in state with the intention of displaying these objects. ...

Move a 'square' to a different page and display it in a grid format after clicking a button

I am currently developing a project that allows students or schools to add projects and search for collaborators. On a specific page, users can input project details with a preview square next to the fields for visualization. Once the user uploads the ...

Creating a dynamic image carousel using jQuery

Today, I completed the jQuery course on Code Academy and am now trying to create an image slider using it. While I have a general idea of how it should work, I feel like I'm missing a key element. My goal is to have the slider continuously running whe ...