App Crashes on Splash Screen on Android 7 React Native - crash

I'm facing the splash screen issue on Android 7 and lower.
It works fine on Android 7+
but on Android 7 and lower the app crashes as soon as it is opened, without a splash screen app is working fine. Any Solutions?
I have tried using different pngs and styles and color values but still the same issue.
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState)
{
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);
}
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
AndroidManifest.xml
....
<activity
android:name=".SplashActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true"
>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
....

The issue has been solved, basically what I did earlier was that I Placed splash_screen.png in the drawable folder which worked perfectly for Android 7+ but was causing problems for Android 7 and lower.
So I placed the same splash_screen.png in all mipmaps folders and referred to mipmaps as follows in the launch_screen.xml file.
android:src="#mipmap/launch_screen"
After that splash screen worked perfectly for all the versions. Thanks

Related

Linking.getInitialUrl() returns null when opening the app from a local notification from react-native-push-notifications

I have implemented react-native-push-notification to show localNotification from a RemoteMessage that I receive from FCM. I receive the notification but on tapping the notification, Linking.getInitialUrl() returns null. I also have react-native-bootsplash integrated for a splash screen. All the integration is as shown below.
AndroidManifest.xml
...
<activity android:name=".MainActivity" android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:exported="true" android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="#style/BootTheme" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this);
}
It seems that the data associated with the notification intent is not being sent to the Activity. So I am not able to find as to how I send the data.

React Native Android launchMode singleTask getLaunchOptions doesn't get called again

I am developing a react-native app for Android. The app takes image sharing with this intent-filter on the main activity
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
I am able to get the initial sharing intent images by overriding getLaunchOptions(), but with this default launchMode="singleTask", I am not able to get new sharing intent when I have the existing instance of the app running.
So, how can I get the new sharing intent while have an instance of the app running?
PS: changing the launchMode to standard to standard kind of solved my problem, but that will create multiple instances of the app.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have the same problem. If the launchMode isn't in AndroidManifest.xml the situation is like standart.
I've found a solution for my case (receiving intents for .txt files)
In AndroidManifest.xml
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
...
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
In MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
onNewIntent(this.getIntent());
}
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// here are received intents
}
In such way I receive intents when app in background or it is not run at all and only ONE instance of the app.
I'm using React Native 0.61 and was having the exact same problem.
I've used the react-native-share-menu lib to make it work.
Alternatively, If you don't want to add a new lib to your project, it might be worth taking a look at how they did it for Android and modify your code accordingly:
https://github.com/meedan/react-native-share-menu/tree/master/android/src/main

How to auto-run React-Native App on device starup

How to start a react-native app on device startup on Android. I have an Android app developed on react-native and if the app is running and user restarts his device, I wish to auto start my app.
Try using the react-native-autostart npm package.
I created a new .java file named BootReceiver.java:
package com.packageName;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
then I edited the AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="com.packageName.BootReceiver" android:enabled="true" android:exported="true">
<intent-filter >
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>

problem with RTL layout in react native project only when i release apk

i am building an app that need to support only rtl layout no matter what is the phone language.
my problem is when i am in debug mode its work just fine and show the layout rtl as i wanted regardless the phone language but after i release the app it show the the layout direction as the phone language.
can anyone tell me what it may be ?
i tried the following solution:
add this line in the constructor of the main page
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
also add this line in android manifest:
android:supportsRtl="true"
both in activity tag and also in application tag
manifest :
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:supportsRtl="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
constructor in App.js
constructor(){
super();
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
}
this is the good result
https://i.imgur.com/S2nV0a4.jpg
this one is not what i want
https://i.imgur.com/VXzYWI1.png
Add these three lines in your MainActivity.java
+ import com.facebook.react.modules.i18nmanager.I18nUtil;
#Override
public void onCreate() {
super.onCreate();
// FORCE RTL
+ I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
+ sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
....
}

Android: Branch.io tutorial: Branch.getAutoInstance(this);

I am trying to get Branch.io to work on Android, but I am running into:
myapplication.MainActivity cannot be cast to android.app.Application
I then changed:
Branch.getAutoInstance(this);
To:
Branch.getInstance();
In onCreate of the Activity.
Then I get:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean io.branch.referral.Branch.initSession(io.branch.referral.Branch$BranchReferralInitListener, android.net.Uri, android.app.Activity)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
Can you help me get the basic up and running?
Following is my AndroidManifest.xml: (note: the branch_key is added in my app code)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.x.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_xxxxxxxxxxxxxxx" />
<activity android:name=".MainActivity">
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
My main Activity:
package com.example.chg.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import org.json.JSONObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Branch.getAutoInstance(this);
Branch.getInstance();
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
Alex with Branch.io here:
We recently made some changes to our tutorial, and it looks like we missed a few things. I appreciate you posting about this — we'll be pushing an update later today for more clarity.
In this particular case, there are two issues:
A mixup between the Application onCreate() and Activity onCreate() methods, neither of which are actually needed for a basic implementation.
A missing Application class (we accidentally deleted this step from our tutorial completely — my apologies).
To get up and running, update your files as follows:
AndroidManifest.xml
You have three options here:
1. Use the Branch application class (easiest)
If you don't already have a custom application class, this is the simplest approach. Add android:name="io.branch.referral.BranchApp" to your Application class:
Edit: snippet UPDATED per comments below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chg.appbranch_01">
<meta-data android:name="io.branch.sdk.BranchKey" android:value="xxx" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="io.branch.referral.BranchApp">
<!--Enable test mode to see debugging data
(https://dev.branch.io/getting-started/integration-testing/guide/android/#use-debug-mode-to-simulate-fresh-installs)-->
<meta-data android:name="io.branch.sdk.TestMode" android:value="true" />
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="theapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
2. Extend your Application class with the BranchApp class
If you already have a custom Application class, this is the simplest approach. Your AndroidManifext.xml file will look like this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.your.app.CustomApplicationClass" >
Your custom Application class (CustomApplicationClass in the example above) will look like this:
public final class CustomApplicationClass extends YourApp {
#Override
public void onCreate() {
super.onCreate();
}
}
3. Integrate directly into your custom application class
The most custom approach, for advanced implementations. You'd have your AndroidManifext.xml file set up the same as above:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.your.app.CustomApplicationClass" >
And then configure your Application class as follows:
public final class CustomApplicationClass {
#Override
public void onCreate() {
super.onCreate();
Branch.getAutoInstance(this);
}
}
Activity Definition
Remove the onCreate() calls. They aren't needed here and are actually the cause of your error message (Branch.getAutoInstance(this) was passing the Activity context as this, when the SDK was expecting the Application context from option 3 above).
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
Sorry for the inconvenience!