Application settings Windows phone 8 - c#

I'm developing for WP8 and I need to store custom app settings. I found func 'ApplicationData' but it's not supported in WP8. Can you help me? I want to store permanent variables provided by user. For example:
Country = UA
News = 1
etc.

You can use Isolated Storage or ApplicationData.LocalSettings like this :
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
Check this Link and also this Link

Related

Can't get thumbnail from AVAsset

In my Xamarin.Forms project, I use dependency injection to call a method inside my .iOS project in order to retrieve a thumbnail of a video that the user just recorded.
Called from my Xamarin.Forms project:
byte[] thumbnailBytes = DependencyService.Get<IMediaMetaData>().ReturnVidThumbnailBytes(vid.Path);
The following code is then called from the .IOS project:
public class MediaMetaData : IMediaMetaData
{
public byte[] ReturnVidThumbnailBytes(string videoFilePath)
{
// videoFilePath example =
// /var/mobile/Containers/Data/Application/3E84C0D0-F590-4AAF-89E7-7D3BFC023E6B/Documents/temp/trim_160491789522565DC08BE-862C-4EE0-A135-BCD9236C6874.mov
//Take local url and create an AVAsset
AVAsset asset = AVAsset.FromUrl(new NSUrl(videoFilePath));
AVAssetImageGenerator assetImageGenerator = AVAssetImageGenerator.FromAsset(asset);
// Total duration of asset
CMTime actualTime = asset.Duration;
// 1/60 = 60th of a second
CMTime cmTime = new CMTime(1, 10);
NSError error;
var imageRef = assetImageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error);
if (imageRef == null)
return null;
var image = UIImage.FromImage(imageRef);
return image.AsJPEG().ToArray();
}
}
The problem:
CopyCGImageAtTime always returns null. I check the NSError and I get the following information:
Class Handle = Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue
code = -11850
Localized failure reason = The server is not correctly configured (But wait, this is a local file I'm accessing here...?)
I've not been able to find any helpful information regarding the class handle error, and the localized failure reason brings up threads from people who are trying to access videos from web services as opposed to local storage. Anyone have experience with the problem I'm having?

How to use Google Cloud Speech (V1 API) for speech to text - need to be able to process over 3 hours audio files properly and efficiently

I am looking for documentation and stuff but could not find a solution yet
Installed NuGet package
Also generated API key
However can't find proper documentation how to use API key
Moreover, I want to be able to upload very long audio files
So what would be the proper way to upload up to 3 hours audio files and get their results?
I have 300$ budget so should be enough
Here my so far code
This code currently fails since I have not set the credentials correctly at the moment which I don't know how to
I also have service account file ready to use
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var speech = SpeechClient.Create();
var config = new RecognitionConfig
{
Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
SampleRateHertz = 48000,
LanguageCode = LanguageCodes.English.UnitedStates
};
var audio = RecognitionAudio.FromStorageUri("1m.flac");
var response = speech.Recognize(config, audio);
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Debug.WriteLine(alternative.Transcript);
}
}
}
}
I don't want to set environment variable. I have both API key and Service Account json file. How can I manually set?
You need to use the SpeechClientBuilder to create a SpeechClient with custom credentials, if you don't want to use the environment variable. Assuming you've got a service account file somewhere, change this:
var speech = SpeechClient.Create();
to this:
var speech = new SpeechClientBuilder
{
CredentialsPath = "/path/to/your/file"
}.Build();
Note that to perform a long-running recognition operation, you should also use the LongRunningRecognize method - I strongly suspect your current RPC will fail, either explicitly because it's trying to run on a file that's too large, or it'll just time out.
You need to set the environment variable before create the instance of Speech:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "text-tospeech.json");
Where the second param (text-tospeech.json) is your file with credentials generated by Google Api.

How to get all enabled keyboard in xamarin.forms with C#

