ionic 4: android permission not working after prod built - android

I am using #ionic-native/android-permissions.
My code in app.component.ts:
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.RECORD_AUDIO).then(
(result)=>{
if(!result.hasPermission)
{
this.androidPermissions.requestPermissions(
[this.androidPermissions.PERMISSION.RECORD_AUDIO,
this.androidPermissions.PERMISSION.GET_ACCOUNTS]
).then(()=>{
// this.rootPage = HomePage;
window.location.reload();
});
}
});
It is working when I do :
ionic cordova run android
or
ionic cordova build android
or
ionic cordova build android --release
But the app is not asking for permission if I add --prod. i.e. :
ionic cordova run android --prod
or
ionic cordova build android --prod --release
So the device mic is not working for the app.

I had this issue, and i solved it by adding permissions to config.xml
then, popup will show and ask client for permissions.
add permissions to config.xml
<platform name="android">
....
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:name="android.hardware.microphone" android:required="true" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</config-file>
....
</platform>

Related

Ionic Cordova InAppBrowser

I have an hybrid app built with:
Ionic 5.4.16
Cordova 10.0.0
AngularCLI 9.0.2
Android sdk 29
I open an URL using Cordova In App Browser https://ionicframework.com/docs/native/in-app-browser .
This URL is a chat page, and in this URL i need access to front and back cameras and microphone, but when I open it, the page doesn't have the access.
It seems it doesn't use the permissions declared in my config.xml, while the app it uses these permissions in its lifecycle.
In my "Android platform" section i declared:
<config-file mode="merge" parent="/*" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
private iab: InAppBrowser
....
const ref = this.iab.create(url, '_blank', 'location=no,zoom=no');
Is there any other permission I need to declare?
Do you have any suggest?

Cordova plugin add fails for ENOENT on AndroidManifest

I've developed a custom plugin for a cordova application and trying to test it out with the latest cordova Android platform version.
Whenever I run:
cordova plugin add ../my-plugin
cordova platform add android
or
cordova platform add android
cordova plugin add ../my-plugin
I get the following error:
Failed to install 'com.my.plugin': Error: ENOENT: no such file or directory, open '/path/to/project/my-application/platforms/android/AndroidManifest.xml'
This is the content of my plugin.xml file for what concerns the AndroidManifest.xml.
<config-file target="app/src/main/AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
I've already seen this answer which is pretty commonly shared throughout different resources and websites I visited but is not helping me since I'm already using app/src/main/AndroidManifest.xml after updating from android#6.4.0 to android#7.0.0.
My environment is:
macOS
cordova#8.1.2
android#7.1.1
Note: As of now I made it work by using android#6.4.0 but I'd like to understand how to make it work with newer platform versions.

Add android.permission.CAMERA with Cordova

I am using the latest version of Cordova (6.3.1) and I want the following permission to appear in the AndroidManifest.xml :
<uses-permission android:name="android.permission.CAMERA" />
Adding this line by hand does not work because the XML is regenerated each time I run the command cordova run android
I have added the cordova-plugin-camera to my project with
cordova plugin add cordova-plugin-camera
This plugin does NOT add the CAMERA permission in the AndroidManifest.xml
I don't know if this is normal
How can I add this permission to my project ?
Edit :
Usually, Cordova plugins are in charge of adding required permissions into the manifest. The camera plugin does not add this specific permission, I wonder :
if the plugin should add this permission (bug ? I have opened an issue on their Jira tracker)
if I can add this permission by hand myself, maybe in the Cordova's config.xml
I don't think the Camera plugin ever added this permission to AndroidManifest.xml. Looking through the Github repo, WRITE_EXTERNAL_STORAGE was added in June 2013 (CB-3654), but I don't see anything for the camera itself. Not sure why that would be, but you can either add the permission to AndroidManifest.xml yourself or add a config-file directive in your project's config.xml file, for example:
<config-file target="AndroidManifest.xml" parent="/*" mode="merge">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
Are you building native or hybrid app?
For native you can refer this website:
https://developer.android.com/reference/android/hardware/Camera.html

Cordova CLI overwriting Plugman plugin on Android?

I'm writing a Plugman-compatible Cordova plugin. Installing it via Plugman, I've confirmed it installs correctly and runs normally:
plugman --platform android --project /platforms/android --plugin my/plugin.path
But if I use:
cordova build/cordova run android
it doesn't work even with plugin installed. This is because Plugman only installs my plugin js file to the /platforms/android/assets/www folder and not the base /www folder, so when I build, the /www folder without the plugin gets copied to /platforms/android/assets/www.
Is there an option or something in plugin.xml I should be specifying to install the plugin to the project root www folder?
When using Cordova CLI, you shouldn't install plugins using plugman. Cordova CLI does use plugman under the covers, but what you want to use is cordova plugins add http://... or cordova plugins add /path/to/plugin.xml.
You didn't specify which version of Cordova you are using, but here's some examples of adding plugins that are core functionality: http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface
It should put the js files in platforms/android/assets/www/plugins/com.plugin-name/www and the java files in platforms/android/src/com/plugin-name/
You can specify this in the plugin.xml file like this (this is an example from a plugin that I upgraded to https://github.com/aharris88/phonegap-sms-plugin3.0 ()):
<js-module src="www/sms.js" name="Sms">
<clobbers target="window.sms" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Sms">
<param name="android-package" value="com.adamwadeharris.sms.Sms"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.SEND_SMS" />
</config-file>
<source-file src="src/android/Sms.java" target-dir="src/com/adamwadeharris/sms" />
</platform>

Phonegap Android InAppBrowser not working

I am working on an Android App with Phonegap Cordova-3.0.0 and when I call InAppBrowser I got MotionEvent mTouchMode = 4 error. And InAppBrowser function is not working. So how can I fix this? Do I need do some setting on AndroidManifest.xml or config.xml?
And I got this on my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And I got this on my config.xml
<plugins>
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
</plugins>
In Phonegap Cordova-3.0.0 version, for the app to communicate closely with various device-level features, we need to add plugins that provide access to core Cordova APIs.
The cordova plugin add command requires you to specify the repository for the plugin code.
For example, In-app browser:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
we need run this in command line. Don't need worries about AndroidManifest.xml or config.xml files. After you run $ cordova build, it will auto write for you.
You could get more idea about it in doc.phonegap
Add following code in config.xml this works fine for mi.
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
<access origin="*" browserOnly="true"/>
You have to mention the below code line in config.xml
<plugin name="InAppBrowser" value="CDVInAppBrowser" />
try to add this to your manifest, it helps me with a f*king plugin to work
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
try also not use 'plugin' tag in config.xml, but:
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser"/>
</feature>
it will help for future updates of phonegap
To open a link in browser inside the app without opening external browser
HTML
<input type="button" id="button1" value = "click here"
onclick="window.open('https://example.com','_blank','location=yes','closebuttoncaption = Return');">
Now go into your project folder and open Terminal or Command Prompt (Windows) and type the following command:
cordova plugin add cordova-plugin-inappbrowser --save
It will configure the required files and also add the plugin into your config.xml file.
Open your HTML page where you're trying to open the link, and put this JavaScript.
<script src="cordova.js"></script>
<script type = "text/javascript" charset = "utf-8">
function onLoad(){
document.addEventlistner("deviceready", OnDeviceReady, false);
}
function onDeviceReady(){
}
</script>

Categories

Resources