invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
625 stars 121 forks source link

App Open ads Show Immediately after interstitial ads is closed . #554

Closed AftabUfaq closed 2 months ago

AftabUfaq commented 3 months ago

What happened?

here is the implementation of my app . there is an issue that app open ads is immediate shown after interstitial ads.

import notifee from '@notifee/react-native';
import React, { useEffect, useRef, useState } from 'react';
import {
  AppState,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';
import Geolocation from 'react-native-geolocation-service';
import {
  AdEventType,
  AppOpenAd,
  InterstitialAd,
} from 'react-native-google-mobile-ads';
import { moderateScale } from 'react-native-size-matters';
import Toast from 'react-native-toast-message';
import Entypo from 'react-native-vector-icons/Entypo';
import { useDispatch, useSelector } from 'react-redux';
import Config from '../../env';
import ALTITUE_METER from '../assets/svgs/Altitude_Meter.svg';
import ANCHOR from '../assets/svgs/Anchor.svg';
import AREA_CODES from '../assets/svgs/AreaCodes.svg';
import COMPASS from '../assets/svgs/Compass.svg';
import LAT_LONG from '../assets/svgs/GPS_COORDS.svg';
import LOCATION_FIND from '../assets/svgs/Location_Find.svg';
import LOCATION_GPS from '../assets/svgs/Location_GPS.svg';
import LOCATION_ALERT from '../assets/svgs/STATION_ALERT.svg';
import SPEED_METER from '../assets/svgs/Speed_Meter.svg';
import WORLD from '../assets/svgs/World.svg';
import CustomMaps from '../components/CustomMaps';
import NativeAdImage from '../components/NativeAdImage';
import { MainRoutes } from '../constants/Routes';
import fonts from '../constants/fonts';
import { SCREEN_WIDTH, hp, wp } from '../constants/scaling';
import colors from '../constants/theme';
import { setCanShowAppOpenAds } from '../store/actions/adsAction';
import {
  setAddressLocation,
  setLocation,
  setLocationPermission,
  setRouteName,
} from '../store/actions/userActions';
import { SearchNumberValidation } from '../validation/SearchNumberValidation';

const HomeScreen = ({navigation}) => {
  const {selectedLanguage} =  useSelector(state => state.languageReducer)
  const {AddsConfig} = useSelector(state => state.remoteAdsReducer)

const interstitial = InterstitialAd.createForAdRequest(AddsConfig.INTER_HOME?Config.INTER_HOME:"", {
  requestNonPersonalizedAdsOnly: true,
});

const appOpenAd = AppOpenAd.createForAdRequest(AddsConfig.APP_OPEN_AD_ID ?Config.APP_OPEN_AD_ID:"", {
  requestNonPersonalizedAdsOnly: false,
});
  const data = [
    {
      id: '1',
      icon: (
        <LOCATION_FIND width={moderateScale(25)} height={moderateScale(35)} />
      ),
      text: selectedLanguage.find_address,
      route: MainRoutes.AddressFinderScreen,
    },
    {
      id: '2',
      icon: <SPEED_METER width={moderateScale(25)} height={moderateScale(35)} />,
      text: selectedLanguage.speedo_meter,
      route: MainRoutes.SpeedMeterScreen,
    },
    {
      id: '3',
      icon: (
        <WORLD
          style={{color: colors.textColor}}
          width={moderateScale(25)}
          height={moderateScale(35)}
        />
      ),
      text: selectedLanguage.world_clock,
      route: MainRoutes.WorldClockScreen,
    },
  ];

  const data2 = [
    {
      id: '1',
      icon: (
        <AREA_CODES
          style={{color: colors.textColor}}
          width={moderateScale(25)}
          height={moderateScale(35)}
        />
      ),
      text:selectedLanguage.area_codes,
      route: MainRoutes.AreaCodeScreen,
    },
    {
      id: '2',
      icon: <COMPASS width={moderateScale(25)} height={moderateScale(35)} />,
      text: selectedLanguage.compass,
      route: MainRoutes.CompassScreen,
    },
    {
      id: '3',
      icon: (
        <ALTITUE_METER width={moderateScale(25)} height={moderateScale(35)} />
      ),
      text: selectedLanguage.altitude_meter,
      route: MainRoutes.AltitudeMeterScreen,
    },
  ];

  const data3 = [
    {
      id: '2',
      icon: (
        <LOCATION_ALERT width={moderateScale(25)} height={moderateScale(35)} />
      ),
      text: selectedLanguage.station_meter,
      route: MainRoutes.LocationAlertScreen,
    },
    {
      id: '3',
      icon: <LAT_LONG width={moderateScale(25)} height={moderateScale(35)} />,
      text: selectedLanguage.gps_coords,
      route: MainRoutes.CoordsAddressFinderScreen,
    },
    {
      id: '3',
      icon: (
        <View style={{height: moderateScale(25), marginBottom: moderateScale(5)}}>
          <Entypo size={moderateScale(25)} name={'network'} color={'#1d2438'} />
        </View>
      ),
      text: selectedLanguage.ip_address,
      route: MainRoutes.IPAddressFinderScreen,
    },
  ];
  const dispatch = useDispatch();
  const [ad_count, setAdCount] = useState(3);
  const appState = useRef(AppState.currentState);
  const [appStateVisible, setAppStateVisible] = useState(appState.current);
  const [is_ad_loaded, setAdLoaded] = useState(false)
  const {canShowAppOpenAd} = useSelector(state => state.adReducer);

  const {routeName} = useSelector(state => state.userReducer);
  const [mobile_number, setMobileNumber] = useState('');
  const [interstialAdsShowing, setInterstialAdsShowing] = useState(false);
  const [country, setCountry] = useState({
    name: 'United State',
    code: 'US',
    callingCode: '1',
  });
  useEffect(() => {
    const subscription = AppState.addEventListener('change', nextAppState => {
      // console.log(interstialAdsShowing,"interstialAdsShowing After Subscription");
      // console.log(appStateVisible, "appStateVisible After Sucscription");
      // console.log(appOpenAd.loaded,  !interstialAdsShowing, AddsConfig.APP_OPEN_AD_ID,"Condition for show Ads");
      if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
        //console.log("App IS COMMING TO FORGROUND");
        if (appOpenAd.loaded && !interstialAdsShowing && AddsConfig.APP_OPEN_AD_ID) {
          appOpenAd.show();
        }
      } else {
        console.log("APP_IS_GOING_TO_BACKGROUND");
        appOpenAd.load();
       // dispatch(setCanShowAppOpenAds(true));
      }
      appState.current = nextAppState;
      setAppStateVisible(appState.current);
    });

    return () => {
      subscription.remove();
    };
  }, [interstialAdsShowing,appStateVisible]);

  const validate_mobile_number = () => {
    SearchNumberValidation(mobile_number, country)
      .then(data => {
        navigation.navigate(MainRoutes.FindNumberDetailsScreen, data);
      })
      .catch(err => {
        Toast.show({
          type: 'error',
          text1: 'Invalid Number Provided',
          text2: `Please enter a valid mobile number`,
          position: 'bottom',
        });
      });
  };

  useEffect(() => {

    interstitial.addAdEventListener(AdEventType.OPENED, () => {
      setInterstialAdsShowing(true);
    });

    interstitial.addAdEventListener(AdEventType.ERROR, () => {
      if (ad_count != 0) {
        setAdCount(ad_count => ad_count - 1);
        interstitial.load();
        setAdLoaded(false);
      }
    });

    interstitial.addAdEventListener(AdEventType.LOADED, () => {
      setAdLoaded(true);
      setAdCount(3);
    });

    interstitial.addAdEventListener(AdEventType.CLOSED, () => {
      dispatch(setCanShowAppOpenAds(false));
      navigation.navigate(routeName);

      setAdLoaded(false);
      interstitial.load();
      setTimeout(() => {
        setInterstialAdsShowing(false)
      }, 2000);
    });
    return () => {
      interstitial.removeAllListeners();
    };
  }, [routeName]);

  const SetNavigationName = item => {

    if(item == "WorldClockScreen" || item == "CompassScreen" || item == "IPAddressFinderScreen"  ){
      navigation.navigate(item);
    }else if (is_ad_loaded) {
      dispatch(setRouteName(item)).then(data => {
        interstitial.show();
      });
    } else {
      interstitial.load()
      navigation.navigate(item);
    }
  };

  return (
    <View style={{...styles.container}}>
      <StatusBar backgroundColor={'#fff'} barStyle={'dark-content'} />
      <View
        style={{
          width: wp(100),
          position: 'absolute',
          top: 0,
          height: moderateScale(260),
        }}>
        <CustomMaps
          mobile_number={mobile_number}
          setMobileNumber={setMobileNumber}
          country={country}
          setCountry={setCountry}
          validate_mobile_number={validate_mobile_number}
        />
      </View>
      <View style={styles.ModalView}>
        <ScrollView
          showsVerticalScrollIndicator={false}
          style={{backgroundColor: '#fff'}}>
          <TouchableOpacity
            onPress={() => SetNavigationName(MainRoutes.GpsTrackerScreen)}
            style={styles.GpsBox}>
            <LOCATION_GPS
              width={moderateScale(45)}
              height={moderateScale(45)}
            />
            <View style={{marginLeft: moderateScale(10)}}>
              <Text style={styles.GPSText}>{selectedLanguage.gps_tracker}</Text>
              <Text style={{...styles.GPSText, fontSize: moderateScale(10)}}>
                {selectedLanguage.quickly_find_your_address}
              </Text>
            </View>
            <ANCHOR
              style={styles.Anchor}
              width={moderateScale(12)}
              height={moderateScale(12)}
            />
          </TouchableOpacity>
          <View style={styles.Row}>
            {data.map((item, index) => {
              return (
                <TouchableOpacity
                  onPress={() => SetNavigationName(item.route)}
                  style={styles.IconTextBox}
                  key={`${index}`}>
                  {item.icon}
                  <Text style={styles.boxText}>{item.text}</Text>
                </TouchableOpacity>
              );
            })}
          </View>
          <View style={styles.AdView}>
            <NativeAdImage />
          </View>
          <View style={styles.Row}>
            {data2.map((item, index) => {
              return (
                <TouchableOpacity
                  onPress={() => SetNavigationName(item.route)}
                  style={styles.IconTextBox}
                  key={`${index}`}>
                  {item.icon}
                  <Text style={{...styles.boxText, fontSize: moderateScale(9)}}>
                    {item.text}
                  </Text>
                </TouchableOpacity>
              );
            })}
          </View>
          <View
            style={{
              ...styles.Row,
              height: moderateScale(60),
            }}>
            {data3.map((item, index) => {
              return (
                <TouchableOpacity
                  onPress={() => SetNavigationName(item.route)}
                  style={styles.IconTextBox}
                  key={`${index}`}>
                  {item.icon}
                  <Text style={{...styles.boxText, fontSize: moderateScale(9)}}>
                    {item.text}
                  </Text>
                </TouchableOpacity>
              );
            })}
          </View>
          <View style={{height: hp(2)}} />
        </ScrollView>
      </View>
    </View>
  );
};

