Cordova Android 10 - Trouble to assign the root path - android

As breautek wonderfully explain here , with Android 10 Platform (the mximum platform available at the moment on Cordova and the minimum platform required to publish on playstore) "XHR not CORS request" and "file://" not working if I don't set on my config.xml
<preference name="hostname" value="localhost" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
I'm pretty sure that this solution is useful... but temporary. I'm sure the PlayStore will impose a new restriction shortly and this solution will be in vain.
So I decided to not use them and carry on... I have solved my problem about XHR CORS request but I have no solution about how to set the root path... for example to assign it an image path
At the moment I get it as:
var urlRootMobile=cordova.file.applicationDirectory+'www/';
var img1 = urlRootMobile."/img/1.png";
var img2 = urlRootMobile."/img/2.png";
var img3 = urlRootMobile."/img/3.png";
Obviously don't work on my app because the path is : " file:///android_asset/www/img/1.png"
I tried to use "https://localhost/www"
I tried to use "https://localhost"
I tried to use "/"
But nothing...
I there some other command or trick ???

You need to use cordova-plugin-file to read these files.
If you just need to read images from www then the path is simply '/img/1.png'

Related

SVG images is not showing in Nativescript

I am trying to use svg images for android in native-script. Here is my code
<StackLayout xmlns:svg="#teammaestro/nativescript-svg">
<svg:SVGImage src="~/images/app_settings.svg" height="250" width="250" /> </StackLayout>
I am using this native-script plugin . However I am not getting any error. But the images are not showing in android emulator.
Finally, I solved this issue on my side.
Firstly, I use this package from SergeyMell: nativescript-svg. Those two packages are very similar since they both forked this same package peoplewareDo/-nativescript-svg.
I moved all the SVG files from App_Ressources to an assets folder in the app folder.
Then I added this line in webpack.config.js:
{ from: '**/*.svg', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }
Finally,
<SVGImage src="~/assets/file.svg"></SVGImage>
This answer is not a big thing but now it's working fine for my project. Some of the steps were already done and the big changes are the folders move. Perhaps Android ignores for some conditions some files from App_Resources.
I hope it'll help as it worked for me.

NLog with Xamarin cross-plattform application doesn't log anything

I set up NLog like this in the Android part of my Xamarin-project.
My NLog.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="true"
throwConfigExceptions="true"
internalLogLevel ="Trace"
internalLogFile ="C:\Users\MyUser\intLogFile.txt"
internalLogToConsole="true"
internalLogIncludeTimestamp ="true">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="/storage/emulated/0/Download/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
I put the NLog.config in the assets-folder in my android-project.
I added this NuGet to my android-project.
I changed the build action to embedded resource.
I made sure to have writing permissions on the external storage of the device.
I am loading the NLog configuration programmatically like this and nlogConfigFile != null is true so I assume the NLog.config is found.
As you can see I enabled throwing exceptions from NLog but there are no exceptions thrown...
...But the internal logging is not working aswell
I followed every step of the troubleshooting by NLog
Has somebody an idea why NLog is still not logging anything?
--------------------- UPDATE ----------------------------
NLog is now logging with basic setup of a LogService-class:
public void Initialize(Assembly assembly, string assemblyName)
{
var location = $"{assemblyName}.NLog.config";
var stream = assembly.GetManifestResourceStream(location);
NLog.LogManager.Configuration = new XmlLoggingConfiguration(XmlReader.Create(stream), null);
NLog.Common.InternalLogger.LogFile = "C:\\Users\\MyUser\\Documents\\internalLog.log";
NLog.Common.InternalLogger.LogWriter = new StringWriter();
NLog.Common.InternalLogger.LogLevel = LogLevel.Debug;
}
But the internal log is still not showing up. As you can see I tried configuring the InternalLogger in code and also in the NLog.config. I tried putting the NLog.config in the assets-folder and in the main android-project and I set build action to respectively embedded ressource or android asset.
--------------------- 2nd UPDATE --------------------------
The InternalLogger is now working on my Android-device.
In this tutorial the internal file is logged to c://temp/... which I assume is a path on Windows. But I am still not able to achieve this during debugging. Is this even possible?
Following some additional troubleshooting tips that helped me solving my issue:
If you are using a real Andriod-device and not an emulator unplug the
debugging connection and reconnect it. The Windows-File-Explorer
sometimes is not updating the files in the folders of the device if
it is not reconnected.
Basic initializing in the code should be enough:
public void Initialize(Assembly assembly, string assemblyName)
{
var location = $"{assemblyName}.NLog.config";
var stream = assembly.GetManifestResourceStream(location);
NLog.LogManager.Configuration = new XmlLoggingConfiguration(XmlReader.Create(stream), null);
}
You should be fine by putting NLog.config as an embedded resource in the main folder of the android project. If not put it as an android asset in the assets-folder.
If it is still not logging try to set the configuration up programmatically
Also make sure your minlevel in the .config is lower than the loglevel you are using.

