Xamarin Forms creating a Folder in Local - xamarin

Creating folder by following code
var documents=Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
var directoryname = Path.Combine(documents, "XX");
Directory.CreateDirectory(directoryname);
but the folder does not exists in the specific path..May i know whats the reason.
regards..

if you need the main picture folder on the android then your code should look like this
string AndroidDcimFolder = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;

From Xamarin Official Site:
Not all directories in this enumeration will be available on all
platforms for all users. When running on the Windows operating system,
the operating system determines the paths to these directories.
Enumeration means Environment.SpecialFolder.
You need to implement a DependencyService and need to call System.Environment.GetFolderPath from within the platform-specific implementation.
Check this sample.
As per my knowledge, it (your code) will not work in Xamarin.Form PCL project.
You can do another thing is, In your Android and iOS Project you can put this code to get the platform specific path:
using Xamarin Forms;
//Get current Path.
Config.PathApp = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);

Related

Image inside folder with two-letter name ('bg') disappears when packaged as UWP app

I've got a really weird problem building a Windows 10 UWP app. When I test on my device in both debug and release modes, an image I set as Background appears perfectly fine. It resizes, etc.
However, when I package the app in preparation for store deployment and install the package to test, images are showing as white.
Here's the code in question:
mainGrid.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(#"ms-appx:///Assets/bg/" + Config.bgImage + ".jpg")), Stretch = Stretch.UniformToFill };
What confuses me the most is why it works in debug/release, but only fails when its released as a package.
The image is set as "Content" and "Copy Always".
Any ideas?
Thanks in advance!
Per comment, this is due to a folder being named bg and the project being set to create a "bundle" (ie, a main package and then a separate package for each language).
For better or worse, the packaging system assumes that any directory with a 2-letter name is a language code (like "en" or "de") and therefore assumes the assets are specific to that language. Those assets are placed in a separate package that are only installed if applicable for the current user.
If you have a large number of assets, and you're localizing them, using a bundle is still a good approach to minimize the app size and download time, in which case you would need to change the directory name to something a bit longer (technically you can control the packaging yourself but it's a lot of work... renaming is probably easier).
But if you don't localize / aren't worried about bloating the app too much, then creating a single package is fine.

Bundling directory of images in app

Wondered if someone could help please:)
Titanium 5.5.0 sdk
Appcelerator 4.7.1
I need to be able to bundle a bunch of images in my iOS app and then get a directoryListing so the user can pick an image out of it.
In an older app I did this by placing my image directory in:
assets/iphone/[folder here]
and used this code:
var path = Ti.Filesystem.resourcesDirectory + '[nameoffolderhere]';
var imgDirectory = Ti.Filesystem.getFile(path);
var imagesArray = imgDirectory.getDirectoryListing();
and it worked. For some reason when I'm building a NEW app this no longer works. Indeed even the older app running under the latest SDK still finds the images. BUT using the exact same folder structure in a new app and it can't find the directory.
Could someone throw a light on the best place to place these directories so I can receive a directory listing and get to the images please?
thanks very much in advance
ade
Do you have <use-app-thinning>true</use-app-thinning> enabled in your tiapp.xml? If so, images are bundles with the asset-catalog are not accessible as files.
You should probably try to place them in app/platform/ios then, to copy them as resources instead of assets or disable app-thinning if you don't explicitly need it.

Visual Studio 2015 won't display local web page (ms-appx ?)

I'm converting an app to run as a Universal Windows App using VS 2015 Community. If I create a webview using the toolbox, I can enter "http://www.google.com" into the Source property, and it will display google.
If I use the drop down on the Source property to reference (say) Help.htm as a local resource, the source windows displays "ms-appx:///Help.htm". Similarly if it is in Assets, it displays "ms-appx:///Assets/Help.htm". When I run the program, where the webview should appear it displays "You will need a new app to display this ms-appx" and invites me to search the store.
I can display a local image in an image box with very similar syntax, with Source being "ms-appx:///Assets/StoreLogo.png". The Source property in this case is in the "common" group, not "miscellaneous", but apart from that appears virtually identical.
Nor can I specify a local path in a URI (although again I can display Google). Behaviour is identical on two different machines. I have spent several days trying to work out what is going on; any suggestions?
Can you please try to load file through code and share results?
public MainPage()
{
this.InitializeComponent();
mywebview.Source = newUri("ms-appx-web:///Help.htm");
}
also try this
mywebview.Navigate(newUri("ms-appx-web:///Help.htm"));
If both above options doesn't work. Please change to below and share results
mywebview.NavigateToString("<Html><Body><h1>Eureka!!!!<h1><Body></Html>");
If you are using it from a Library project, you must also add the name of the library, like that:
ms-appx-web:///[Library]/Help.htm

