Cordoba - modify or delete MainActivity

I am developing a Cordoba application that should work in the "Kiosk" mode - the device will be blocked for this application and will not be able to exit.

To do this, I use a slightly modified version of cordova-plugin-kiosk , which provides additional activity ( KioskActivity), which is defined as a launcher (it has android.intent.category.HOME).

This works quite well. However, the application still has the original MainActivity cord, which causes some confusion, especially since this is what is launched by the icon in the original launcher and the command cordova run android. This also results in two entries in the Chrome remote inspector.

AndroidManifest.xml as follows:

    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:label="@string/activity_name" android:launchMode="singleInstance" android:name="jk.cordova.plugin.kiosk.KioskActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </activity>

.

:

  • MainActivity AndroidManifest.xml , , cordova run android KioskActivity.
  • MainActivity KioskActivity .

, , cordova.

+4
2

Manifest.xml, plugin plugin.xml.

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="overwrite">
<activity android:name="MainActivity" android:label="NewLabel" android:configChanges="orientation|keyboardHidden" />

MainActivity , .

+3

:

1. MainActivity

hook, MainActivity.java platforms/android/src/[packageName]/ MainActivity.

, <platform name="android"> config.xml before_build, :

<hook type="before_build" src="scripts/updateMainActivity.sh" />

scripts/updateMainActivity.sh:

#!/bin/bash
cp MainActivity.java platforms/android/src/[packageName]/

( nodeJS, - )

2. cordova-custom-config MainActivity

cordova-custom-config , , <platform name="android"> config.xml:

<preference name="android-manifest/application/activity[@android:name='MainActivity']" delete="true" />

. cordova-custom-config >= 3.0.0.

, , cordova-custom-config.

+3

Source: https://habr.com/ru/post/1648805/


All Articles