Helpful things you need to know

Hello, I am Kumaraswamy.
I have made a list of things which might help you in the future.


Encode to Base 2 (Binary)

math_number_radix

Instead of encoding number by number, you could do more using JavaScript.
To encode text into binary form, first paste the below code into text variable.

function toBase2(text) {
  var length = text.length,
      output = [];
  for (var i = 0;i < length; i++) {
    var bin = text[i].charCodeAt().toString(2);
    output.push(Array(8-bin.length+1).join("0") + bin);
  } 
  return output.join(" ");
}

So here is a method in Js to encode text into binary.
Credits : StackOverFlow

Now to take advantage of the WebView component. We will run a script like in the above image.
In the first join, we will attach the script from the variable so that we can call it using the toBase2("Text") method. Then using window.AppInventor.setWebViewString() method we will call the toBase2() method along with the parameter which is text.


window.AppInventor.setWebViewString() Method raises when WebViewStringChange event and in the value we get the binary encoded result.



Encode URI

Note: There is already block in Web component, this is just for learning

Let's say in some case you're making a request to Web. Then to encode the URI which is the input/text you're sending.

So here too we will run JS and change the WevViewString



Base64 Encoding & Decoding

So to encode the text into Base64 8 bit representation, we will use btoa() method in JavaScript which means to encode to base64

And to decode the encoded result we will use atob() method to decode back.

Get the ASCII code (Decimal base) of the character

To get the ASCII code we will use codePointAt(0) method in JavaScript. You can replace 0 with the letter you want to decode in string/text, 0 means the first letter here.



Filter Emojis

To remove emojis in the text we will use :

replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''

Credits : StackOverFlow



Is Page secure

To check the current page/website is secure or not use.


It returns true/false, compares them with the text block and not logic block.

Check if a string contains emoji

Increase/Decrease Phone internal volume

component_method
component_method (1)



Clear app data

component_method

Clears the app data including all allowed permissions. Its like a reset of the app.



Thanks!

16 Likes

Wow Nice Tutorial :star_struck:

1 Like

Awesome Guide @Kumaraswamy :heart_eyes:

1 Like

A post was split to a new topic: Problem with Javascript function