I'm using cordova-plugin-mfilechose in my Ionic 4 application. It works fine till Android version 9. But in Android 10 whenever we trigger the plugin it just opens a window saying Internal storage but no file is listed, though there are many files inside the phone. I have used the same code as per the official documentation, added below. Thanks in advance.
window.plugins.mfilechooser.open(['.doc', '.xls', '.ppt'], function (uri) {
alert(uri);
}, function (error) {
alert(error);
});
The plugin looks like it is using standard Java File operations and paths to choose files, in Android 10 and above you cannot use file paths or Java File operations any more on anything but your App's private directory.
See https://developer.android.com/training/data-storage/files/external-scoped
Also not sure why you would use such a plugin as Android provides the functions natively with Storage Access FrameWork(SAF) or MediaStore
See https://developer.android.com/guide/topics/providers/document-provider#client
on how.
Everything can now only work with Java FileDescriptor
I found a workaround to my problem. Though it is not a solution in long run. In my Ionic 4 project project/config.xml android-targetSdkVersion was 29. I changed it to 28. Which works on Android 10 and also on all the lower versions. Below is the code.
<preference name="android-targetSdkVersion" value="28" />
I think all ionic plugins like cordova-plugin-camera and cordova-plugin-telerik-imagepicker needs to update to fully compatible with android 10 for scoped storage.
Related
I have managed to connect a device ( I see logs and see the tree of React Native elements), but now I have an issue with connecting the app - "NO APPLICATION SELECTED" is what I see. Any ideas to fix it?
Ran into the same problem on both iOS and Android with Flipper 0.135.0. Managed to make both work by following the steps below.
iOS
This answer solved the issue for me.
tl;dr
brew update && brew upgrade idb-companion
Also make sure you are installing the correct Cocoapod of Flipper by specifying the exact version in your Podfile with (for version 0.135.0)
use_flipper!({ 'Flipper'=> '0.135.0' })
Android
Ensure that ReactNativeFlipper.java is in the correct folder, as in this example project.
With for example the applicationId com.domain.appName, the correct path is
android/app/src/debug/java/com/domain/appName/ReactNativeFlipper.java
In my project this Java file was in the incorrect folder, which resulted in the Logcat error
java.lang.ClassNotFoundException: com.domain.appName.ReactNativeFlipper
Ensure that you are running the latest version of Flipper (0.120.0 as of this message) and then:
For Android:
Bump the FLIPPER_VERSION variable in android/gradle.properties, for example: FLIPPER_VERSION=0.120.0.
Run ./gradlew clean in the android directory.
For iOS:
Call use_flipper with a specific version in ios/Podfile, for example: use_flipper!({ 'Flipper' => '0.120.0' }).
Run pod install in the ios directory.
Reference: https://fbflipper.com/docs/getting-started/react-native/#using-the-latest-flipper-sdk
Go to settings and check if the path for your Sdk is correct
In my case issue was with the Emulator OS and API.
I used following combination and it worked:
Device: Pixel 4a
OS: Android 12
API: (Release Name: S, API level: 31, ABI: arm64-v8a, Target: Android 12
I also faced this issue, I was not seeing android simulator and the app to select, but it was working fine for iOS without any config.
The problem with my setup was that in the Flipper settings, the android SDK's path was not correct, after updating the path and restarting Flipper, it automatically detected the simulator and the app.
Hope this helps.
I was able to solve that on Android, open ReactNativeFlipper.java file
In the first line package com.yourappname; change it to exactly your package name inside AndroidManifest.xml
In the MainApplication.java there is a line like
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
inside onCreate() function. In my project this line was commented. I removed the comment and run react-native run-android and flipper get connected to the app
I am learning to use cordova and i have been just doing a normal install of android platform in my cordova application, everything worked fine except for some errors i don't intent to fix just yet (which are external resource files loaded from javascript). I just installed phonegap-plugin-push for working on a push notification support, i believe i have to first register the device on which the notification should be recieved so i ran the app without any other configuration rather than downloading the libraries and putting the google-services.json file at the root application folder.
I try to find the commands for pushing but i am unabled to do so and i think it might be because of an error thrown in the console
Failed to load resource: net::ERR_FILE_NOT_FOUND /cordova_plugins.js
so i have been searching on google and i have found that i don't need to add anything but cordova.js as i have already done upon cordova application installation in order to work with cordova features.
I don't know if i have to add something else or if i am missing some code in order to make this plugin work, probably this plugin is not compatible with cordova but phonegap is built over cordova so i don't know.
in case it is necessary, this are the versions i am using:
Cordova-CLI: 7.1.0
Google Play Services: 46
Android support repository: 47
Android SDK: 26
I failed to say that the application running in cordova is done with angular and angular-ui-router.
After long hours of testing i've found out that the problem is caused by angular-ui-router, because i was using angular-ui-router i have set a <base href> tag in the head tag which is what is making cordova to fail, this is now actually how cordova is intended to work, it is because of how the files are placed. On android the files are placed in android_asset/www/, i don't know how the files are placed in other platforms, but when <base href> tag is set with a new value then the calls are now trying to be done in a directory where the files are not placed.
The solution in angular is to not set a <base href> tag and disable html5Mode in the config
app.config(["$stateProvider", "$locationProvider", "$urlRouterProvider",
function($stateProvider, $locationProvider, $urlRouterProvider){
// Set the default url state
// NOTE: Do not set <base href> tag, this breaks cordova calls
$urlRouterProvider.otherwise("/");
// Disable html5 native router mode
$locationProvider.html5Mode(false);
......
}
]);
I've realized this because in chrome device remote inspector i was getting error calls to wrong directories, by looking at the url where the application is running i saw that the calls were not in the proper directory
I am new to all of this, so I am probably missing something pretty obvious, but I am trying to change the userAgent string in an application I am building with Cordova. Based upon the documentation at the Cordova website, it would appear that I should only need to add the following to my config.xml file:
preference name="OverrideUserAgent" value="My string value here"
So I included this line in my config.xml and then added this code to my javascript in my cordova app:
var ua = navigator.userAgent;
alert(ua);
I then build the project and install it on my android phone. However, when I run the app I get the same userAgent reported back by my alert regardless of whether I included preference name="OverrideUserAgent" value="My string value here" in the config.xml or not. I am using version 5 of Cordova (5.3.1 I believe) and this config.xml fix was listed in the documentation for version 5.1.1 on the Cordova website.
I have also seen another possible fix on stackoverflow in the following post:
Change PhoneGap / Cordova User-Agent for AJAX
Specifically I am looking at the response that recommends:
put this in your onCreate method: (after super.init();)
super.appView.getSettings().setUserAgentString("Your own agent string");
I am sorry to ask such a basic question, but how to I carry this out? Is it possible to do this while still using the Cordova CLI or do I need to import the project into Android studio first? Where exactly do I find the onCreate method that I need to modify.
Thank you for any help you may be able to offer.
I used to be able to run this without problem to get to the databases folder of my Android App:
window.resolveLocalFileSystemURI('file:///data/data/{package name}/databases',
function (entry) {
alert(entry.fullPath);
}, rlfsOnErrors);
However, the statement returns error when I am using file-transfer plugin v0.4.2. When I switched back to file-transfer plugin v0.3.3, there is no problem. When I am using v0.4.2, I can only gain access to file:///data/media/xxxx directory and not file:///data/data/xxxx.
Anyone has any idea how I can workaround this ? Currently, I am sticking to v0.3.3, but I am sure there is some way to workaround this ?
Thanks.
We are using Phonegap 3.1.0-0.15.0 and the application chocked when trying to access location information.
Works fine in iOS however the App chock on Android
We are using:
navigator.geolocation.getCurrentPosition(app.location.onSuccess, app.location.onError);
and we also tried:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(app.location.onSuccess, app.location.onError);
The logcat mentioned the following:
Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1511
Uncaught module cordova/plugin/geolocation not found at file:///android_asset/www/phonegap.js:56
The plugin was added using:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Are we doing something wrong ?
Thank you in advance
/Edwardo.
Just to answer my own questions. I removed all the plugins manually and then add them (including the problematic geolocation plugin) using the following command:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
That solved my issue.
Edward.