Good day,
in android phone -> virtual keyboard, system list all the enabled keyboards in this page, how can i get all enabled keyboards type with C# in my Xamarin.forms APP?
Thanks!
Roll
In Android, you could use InputDevice.
InputDevice: https://developer.android.com/reference/android/view/InputDevice
You could try the code below:
int[] devicesIds = InputDevice.GetDeviceIds();
foreach (var item in devicesIds)
{
//Check the device you want
InputDevice device = InputDevice.GetDevice(item);
//device.getName must to have virtual
var s = device.Name;
var b = device.KeyboardType;
}
You could use DependencyService to call this in Xamarin.Forms.
DependencyService: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
thanks your reply, i try the way you suggested, but the returned value was not i want...
i found another post here, use that way and finally get the things i want,
here is my code to share:
InputMethodManager manager = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
IList<InputMethodInfo> mInputMethodProperties = manager.EnabledInputMethodList;
IEnumerator<InputMethodInfo> imi = mInputMethodProperties.GetEnumerator();
while (imi.MoveNext())
{
InputMethodInfo inputInfo = imi.Current;
var iN = inputInfo.ServiceName;
}
Best Regards & thanks
Roll

DocuSign SOAP API Title Tab does not keep value

I am using DocuSign SOAP API in an ASP.NET app in C# to send some docs for e-signature.
One of the field is the title tab. I have the following code for that.
When testing, the tab correctly shows the title, which is picked up from the back-end DB. But when I see the completed document, the title is changed to something else. Does anyone know how can I resolve this?
When signing, if I modify the value - add and remove space - it works OK.
tab5 = new DocuSignAPI.Tab();
tab5.RecipientID = rcpt1.ID;
tab5.DocumentID = docId;
tab5.Type = DocuSignAPI.TabTypeCode.Custom;
tab5.CustomTabType = DocuSignAPI.CustomTabType.Text;
tab5.Name = "clientTitle";
tab5.CustomTabTypeSpecified = true;
tab5.Value = (dr["Rcpt_1_Role"]).ToString();
tab5.Type = DocuSignAPI.TabTypeCode.Title;
tab5.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab5.AnchorTabItem.AnchorTabString = "CLIENT TITLE:";
tab5.AnchorTabItem.Unit = DocuSignAPI.UnitTypeCode.Pixels;
tab5.AnchorTabItem.UnitSpecified = false;
tab5.AnchorTabItem.IgnoreIfNotPresent = true;
tab5.AnchorTabItem.UnitSpecified = true;
tab5.AnchorTabItem.YOffset = -10;
tab5.AnchorTabItem.XOffset = 100;
When using certain DocuSign tab types (such as titleTabs or emailTabs for instance) the DocuSign platform will populate some of that information from the user's account if they have one.
For example, if the user has a DocuSign account where they have entered the title "CEO", then whenever you send an envelope to that exact recipient (name and email combo) and you use a titleTab the system will populate from their account.
I do not believe there is a way to override this, probably your best option is to just use a textTab instead and with that you can populate with any data from a database or wherever else you want to supply it from.

Saving a list - Windows 8

I'm developing the Windows 8 equivalent of my app.
I'm trying to save simple list of strings to ApplicationDataContainer, as I would with IsolatedStorage for Windows Phone 8.
In Windows Phone 8 I would do it like this:
List<String> myList;
myList= readSetting("myList") != null ? (List<String>)readSetting("myList") : new List<String>();
Helper method:
private static object readSetting(string key)
{
return IsolatedStorageSettings.ApplicationSettings.Contains(key) ? IsolatedStorageSettings.ApplicationSettings[key] : null;
}
But how should I do this in Windows 8? My app is of the type Split Page.
Thanks a lot!
Kind Regards,
Erik
Try using Storage Helpers like this and this. Or you can use StorageFile in Windows 8 which allows you read-write files in local folder
The equivalent to IsolatedStorageSettings on Win8 (and WP8) is ApplicationData.Current.LocalSettings
Create a container
var container = ApplicationData.Current.LocalSettings.CreateContainer("defaultContainer",ApplicationDataCreateDisposition.Always);
container.Values["newKey"] = "New Value";
Your method would become:
private static object readSetting(string key)
{
var container = ApplicationData.Current.LocalSettings.CreateContainer("defaultContainer",ApplicationDataCreateDisposition.Existing);
if (container == null)
{
return null;
}
return Container.Values[key]
}
Note that this will also work on Windows Phone 8 if you would like to reuse some code between the two platforms.

Categories