export default HomeScreen;

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    backgroundColor: colors.white,
    alignItems: 'center',
  },
  ModalView: {
    marginTop: moderateScale(250),
    borderTopRightRadius: moderateScale(20),
    borderTopLeftRadius: moderateScale(20),
    height: hp(100) - moderateScale(250),
    backgroundColor: colors.white,
    width: wp(100),
    paddingTop: moderateScale(15),
    paddingHorizontal: moderateScale(15),
  },
  GpsBox: {
    backgroundColor: colors.primaryColor,
    width: SCREEN_WIDTH,
    flexDirection: 'row',
    alignItems: 'center',
    height: moderateScale(65),
    padding: moderateScale(10),
    borderRadius: moderateScale(10),
  },
  Anchor: {
    position: 'absolute',
    right: moderateScale(20),
    alignSelf: 'center',
  },
  GPSText: {
    fontFamily: fonts.Medium,
    fontSize: moderateScale(14),
    color: colors.white,
  },
  Row: {
    flexDirection: 'row',
    backgroundColor: '#fff',
    alignItems: 'center',
    height: moderateScale(90),
    alignSelf: 'center',
    width: SCREEN_WIDTH,
    justifyContent: 'space-between',
  },
  IconTextBox: {
    paddingVertical: moderateScale(7),
    borderColor: colors.borderColor,
    borderWidth: moderateScale(0.75),
    borderRadius: moderateScale(6),
    justifyContent: 'center',
    alignItems: 'center',
    width: moderateScale(100),
  },
  boxText: {
    fontFamily: fonts.Medium,
    fontSize: moderateScale(11),
    color: colors.textColor,
  },
  AdView: { 
    borderRadius: moderateScale(6),
    borderWidth: moderateScale(1),
    alignItems: 'center',
    justifyContent: 'center',
    paddingVertical:moderateScale(5),
    borderColor: colors.borderColor,
  },
});

