18910140161

html-Android WebView-以编程方式强制第三方网页的输入域使用数字键盘?-堆栈溢出

顺晟科技

2022-10-19 12:53:56

91

快速上下文:我们有一个非常独特的情况,我们正在切换到一个新的人力资源平台,该平台只允许我们的工厂员工通过时间锁网页进行计时。我们已经有几个三星Galaxy Tab A设备放置在我们的大楼里,作为当前人力资源系统的时间锁亭。由于我们只能通过Knox一次将这些平板电脑锁定在一个应用程序上,例如,Chrome web浏览器会让员工意外地离开新平台的timeclock网页,并给试图打卡或下班的其他人带来问题。

所以,我们已经安装了一个Android应用程序,实现了一个基本的WebView硬编码到新的人力资源公司提供给我们的timeclock URL。但是,这里最大的问题是没有页面键盘,徽章ID字段是text类型,它调用Android qwerty键盘来获取徽章ID PIN,该PIN只能是所有数字...一家第三方公司为人力资源公司建立了这个网页,所以我会很惊讶,如果我们能在他们的一端改变它。


只是为了展示我们的一些基本样板来实现上面的...

AndroidManifest.xml

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>

MainActivity.java

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>

activity_main.xml

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>

我们已经做了大量详尽的搜索,并试图跳出框框思考,但作为一个小制造商只有2个系统管理员,我们绝不是经验丰富的Java开发人员!我们尝试研究并尝试了以下想法:

  • 每当调用qwerty键盘然后调用数字或电话键盘时的事件侦听器
  • 从WebView获取HTML内容,查找标记并尝试以编程方式将其更改为ONT或以获得正确的键盘来显示
  • 强制我们的应用程序调用数字键盘,并严格将其保持在网页上方
  • 我们看到有人提到edittext类用于配置输入和键盘类型,但问题当然是我们不是在应用程序中处理有问题的输入,而是通过WebView在其他人的网页上

这当然是一个非常小的边缘问题,我们被迫为自己想出一个复杂的解决方案...我们可以观察在任何Android设备上哪种输入类型产生哪种键盘。我们所要做的就是在我们的应用程序中的WebView站点上获得一个数字软键盘,这样员工就可以轻松地走上去,输入他们的徽章并完成他们的时钟操作。

我希望这是简明但彻底的...这里必须有一个创造性的解决方案,有人对我们如何实现这一点有任何建议或建议吗?即使只是给我们指明正确的方向,也会非常感谢...谢谢!!


顺晟科技:

在WebViewClient中,重写并执行以下操作:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>

这个想法是修改加载的页面,使其按照您需要的方式运行。

更新:完整代码

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>

不要忘记将代码中的URL更改为您自己的URL。

在活动的oncreate中:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Paytime Time Clock"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaytimeWebpage"
        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>
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航