Uri to open third party apps for wp8 - windows-phone-8

I tried to create an app that opens some third party apps with the help of its Uri from a Tile. Well, it actually works in opening the third party apps but the problem is, first it launches my app(i.e MainPage is visible for a second) and then only it opens the respective app. Is there any way to make my app's MainPage invisible before opening an app or am i missing anything in Capabilities?
Here is my code :
IconicTileData iconicTileData1 = new IconicTileData();
iconicTileData1.Title = name;
iconicTileData1.SmallIconImage = new Uri("/Icons/Small.png", UriKind.Relative);
iconicTileData1.IconImage = new Uri("/Icons/Metro/" + name + "Medium.png", UriKind.Relative);
IconicTileData iconicTileData2 = iconicTileData1;
Uri navigationUri = new Uri("/MainPage.xaml?target=ms-settings-bluetooth:", UriKind.Relative);
ShellTile.Create(navigationUri, (ShellTileData)iconicTileData2, true);
Thanks in advance for your help.

You could try to specify a "custom" page target (instead of MainPage.xaml) and then make a UriMapper that will allow your app to redirect. Here is a nice blog post on creating a UriMapper. Here is some pseudo-code to help:
public class SettingsUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString.StartsWith == "/LaunchSettings.xaml")
{
// parse which settings to go to
// launch settings uri
}
return uri;
}
}

Related

MVC Open binary in Microsoft Word

I support a web application on an intranet which has a word icon the user can click which will then retrieve bytes from a SQL server and then open Microsoft Word to display the document.
While this works well, our organisation is moving from IE to Chrome, and this doesn't work in Chrome, and from what I have heard Chrome doesn't support ActiveX which is what is used to open Microsoft Word.
So we are looking for a solution that will work in Chrome.
A quick example of what we do.
Javascript fired by onclick event
var wordObject = new ActiveXObject("Word.Application");
wordObject.Documents.open('http://localhost:8080/Document/Download/MyDocument.docx?documentId=12345');
wordObject.Visible = true;
Action in Controller
[HttpGet]
public ActionResult Download(int documentId)
{
var result = DocumentService.GetLatestDocumentVersion(documentId);
if (!result.Succeeded)
{
return HttpNotFound();
}
return new DocumentResult(result.Data.FileData, result.Data.FileType, result.Data.FullName);
}
public class DocumentResult : FileContentResult
{
private ContentDisposition _contentDisposition;
public DocumentResult (byte[] fileContents, FileType fileType, string fileDownloadName)
: base(fileContents, fileType.ToMimeType())
{
string disposition = fileType == FileType.Pdf ? DispositionTypeNames.Inline : DispositionTypeNames.Attachment;
_contentDisposition = new ContentDisposition(disposition);
_contentDisposition.FileName = fileDownloadName;
}
}
I want the same functionality but in Chrome, any ideas?
So instead of opening word through javascript you simply replace the url with something like
Document
This uses office uri schemas see https://learn.microsoft.com/en-us/office/client-developer/office-uri-schemes?redirectedfrom=MSDN
Thanks to MS Premier Support.

How to log in to Chrome with Selenium?

I am testing a Chrome extension which requires the user to be logged in to use, but I cannot figure out how to login with my test account. I have tried logging in to accounts.google.com but this is apparently insufficient; as far as the chrome APIs are concerned there is no authenticated user.
Chrome keeps prompting for login at chrome://chrome-signin but because I can't view the html of the page I can't determine what elements to interact with in Selenium to use it.
You may need to login manually once and then use that for automation.
Try below code , may be it help you:
System.setProperty("webdriver.chrome.driver","<chrome exe path>");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir= <full local path Google Chrome user data default folder>);
WebDriver driver = new ChromeDriver(options);
driver.get("https://mail.google.com");
Login once manually when browser launched.
Then re-run script now it should use previous login.
Hope it will help you.
I think you can still login automatically. The reason is, when opening the page chrome://chrome-signin, the account textbox is automatically focused, so you just need to use keyboards to login without knowing how the html of the page looks like.
Try the code below (you might need to put some sleep in some places to make sure that everything is loaded properly.
public void loginToChrome(username, password) {
driver.get("chrome://chrome-signin");
var action = new Actions(driver);
action.sendKeys(username).perform();
action.sendKeys(keys.ENTER).perform();
action.sendKeys(password).perform();
action.sendKeys(keys.ENTER).perform();
}
First login to gmail on regular chrome browser (NOT the one triggered by selenium driver). Once you login, install the EditTheCookie extension. And on the gmail tab, click this extension icon. It will give option to copy the cookies in json format to clipboard. Paste that into Gmail.data which will be used in below programme.
Once you past, place that Gmail.data file in a avilable location for below programme (you can place anywhere and update the path of that file in below code accordingly).
I've developed this and is a working solution for me since long.
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.google.gson.Gson;
public class LoginUtils {
private static final String GMAIL_LOGIN_URL =
"https://accounts.google.com/signin/v2/identifier";
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver = LoginUtils.login(driver, GMAIL_LOGIN_URL, "Gmail.data");
}
public static final WebDriver login(WebDriver driver, String url, String pathOfJsonFileName) {
Cookies[] data = readJson(pathOfJsonFileName);
driver.navigate().to(url);
// Set the expire time of each cookie.
Date expiryTime = new Date(System.currentTimeMillis() + 1000000000);
for (Cookies cookie : data) {
Cookie ck = new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
expiryTime, Boolean.parseBoolean(cookie.getSecure()), Boolean.parseBoolean(cookie.getHttpOnly()));
driver.manage().addCookie(ck);
}
return driver;
}
private static final Cookies[] readJson(String jsonFileName) {
String json = null;
try {
byte[] encoded = Files.readAllBytes(Paths.get(jsonFileName));
json = new String(encoded);
} catch (Exception e) {
e.printStackTrace();
}
return new Gson().fromJson(json, Cookies[].class);
}
}