Platforms

Only on Android

React Native Info

System:
  OS: macOS 14.0
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 2.04 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.0
    path: ~/.nvm/versions/node/v18.17.0/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.yarn/bin/yarn
  npm:
    version: 10.5.0
    path: ~/repos/GPSTracker/node_modules/.bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.0
    path: /Users/apple/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK:
    API Levels:
      - "25"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 19.1.0
      - 20.0.0
      - 21.1.2
      - 22.0.1
      - 23.0.1
      - 23.0.2
      - 23.0.3
      - 24.0.0
      - 24.0.1
      - 24.0.2
      - 24.0.3
      - 25.0.0
      - 25.0.1
      - 25.0.2
      - 25.0.3
      - 26.0.0
      - 26.0.1
      - 26.0.2
      - 26.0.3
      - 27.0.0
      - 27.0.1
      - 27.0.2
      - 27.0.3
      - 28.0.0
      - 28.0.1
      - 28.0.2
      - 28.0.3
      - 29.0.0
      - 29.0.1
      - 29.0.2
      - 29.0.3
      - 30.0.0
      - 30.0.1
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 32.1.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
      - 34.0.0
      - 34.0.0
      - 34.0.0
      - 34.0.0
    System Images:
      - android-30 | Google Play Intel x86 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11255304
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/apple/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: ^18.2.0
  react-native:
    installed: 0.73.5
    wanted: ^0.73.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Are your using Typescript?

