# FAQ
# Support outside of class hours
- If you have questions/problems about your project, please use Cordova's Teams channel.
- Help each other out!
- If the problem is solved, please add [SOLVED] or [OPGELOST] to the original question.
# Compiler errors
- It happens regularly that the Android app becomes corrupt and therefore generates compiler errors.
(Usually after removing a plug-in). - Make a habit of regularly deleting the platforms/android and platforms/browser folders.
- The next time you compile, these folders will automatically be recreated and no corrupted code will be left behind.
# Debugging on Android
- Always use
chrome://inspect
to find bugs directly on your device.
See: Debugging on a real Android device
# PHP backend
- PHP files do NOT belong in the app (especially not in the www folder).
- PHP files work ONLY on a web server that supports PHP (e.g.: sinners).
# Get JSON data
- In the app you use
$.getJSON()
to fetch the data from the server and process it.
See examples: PHP backend
# Error 500 with phonegap server
$.getJSON('https://pverhaert.sinners.be/cordova/master_1.php', function (data){
console.log('data', data);
})
1
2
3
2
3
- This code works on your smartphone, but NOT with
phonegap serve
.
- To test locally in the browser you should (by exception) use
cordova serve
and click through tobrowser
.
# Add data to database
- For the task, it is sufficient to fetch JSON data.
- Adding data to the database is not a requirement, but it is a nice addition.
- Adding data is not discussed in this course. Some tips to get you started:
- These PHP pages are also on the web server.
- Look for examples yourself: php mysql insert data with pdo.
- Do not use a classic form with a submit button in your app (because then you leave the app) but post the data with jQuery to the backend!
Use the jQuery functions
$.POST()
or$.AJAX()
for this.
Look for examples yourself: jquery post data to mysql backend.
# Android security
- Android version 10 (API 29) and higher is quite strict in its security policy.
- In order to obtain read and write rights on the system, you will have to add this explicitly to the configuration.
- This is important to get certain plug-ins (file, calendar, audio, camera, ...) working.
- If you are using one of these plug-ins, add the following code (within
<platform name="android">
!) toconfig.xml
:
(It's best to delete the platforms/android folder after each change inconfig.xml
).
<platform name="android">
<!-- https://developer.android.com/reference/android/Manifest.permission.html -->
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
</config-file>
<!-- https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage -->
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:requestLegacyExternalStorage="true" />
</edit-config>
<allow-intent href="market:*" />
...
</platform>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Example
- Download and unzip sample_media.zip.
- Install the node modules
$ npm install
. - Examine the code.
- www/js/image.js line 5: refer
path
to an existing jpg file. - www/js/audio.js line 6: refer
path
to an existing mp3 file.
- www/js/image.js line 5: refer
- Test the app on your smartphone:
$ cordova run android
. - In this example, the following plugins are used: