Skip to content

Commit 7c39f0b

Browse files
1 parent a82ad7c commit 7c39f0b

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

AndroidNativeWebViewExample.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ FORMS += mainwindow.ui
3030
CONFIG += mobility
3131
MOBILITY =
3232

33+
OTHER_FILES += \
34+
android/AndroidManifest.xml
35+

android/AndroidManifest.xml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
<?xml version='1.0' encoding='utf-8'?>
1+
<?xml version="1.0"?>
22
<manifest package="org.qtproject.example.AndroidNativeWebViewExample" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
33
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="@string/app_name">
4-
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
5-
android:name="org.qtproject.qt5.android.bindings.QtActivity"
6-
android:label="@string/app_name"
7-
android:screenOrientation="unspecified"
8-
android:launchMode="singleTop">
4+
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="@string/app_name" android:screenOrientation="unspecified" android:launchMode="singleTop">
95
<intent-filter>
106
<action android:name="android.intent.action.MAIN"/>
117
<category android:name="android.intent.category.LAUNCHER"/>
@@ -38,17 +34,17 @@
3834
<!-- Splash screen -->
3935
</activity>
4036
</application>
41-
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
37+
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"/>
4238
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
4339

4440
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
4541
Remove the comment if you do not require these default permissions. -->
46-
<uses-permission android:name="android.permission.INTERNET" />
47-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
42+
<uses-permission android:name="android.permission.INTERNET"/>
43+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4844

4945

5046
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
5147
Remove the comment if you do not require these default features. -->
52-
48+
5349

5450
</manifest>

android/src/org/qtproject/qt5/android/bindings/QtActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public class QtActivity extends Activity implements NativeCalls
182182
// this repository is used to push Qt snapshots.
183183
private String[] m_qtLibs = null; // required qt libs
184184

185-
//-------------WEBVIEW----------------
185+
//-------------WEBVIEW----------------
186186
protected ArrayList<WebView> webViewsList = new ArrayList<WebView>();
187187

188188
//-----------------------------------------------------------------------------
@@ -215,7 +215,7 @@ public void handleMessage(Message msg) {
215215
WebView webView = new WebView(QtActivity.this.getApplicationContext());
216216
webView.setTag(msg.what);
217217
webView.getSettings().setJavaScriptEnabled(true);
218-
webView.setWebViewClient(new WebViewClient());
218+
webView.setWebChromeClient(new WebChromeClient());
219219
webView.setBackgroundColor(Color.BLACK);
220220
webViewsList.add(webView);
221221
}

mainwindow.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
#include "mainwindow.h"
22
#include "ui_mainwindow.h"
33

4+
#include <QtWidgets/QLayout>
5+
46
MainWindow::MainWindow( QWidget *parent )
57
: QMainWindow( parent )
68
, ui( new Ui::MainWindow )
9+
, m_webVeiw( NULL )
710
{
811
ui->setupUi(this);
9-
10-
m_webVeiw = new QtCustomAndroidWebView( this );
11-
m_webVeiw->move( 10, 45 );
12-
m_webVeiw->resize( 300, 200 );
1312
}
1413

1514
MainWindow::~MainWindow()
1615
{
1716
delete ui;
18-
delete m_webVeiw;
17+
18+
if( m_webVeiw )
19+
delete m_webVeiw;
1920
}
2021

2122
void MainWindow::on_pushButton_clicked()
2223
{
24+
if( m_webVeiw )
25+
delete m_webVeiw;
26+
27+
m_webVeiw = new QtCustomAndroidWebView( this );
28+
m_webVeiw->move( 10, 45 );
29+
m_webVeiw->resize( 700, 600 );
30+
2331
m_webVeiw->loadURL( ui->lineEdit->text() );
2432
}

0 commit comments

Comments
 (0)