Send data changing page Windows Phone

I'm trying to change page and send some data to the new page just create. Basicaly, I have a page where the user could log, I'm gonna save the informations and then I'm going to open a new page by sendind the information to my "profil" page, where the user will have the information about his account. I'm using the MVVM patern, I don't know if it's going to change something but I ad this precision ;).
Edit: The only solution i have found is to pass the string of my object (gladly it is just strings). Because we can pass strings to another page. But I would prefer to give my object directly, or change my architecture if needed. Like don't create a page but replace my Usercontroles by others :(.
Thanks for the help.
For temp data:
If it is WP silverlight app, we can directly assign object to public property of destination page in OnNavigateFrom event of source page. For example, we can declare a public property A on Dest page, and implement the following in Source page to pass the user object:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Dest destPage = e.Content as Dest;
if(destPage != null)
{
User a = new User();
a.UserName = "aa";
a.ID = 1;
destPage.A = a;
}
}
For WP runtime app on WP 8.1, you can directly use Frame.Navigate(TypeName, Object) to pass the parameter.
For persist data:
I will suggest storing the data to local storage on source page and read it from destination page.
If I understand right you should use parameters in navigate URI
For example to send name you can use:
NavigationService.Navigate(new Uri("/View/Page.xaml?name=UserName", UriKind.Relative));
and then in OnNavigatedTo() check name parameter:
string name;
NavigationContext.QueryString.TryGetValue("name", out name);
You can use IsolatedStorageSettings.ApplicationSettings["keyname"]=yourobject;
And whenever you want to use this value just unbox this value as below,
if(IsolatedStorageSettings.ApplicationSettings.Contains("keyname"))
{
var obj=(yourobject)IsolatedStorageSettings.ApplicationSettings["keyname"];
}

Flickr API image unavailable windows phone

I'm trying to use flicke's api to import images into a Windows Phone app and display them on the phones panoramic dispaly.
I'm new to flickr's API and am stuck ATM.
I've tried the following call:
// original string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&format=json&nojsoncallback=1&api_sig=bb86a60e9e42f31950bf53d25fc45f08";
string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&extras=url_sq%2C+url_t%2C+url_s%2C+url_q%2C+url_m%2C+url_n%2C+url_z%2C+url_c%2C+url_l%2C+url_o+&format=json&nojsoncallback=1&api_sig=9e74e094d8c6a7496fc66e070f5c0898";
var baseUrl = string.Format(flickString, flickrAPIKey);
string flickrResult = await client.GetStringAsync(baseUrl);
FlickrData flickrApiData = JsonConvert.DeserializeObject<FlickrData>(flickrResult);
if(flickrApiData.stat == "ok")
{
foreach (Photo data in flickrApiData.photos.photo)
{
// To retrieve one photo
// http://farm{farmid}.staticflickr.com/{server-id}/{id}_{secret}{size}.jpeg
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_o.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_b.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_n.jpg";
string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}"
string baseFlickrUrl = string.Format(photoUrl,
data.farm,
data.server,
data.id,
data.secret);
flickr1Image.Source = new BitmapImage(new Uri(baseFlickrUrl));
break;
}
}
}
When I deploy and run the app I get an image saying that this image is unavailiablemessage every time? I've tried changing the search terms etc and still get the sme message. Which is making me wondor if I've missed something setting up my account with flickr earlier that I'm not aware of? It's very frustrating - help please.
Thanks to card_master for his help so far
I'm also integrating with Flickr. I'm creating a web site that uses their api.
I'm using FlickrNet. This is an open source .net library that you can use to call the Flickr Services. This is a C# library.
The benefit of using it on a mobile application you can take advantage of the caching. It allows you to store images in the phones storage. This won't work on a web application though.

Best Way to keep Settings for a WinRT App?

I'm working on a WinRT app that's actually also a game. I need to keep different information such as audio settings or player statistics somewhere in sort of a file or somehow. If it's a file, just write settings in or... ? I have an idea but I think is way too rudimentary... What is the best approach to obtain this?
Any help or suggestions are greatly appreciated!
Here are some ways to save Data in a WinRT app, the method with Settings in the name is probably what you are looking for!- just added the other ones as well,- you also can serialize data if you want to. This is working code- but don't forget to add error handling etc. It's a simple demo code :)
As for settings, you can save simple settings as key and values, and for more complex settings you can use a container. I've provided both examples here =)
public class StorageExamples
{
public async Task<string> ReadTextFileAsync(string path)
{
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.GetFileAsync(path);
return await FileIO.ReadTextAsync(file);
}
public async void WriteTotextFileAsync(string fileName, string contents)
{
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, contents);
}
public void SaveSettings(string key, string contents)
{
ApplicationData.Current.LocalSettings.Values[key] = contents;
}
public string LoadSettings(string key)
{
var settings = ApplicationData.Current.LocalSettings;
return settings.Values[key].ToString();
}
public void SaveSettingsInContainer(string user, string key, string contents)
{
var localSetting = ApplicationData.Current.LocalSettings;
localSetting.CreateContainer(user, ApplicationDataCreateDisposition.Always);
if (localSetting.Containers.ContainsKey(user))
{
localSetting.Containers[user].Values[key] = contents;
}
}
}
The MSDN has an article on using app settings in Windows Store apps.
The Windows.UI.ApplicationSettings namespace contains all the classes you need.
Provides classes that allow developers to define the app settings that appear in the settings pane of the Windows shell. The settings pane provides a consistent place for users to access app settings.
Basically these classes let you store application settings and hook them into the standard place for all application settings. Your users don't have to learn anything new, the settings will be in the expected place.