Categories
discuss

Intl.numberformat in React native works fine when running in ios but not in android

I am developing an app with React Native to run on IOS and Android. I use Intl.numberformat() to print currency, and it works smoothly when the app runs on IOS, but I get this error when running on Android: ReferenceError: Can't find variable: Intl.

How can I make it run in both plataforms?

Answer

I had faced similar issue. The issue was with Javascript core which runs the react- native. There are two ways to overcome this.

1.Method 1 You’ll have to integrate latest javascript core into your android build or upgrade react native to 0.59

You can find it here

  1. Method 2 Add or override the following code in your app/build.gradle

def jscFlavor = ‘org.webkit:android-jsc-intl:+’

Clean build and react-native run android

Categories
discuss

Android WebView load from internal storage | Android 11 | Android R

Actually my requirement is I want to load dynamic files into WebPage like image. video, audio etc.., it’s either from asset or apps own files directory, that’s not a problem.

I tried using following two ways.

Way 1

Here is my html file is in assets folder, and I have 123.jpg in both assets folder and also internal folder,

Home.html,

<!DOCTYPE html>
<html>
   <head>
      <title>Page Title</title>
   </head>
   <body>
      <h1>Image testing</h1>
      <p>Relative Path</p>
      <img src="123.jpg" alt="Italian Trulli" width="100%">
      <p>From Files Directory</p>
      <img src="file:////data/user/0/com.guna.testapplication/files/123.jpg" alt="Italian Trulli" width="100%">
   </body>
</html>

And I am loading it into webview like

webView.loadUrl("file:///android_asset/Home.html")

And here is my output for 29,

enter image description here

Look, both from Asset and files directory loaded as expected.

And here is for 30,

enter image description here

Here only from asset directory loaded. And files directory not loaded.

Way 2

Here I’m loading both html and image from internal storage.

Home.html

<!DOCTYPE html>
<html>
   <head>
      <title>Page Title</title>
   </head>
   <body>
      <h1>Image testing</h1>
      <img src="123.jpg" alt="Italian Trulli" width="100%">
   </body>
</html>

And I’m loading webview like this,

webView.loadUrl("file:////data/user/0/com.guna.testapplication/files/Home.html")

If my compileSdkVersion 29 and also targetSdkVersion 29 this works well,

Output for 29

enter image description here

If I change SdkVersion like compileSdkVersion 30 and also targetSdkVersion 30 this gives me access denied error,

Output on 30

enter image description here

Manifest

<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">
    <activity
        android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Answer

Found the Answer,

From setAllowFileAccess we have to explicitly set it to true when we are targeting Build.VERSION_CODES.R, otherwise it wont allow you to load file:// URLs.

So the solution is

webView.settings.allowFileAccess = true

In Java,

webView.getSettings().setAllowFileAccess(true);

This works as expected for both scenario.

Categories
discuss

Exception in thread “main” java.lang.NumberFormatException: For input string: “9000000000000000” under radix 16

I try to run this code but it occur error.

System.out.println(Long.parseLong("9000000000000000", 16));

As we know that the minimum number of long is -9,223,372,036,854,775,808 and 0x9000000000000000 is -8,070,450,532,247,928,832 why it will occur error?

Answer

9000000000000000 base 16 is a positive number since there is no sign. Since a long is signed, the greatest number that it can hold is 0x7FFF_FFFF_FFFF_FFFF. So yours is too great.

If you want -8,070,450,532,247,928,832, use parseUnsignedLong():

        System.out.println(Long.parseUnsignedLong("9000000000000000", 16));

Output:

-8070450532247928832

Now values up to 0xFFFF_FFFF_FFFF_FFFF are accepted.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..