How to add Windows Phone project with resx localization to Xamarin PCL solution?

I have a working PCL project for iOS and I'm trying to create the Windows Phone 8.1 version.
I'm following this tutorial: https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/
And checking the app at: https://github.com/xamarin/xamarin-forms-samples/tree/master/UsingResxLocalization
But it is too deprecated. Even the git project is different from the tutorial, and none of them works.
The ILocalize interface for Windows should look like:
[assembly: Dependency(typeof(UsingResxLocalization.WinPhone.Localize))]
namespace UsingResxLocalization.WinPhone
{
public class Localize : UsingResxLocalization.ILocalize
{
public System.Globalization.CultureInfo GetCurrentCultureInfo ()
{
return System.Threading.Thread.CurrentThread.CurrentUICulture;
}
}
}
But System.Threading.Thread.CurrentThread.CurrentUICulture simply doesn't exist. I found out that I can use Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString() instead.
It works for the localized language resources but the default Resource is not working either for the default language "en" or any other non localized language like "ru". I get another error:
In the TranslateExtention class ProvideValue() method I get:
Key 'Start' was not found in resources 'AppNameSpace.AppResources' for
culture 'en'
Being "Start" the first key it tries to get from the resource. It happens for all the other keys on the project.
AppNameSpace.AppResources would be the right file, and "en" is the region I set, so it should work. But it's not.
I'm also getting the following warning when compiling:
The assembly "MyApp.dll"
does not have a NeutralResourcesLanguageAttribute on it. To be used in
an app package, portable libraries must define a
NeutralResourcesLanguageAttribute on their main assembly (ie, the one
containing code, not a satellite assembly). 4>C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1216,5):
warning APPX2002: Cannot find the neutral resource language for the
resources for portable library 'MyApp'. Verify that
the portable library defines a NeutralResourcesLanguageAttribute. The
build is continuing assuming the project's default culture of 'en-US'
correctly identifies the portable library's neutral resources.
4>MakePRI : warning 0xdef00522: Resources found for language(s) 'de,
es, fr, pt' but no resources found for default language(s): 'en-US'.
Change the default language or qualify resources with the default
language. http://go.microsoft.com/fwlink/?LinkId=231899
But I have no idea how to fix it.
On the tutorial it also says:
Windows Phone projects must be properly configured for localized text
to be displayed. Supported languages must be selected in the Project
Options and the WMAppManifest.xml files. If these settings are not
updated the localized RESX resources will not be loaded.
Fine, but those options doesn't exist anymore. At least where they should be. I even found a Package.appxmanifest file in my project, but it doesn't have those regional options.
So, I need help with an updated way to do it.
Thanks
So I found out that when you add a Windows Phone project to a solution with no Windows Phone projects, it doesn't add everything it needs.
Also the tutorials don't show everything that is necessary (no big news there).
All my project was missing was [assembly: NeutralResourcesLanguage("en-US")] in my PCL AssemblyInfo.cs file.
The RESX tutorial also says that you should use:
if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
{
ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
}
In the TranslateExtention.cs file because Windows Phones don't need it. Well, that's false. At least for the emulator to get the right language, it needs to use the DependencyService and get the CultureInfo this way:
System.Globalization.CultureInfo ci = null;
ci = new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString());
return ci;

WP7 Localization issues from C#

I'm having an issue with the localization in my converters. So, I tried a new project and still have problems.
So, I created a fresh new Silverlight for Windows Phone application (7.0, but 7.1 don't resolve my problem).
I added two resources files: Strings.resx and Strings.fr.resx. This two files have two string property: HelloString and ByeString, all initiated correctly.
Then, I go to the Mainpage.xaml.cs, in the ctor and add the following simple line.
PageTitle.Text = Strings.HelloString;
Whenever I have the emulator or my phone set to English or French, I always got the same strings (Hello).
I tried to rename the file Strings.fr-FR.resx. Still the same issue.
The CurrentUICulture returned from the current thread is correct.
I also tried to force culture on the resource:
Strings.Culture = new System.Globalization.CultureInfo("fr-FR");
Does anyone have an idea?
You don't say that you've set the SupportedCultures for the project. Without this the additional language resource files will never be used.
See http://msdn.microsoft.com/en-us/library/dd941931(v=vs.95).aspx

Resources