I have Created a AppResource.Resx and and AppResource.da.resx and i have also Resources string in String.XML with Value-da => String.XML
AppResources.Culture = new CultureInfo("da-DK");
Java.Util.Locale.Default = new Java.Util.Locale("da", "DK");
Resources.Configuration.Locale = Java.Util.Locale.Default;
Resources.UpdateConfiguration(Resources.Configuration, Resources.DisplayMetrics);
var sfs = Resources.GetText(Resource.String.AboutLabel);
var dfdd = AppResources.AboutLabel;
Finish();
Intent intent = new Intent(this, this.Class);
StartActivity(intent);
var dffdsadd = AppResources.AboutLabel;
var fdsfdsafs = Resources.GetText(Resource.String.AboutLabel);
here is I'm Trying to set or update the Resources of android and these resources get from AppResource.resx file but not updating resources?
How i can bind AppResources string with android String so localization and value access?
When you import files, translate files, export files, for use in your Xamarin mobile apps, you could use one of the following file formats:
RESX files for Xamarin.Forms
Localizable.strings files for the Xamarin.iOS native platform
Android Strings files for the Xamarin.Android native platform
Do not bind AppResources string with android String so localization and value access. You could download the sample code from the link for reference.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?pivots=windows
Related
The code I have now is:
Intent intent = new Intent();
intent.SetType("text/plain");
intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(intent, "Select file"), 1);
string str = System.Environment.GetFolderPath(?????);
That last line of course doesn't work. I'd like the user to be able to browse folders on the device and open one of them. This is simple in Windows but Android is proving difficult.
1/3/2023:
This issue is still unsolved. Coming from Windows and C# this is all trivial. But Android, not.
I have tried these:
var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var documents = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory);
var documents = System.Environment.CurrentDirectorygetExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
WIth some I can save the file from my app on Android but I cannot find them (non-programmatically).
When I save files in FXTextEdit (on Android), I save them to folders I can easily access. Why not progammatically?
I am coding in C#.
Thanks.
I'm using Xamarin iOS. I'd like to have our application open a .pdf file in the default reader. For Android I managed to get it done by following a two-fold process: (1) copy the file from the Assets folder to the Android device's Downloads folder, and (2) starting an activity to view the file.
I cannot find any similar resources for the iOS. We don't want to use the control in the Xamarin website, as it involves downloading lots of JavaScript (?) code, making the size of the app bigger, and also doesn't support pinching the screen to zoom. We want to use the OS's default pdf reader.
Thank you.
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
I google a lot over this and still can't found a way to make it work
My app downloads epubs from many sources and then I save them to the local Storage (and unzip them)
I can read the extracted files with no problems with Storage commands but just can't to open it on WebView control
I tried all this:
The real path: C:\Data\Users\DefApps\APPDATA\Local\Packages\xxx\LocalState\***
Uri localUri = new Uri("ms-appx-web:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("ms-appdata:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///LocalState/***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///C://Data//Users//DefApps//APPDATA//Local//Packages//xxx//LocalState//***//OEBPS//04_CL_CH.01.xhtml");
// two ways
WebView1.Navigate(localUri);
WebView1.Source = localUri;
// this works, but as is an epub file, so need lot of files and styles
var XHTML = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("***\\OEBPS\\04_CL_CH.01.xhtml");
WebView1.NavigateToString(await Windows.Storage.FileIO.ReadTextAsync(XHTML));
This is a C# Windows Phone universal app, and I'm using VS 2013 Express
Take a look at http://blogs.windows.com/buildingapps/2013/07/17/whats-new-in-webview-in-windows-8-1/, it says:
ms-appdata:///local/TopLevelDirectory/file for files from the local
state
ms-appdata:///temp/TopLevelDirectory/file for files from the
app’s temporary state folder
This will get me my iOS app's document root:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Is there something similar to get to the Library folder?
var docsPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var libPath = Path.Combine (docsPath, "..", "Library");
Currently (iOS 12) you can retrieve the Library path via:
var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Resources);
".../APP-UUID/Library"
For directories nested within the Library folder, such as the local app cache, you can do:
var pathToCache = Path.Combine(libraryPath, "Caches");
".../APP-UUID/Library/Caches"
Additional directories on Xamarin IOS that may be of interest:
SpecialFolder.Favorites = ".../APP-UUID/Library/Favorites"
SpecialFolder.MyDocuments = ".../APP-UUID/Documents"
SpecialFolder.MyMusic = ".../APP-UUID/Documents/Music"
SpecialFolder.MyPictures = ".../APP-UUID/Documents/Pictures"
SpecialFolder.MyVideos = ".../APP-UUID/Documents/Videos"
SpecialFolder.Desktop = ".../APP-UUID/Documents/Desktop"
More options can be explored on the Xamarin Docs for File System
In iOS8 I used this and it worked:
NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User) [0].Path
I got this from Xamarin's page about the iOS file system. It says "iOS 8 NOTE: parts of this document are affected by changes in iOS 8. If your application uses Environment.SpecialFolder or calculates relative paths like "../Documents" you should read this tech note from Apple. Updated information is also available at iOS File System Basics."
I'm trying to make an android app with a webview which can upload images to a html page.
I think i found a solution here: Android ACTION_IMAGE_CAPTURE Intent
but i'm having trouble translating everything to Xamarin c#, any can help me here? the code i'm interestet in is:
File imageDirectory = new File("/sdcard/signifio");
String path = imageDirectory.toString().toLowerCase();
String name = imageDirectory.getName().toLowerCase();
ContentValues values = new ContentValues();
values.put(Media.TITLE, "Image");
values.put(Images.Media.BUCKET_ID, path.hashCode());
values.put(Images.Media.BUCKET_DISPLAY_NAME,name);
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Media.DESCRIPTION, "Image capture by camera");
values.put("_data", "/sdcard/signifio/1111.jpg");
uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, 0);
more specific it's what classes i have to import to find Media.TITLE, Images.Media.BUCKET_ID.... and so forth.
Try Android.Provider.MediaStore
If they aren't in their you could use the actual strings instead, see the Android documentation
Here's the call to getContentResolver Xamarin style:
this.ContentResolver.Insert(Android.Provider.MediaStore.Images.Media.ExternalContentUri, values);
For the location of the file use:
Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
There is a recipe for using a camera intent in the Xamarin documentation.