White notification icon for Android with Phonegap Build and PushPlugin

I'm messing around with Phonegap using Adobe's Build service and I was wondering if (and if so, how) I could make my notifications display a white icon (as Google describes here). I'm using the PushPlugin but I couldn't find any documentation on this. At the moment my app just displays the launcher icon next to the notification content.
So does anyone know if there's some way to enable an alternate notification icon with the PushPlugin, am I stuck with the launcher icon or is there another plugin with this feature?
Thanks!
I have never used Phonegap build - I do the build process manually on my machine. Anyway, I think you should find the GCMIntentService.java file under src/com/plugin/gcm. In that file, search for the following line of code:
.setSmallIcon(context.getApplicationInfo().icon)
This may be replaced by the icon you want. If you place an icon named "notification.png" in the /res/drawable folder, you could change the code line to:
.setSmallIcon(your.package.name.R.drawable.notification);
The new "phonegap-plugin-push" plugin has excellent support for notification icons for the new Lollipop.
Build an icon that has color on a transparent icon first. Per google's guidelines all notifications will display white on the notification tray.
So build the icon and then specify it as follows. "icon" specifies the image.
Place copies of "myicon" with appropriate resolutions in /platforms/android/res/drawable-RES/ folders as follows:
mdpi - 22x22 area in 24x24
hdpi - 33x33 area in 36x36
xhdpi - 44x44 area in 48x48
xxhdpi - 66x66 area in 72x72
xxxhdpi - 88x88 area in 96x96
Now in your JS, specify your icon. The "iconColor" is optional and will specify the background when you swipe down.
var push = PushNotification.init({
"android": {
"senderID": "<<SENDER_ID>>",
"icon": "myicon",
"iconColor": "#123456"
},
In your push payload you can now-override the icon that is specified on swipe down by adding an "image" parameter. Image can either be a resource, it can reference "www/image/image.png", or can be a full URL.
The "plugin docs" are excellent, I recommend reading them. Hope this is useful to somebody.
Set this on your PhoneGap or Cordova config.xml
<preference name="android-targetSdkVersion" value="20"/>
This is for the new plugin - phonegap-plugin-push
Might work for the old PushPlugin as well.
Android has set guidelines for the notification icon for Lollipop and above. The icon needs to be purely white and transparent.
What I did:
Generated different sizes for my logo image (lets name it "notif.png") which had transparent back, using this tool. Remember to have a transparent back image, if you dont have a transparent image, android will just show white icon only. Lets assume the generated icon's name is "ic_notif".
Copy the respective size images to res/drawables folder.
In the push JS code, give the value "ic_notif" to "icon" property. And "grey" to "iconColor" property like this: PushNotification.init({"android":{"senderId":"XX","icon":"ic_notif","iconColor":"grey"}});
Test your notification using this tool.
Android API 21+ uses only white color for small icon.
Changing target SDK Version makes your compiler to use elder SDK so U`ll be cut in new SDK features.
So the best way is to have two icons: small and big one (when bar is dragged down)
For a time, you can set your android-targetSdkVersion to API 20.
This version don't use the new features, that broke the old resources.
For me the solution works when combining two answers from here:
First I set the target sdk version
<preference name="android-targetSdkVersion" value="20"/>
And then I edited the plugin code as suggested here, in GCMIntentService class I modified the setNotificationSmallIcon method to be:
private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
mBuilder.setSmallIcon(getApplicationContext().getApplicationInfo().icon);
}
or if you want to set a custom icon then use
private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
mBuilder.setSmallIcon(<your.package.name>.R.drawable.<notification-drawable-name>);
}
I also faced too many problem in this but after searching all over the internet i found different solutions for this issue.Let me sum up all the solutions and explain:
Note:This solution is for Phonegap cordova users
Example
<preference name="android-targetSdkVersion" value="20"/>
You need to set your android-targetSdkVersion value to less than 21.
So after setting this value Notification icon image will appear till Android 6(Marshmallow), It won't work in Android 7(Nougat).
This solution worked for me.
Change the statusbarStyle in your config file.
Example
<preference name="StatusBarStyle" value="lightcontent" />
But this solution will work only when your app is opened.
So, I guess this solution is not the best solution but it worked for many users.
Make your icon transparent.
This solution worked for many people.
Actually the thing is, In the development of Native aplication we need to provide them three images:
(a)App icon
(b)Notification icon
(c)Status bar icon image, but in case of Hybrid mobile application development there is no option to do so.
So make your icon transparent and this solution will solve your problem.
And I am sure one of the above solution will work for your issue.
With the recent update to PhoneGap Builder to version 2 (and CLI v7.0.1), I'm now able to get white notification icons to appear correctly with cordova-plugin-push.
I first created my .png icons (with transparency) in GIMP. I then put them in my project at /www/res/notify_icon/android/
Here are the relevant excerpts of my config.xml file:
<widget id="com.myapp.app" version="1.2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<preference name="phonegap-version" value="cli-7.0.1" />
<preference name="pgb-builder-version" value="2" />
...
<plugin name="phonegap-plugin-push" source="npm" spec="~2.0.0-rc5">
<param name="SENDER_ID" value="1xxxxxxxxxx0" />
</plugin>
...
<platform name="android">
<resource-file src="google-services.json" target="google-services.json" />
<resource-file src="www/res/notify_icon/android/notify_icon-36-ldpi.png" target="res/drawable-ldpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-48-mdpi.png" target="res/drawable-mdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-72-hdpi.png" target="res/drawable-hdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-96-xhdpi.png" target="res/drawable-xhdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-144-xxhdpi.png" target="res/drawable-xxhdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-192-xxxhdpi.png" target="res/drawable-xxxhdpi/notify_icon.png" />
...
</platform>
</widget>
Here is the where I initialize push:
document.addEventListener("deviceready", function() {
var push_options = {
android: {
senderID: "1xxxxxxxxxxx0",
sound: true,
vibrate: true,
icon: 'notify_icon',
iconColor: '#66CC00'
},
browser: {},
ios: {
senderID: "1xxxxxxxxxxx0",
alert: true,
badge: true,
sound: true
},
windows: {}
};
var push = PushNotification.init(push_options);
You just need to the change the
android-targetSdkVersion
in your config.xml file.
<preference name="android-targetSdkVersion" value="20" />
20 android sdk version support the logo in Android. So you have to change the android sdk version in your code.
If you're using Build's PushPlugin; local modifications to .setSmallIcon()#100 will be lost.
Unless you build locally or use an alternative GCM plugin, you're restricted to modifying:
title extras.getString("title")
message extras.getString("message")
msgcnt extras.getString("msgcnt")

locales/en-US/translation.json loads in Eclipse but fail in iphone

I am currently developing a cross platform mobile app using phonegap 2.5. When app starts it loads a json file for setting the app's language. It works perfectly in android but in ios it gets me that error: failed loading: locales/el-GR/translation.json. I tried to change the relative path for locales folder or move the current folder to other scope but neither seems to work.
WWW subfolder path
_www/
__index.html
__js/
___some js files like as main.js, cordova.js,jqmobi.min.js, i18next-1.7.1.min.js e.t.c.
__locales/
___en-US/
____translation.json
And the function i call in main.js:
i18n.init(
{
lng: AppSettings.Language.get(),
fallbackLng: 'en-US',
/* Where __lng__/__ns__.json = en-US/translation.json */
resGetPath : '/locales/__lng__/__ns__.json',
resPostPath: '/locales/__lng__/__ns__.json',
debug: true
},
function(){
}
);
In main.js i give the relative url path for loading translation.json (locales/en-US/translation.json). This works fine in android but in ios it doesn't seem to load it.
So, if you can, i could need some help.
Does iphone understand differently the relative paths of a phonegap mobile app?
What path should i give so that the app loads the translation.json?
If you need more info tell me.
Ty in advance.

Setup SoftKeyBoard Cordova Plugin

I would like to hide the softkeyboard onBlur.
Therefore, I found the softkeyboard plugin, and I suppose I installed it properly, following numerous threads posts.
However, this is the first time I use a plugin for cordova, and I get this error, so I guess something is missing:
Cannot read property 'SoftKeyBoard' of undefined
This refers to the js call in the html file:
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
Does not window.cordova.plugins exist?
In order to set up the plugin, I did the following:
copy SoftKeyBoard.java to src/org.apache.cordova.plugins.SoftKeyBoard. I also rewrote the first line package accordingly.
copy the js file, and link it to the html file
add this line to res/xml/config.xml:
<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
In this XML, it's located in <cordova><plugins>
Is there anything else I should have done?

Categories

Resources