package.json

{
  "name": "GPSTracker",
  "version": "2.1.0",
  "private": true,
  "scripts": {
    "release": "npx react-native run-android --mode=release",
    "dev": "npx react-native run-android",
    "ios": "react-native run-ios",
    "start": "npx react-native start",
    "test": "jest",
    "lint": "eslint .",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@notifee/react-native": "^7.8.2",
    "@react-native-async-storage/async-storage": "^1.22.3",
    "@react-native-clipboard/clipboard": "^1.13.2",
    "@react-native-community/blur": "^4.4.0",
    "@react-native-community/netinfo": "^11.3.1",
    "@react-native-community/slider": "^4.5.0",
    "@react-native-firebase/app": "^19.0.1",
    "@react-native-firebase/remote-config": "^19.0.1",
    "@react-native-masked-view/masked-view": "^0.3.1",
    "@react-navigation/bottom-tabs": "^6.5.16",
    "@react-navigation/drawer": "^6.6.11",
    "@react-navigation/material-bottom-tabs": "^6.2.24",
    "@react-navigation/native": "^6.1.14",
    "@react-navigation/native-stack": "^6.9.22",
    "@reduxjs/toolkit": "^2.2.1",
    "@shopify/flash-list": "^1.6.3",
    "google-libphonenumber": "^3.2.34",
    "i": "^0.3.7",
    "lottie-react-native": "^6.7.0",
    "moment": "^2.30.1",
    "npm": "^10.5.0",
    "patch-package": "^8.0.0",
    "postinstall-postinstall": "^2.1.0",
    "react": "^18.2.0",
    "react-native": "^0.73.5",
    "react-native-admob-native-ads": "^0.6.6",
    "react-native-android-location-enabler": "^2.0.1",
    "react-native-barometer": "^1.0.18",
    "react-native-compass-heading": "^1.5.0",
    "react-native-contacts": "^7.0.8",
    "react-native-cool-speedometer": "1.1.0",
    "react-native-device-country": "^1.0.4",
    "react-native-device-info": "^10.13.1",
    "react-native-fast-image": "^8.6.3",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "^2.15.0",
    "react-native-google-mobile-ads": "^13.0.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-localize": "^3.0.6",
    "react-native-maps": "^1.10.3",
    "react-native-modal": "^13.0.1",
    "react-native-pager-view": "^6.2.3",
    "react-native-permissions": "^4.1.4",
    "react-native-reanimated": "^3.7.2",
    "react-native-responsive-fontsize": "^0.5.1",
    "react-native-responsive-screen": "^1.4.2",
    "react-native-safe-area-context": "^4.9.0",
    "react-native-screens": "^3.29.0",
    "react-native-size-matters": "^0.4.2",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^15.0.0",
    "react-native-svg-transformer": "^1.3.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.2.0",
    "react-native-vector-icons": "^10.0.3",
    "react-redux": "^9.1.0",
    "redux": "^5.0.1",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "rn-range-slider": "^2.2.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

app.json

{
  "name": "GPSTracker",
  "displayName": "GPSTracker",
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-794898570fdfdfdf",
    "delay_app_measurement_init": false,
    "optimize_initialization": true,
    "optimize_ad_loading": true,
    "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you."
  }
}

ios/Podfile

no thing here .I am suing android only

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"

    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath('com.google.gms:google-services:4.4.1')
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
apply plugin: 'com.google.gms.google-services'
/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
    // codegenDir = file("../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
}

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.mobile.number.locator.phone.caller.location.finder"
    defaultConfig {
        applicationId "com.mobile.number.locator.phone.caller.location.finder"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 21
        versionName "2.1"
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:flipper-integration")
    implementation platform('com.google.firebase:firebase-bom:32.7.3')
    implementation 'com.google.firebase:firebase-analytics'
    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")

android/settings.gradle

rootProject.name = 'GPS Tracker'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

AndroidManifest.xml

<manifest 
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
       android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:usesCleartextTraffic="true"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:theme="@style/AdTheme"
        tools:replace="android:theme"
      />
      <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAwH_rp-6rIrnF2zfl_VXOX7n1h_Dz1-iQ"
      />

      <meta-data
        tools:replace="android:value"
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-cxcxcxcxcxcxcxcxcxcxcxcx"
      />

      <service 
        android:name="app.notifee.core.ForegroundService" 
        android:foregroundServiceType="location" 
      />
    </application>
</manifest>
github-actions[bot] commented 2 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

AftabUfaq commented 2 months ago

i have managed to fix it