For desktop apps, I've used the following to access network shares:
[DllImport("mpr.dll")]
private static extern int WNetAddConnection2(NetResource netResource,
string password, string username, int flags);
[DllImport("mpr.dll")]
private static extern int WNetCancelConnection2(string name, int flags,
bool force);
Are there similar APIs available on WP8 SDK?
No. Windows phone doesn't support network shares. It's not the same as full windows. There is not dllimport or access to native Apis
I don't think this is possible either. Plus I'm sure you don't want to build a small server to serve up files and folders from the targeted computer... but you can do something similar to what the app "Easy Transfer" (http://www.windowsphone.com/en-us/store/app/easy-transfer/5ccb6655-2ff9-4977-bf8b-577e92bbb236) did and build the app to act as the server.
Related
I'd like to access my app's certificate store from another app. I have already enabled "sharedusercertificates" in the package.appmanifest file.
Windows.Storage.StorageFile selectedCertFile = await folder.GetFileAsync(fileName);
IBuffer buffer = await FileIO.ReadBufferAsync(selectedCertFile);
string certificateData = CryptographicBuffer.EncodeToBase64String(buffer);
string password = "password";
await CertificateEnrollmentManager.ImportPfxDataAsync(
certificateData,
password,
ExportOption.NotExportable,
KeyProtectionLevel.ConsentWithPassword,
InstallOptions.None,
selectedCertFile.DisplayName);
In my own app, I can list the installed certificates without a problem:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var task = CertificateStores.FindAllAsync();
task.AsTask().Wait();
var certlist = task.GetResults();
Debug.WriteLine("Cert count: {0}", certlist.Count);
LoadCertList(certlist);
}
private void LoadCertList(IReadOnlyList<Certificate> certificateList)
{
listbox1.Items.Clear();
foreach (Certificate cert in certificateList)
{
listbox1.Items.Add(cert.Subject);
}
}
If I try to access those from another app, It will not be listed.
In the Windows Phones 8.1's mail client settings, the installed certificate is missing, too. Certificates which have been installed regularly, not programmaticaly, are listed.
Is there a way to install my custom certificates to the system's certificate store? So it can be used in other apps.
I have been searching the web for days now, but I didn't find a solution.
Due to this, it should be possible.
"The sharedUserCertificates capability grants an app container read access to the certificates and keys contained in all user stores and the Smart Card Trusted Roots store. "
https://msdn.microsoft.com/en-us/library/windows/apps/hh465025.aspx
Did I miss something? Help will be much appreciated.
Dino
If you want a certificate to be accessible for other Apps, you need to enroll it using CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync rather then CertificateEnrollmentManager.ImportPfxDataAsync.
Please note that there is no way of deleting the shared certificate unless it's expired (using InstallOptions.DeleteExpired as a Parameter in ImportPfxDataAsync).
Also, the more certificates you share this way, the slower the queries against the certificate stores get.
I am developing a Windows Phone 8.1 Application and there is a need to get the Application Process ID from code. Any API with which I can get that?
You can use GetCurrentProcess followed by DuplicateHandle (and later CloseHandle) but I'm curious what you need it for... there's not much you can do with it in a Store app so maybe this won't complete your scenario.
Finally got the solution.
The Dll's for Desktop apps and Phone apps are different though the function names will be same.
When tried to import Kernal.dll lib in WIn Phone 8.1 and used p/invoke code, an exception, DllNotFoundException will be thrown. Instead in Win Phone 8.1 instead use "api-ms-win-core-processthreads-l1-1-1.dll"
To get the process ID in Win Phone 8.1 :
1)Create binding to WIN32 lib:
[DllImport("api-ms-win-core-processthreads-l1-1-1.dll", CharSet = CharSet.Unicode, ExactSpelling = false, PreserveSig = true)]
internal static extern uint GetCurrentProcessId();
2)Call the function:
uint id= GetCurrentProcessId();
For the complete set of Win Phone 8 supported API's see the MSDN link:
https://msdn.microsoft.com/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs
Basically I am PHP developer! and now I want to implement the push notifications for windows phone! So for this I have refereed many blogs and also started implement on this! but for demo purpose how I can get my device token and device specific type of my phone that having Windows 8.1 OS.
Is any GUI tool for getting this.
If you need the Device Token as follows-
Byte[] DeviceArrayID = (Byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string UniqueDeviceID = Convert.ToBase64String(DeviceArrayID);
Debug.WriteLine("Device ID - " + UniqueDeviceID
Also, if you need help regarding push notifications in Windows Phone apps, follow this link-
http://msdn.microsoft.com/en-us/library/windows/apps/hh202967%28v=vs.105%29.aspx
It also has a project for a simple webpage which can send notification to your device for testing purposes.
The following should work
object DeviceUniqueID;
byte[] DeviceIDbyte = null;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out DeviceUniqueID))
DeviceIDbyte = (byte[])DeviceUniqueID;
string di = Convert.ToBase64String(DeviceIDbyte);
The above code will give you the device ID. You can use the string di to pass the Device ID to your web service to provide the user with push notifications.
I use Code Contracts in my code, my app runs fine on the emulator. When I deploy it on a device, it fails/crashes whenever Contract statement is executed.
public static HTTPRequest CreateGetRequest(string url,
bool shouldUseCustomTimeout)
{
// preconditions
Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(url));
return new HTTPRequest(url,
System.Net.Http.HttpMethod.Get,
shouldUseCustomTimeout);
}
Is the code contract supported on actual device? Should I install a separate extension?
Is the code contract supported on actual device?
Yes.
I got it working by following the steps on this blog: http://blog.stephencleary.com/2011/01/simple-and-easy-code-contracts.html
It turns out that I had to enable for the library projects too. I was setting code contracts only for the test app.
I'm building an app and I would like to track my device data session information.
For example duration, received bytes, sent bytes, bearer, access point, local IP address, protocol when connected using wifi, 3g, gprs, cell network.
If I can get all would be perfect, but getting 1 is more than enough.
I hope someone could show me some solutions or possibles APIs, if possible.
Thanks a lot in advance.
There are 3 namespaces in WP8 that provide network information: System.Net.NetworkInformation, Microsoft.Phone.Net.NetworkInformation and the new WP8 WinPRT namespace Windows.Networking.Connectivity.
While DataUsage/DataPlan APIs are available in the new WP8 namespace, they aren't supported on WP8 and only exist for Win8 API compatibility. You can use either the new WP8 APIs or WP7 APIs to enumerate over all connected interface type and check if they're WiFi/Ethernet/3G/etc:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
foreach (var network in new NetworkInterfaceList())
{
Debug.WriteLine(network.InterfaceType);
}
}