Whether SIM card is available or not in windows phone universal project - windows-runtime

I'm creating winrt universal project for mobile and tablet.
I want to check:
In mobile application, I am sending a sms text to sms application like this.
var message = new ChatMessage();
message.Recipients.Add("9999");
message.Body = "R*" + voucherNo + "*" + accountNo + "*" + pin;
await ChatMessageManager.ShowComposeSmsMessageAsync(message);
I want to place a check above that whether user has inserted sim card or using mobile with out sim card. Well app is not crashing due to this so this is not a big issue if I couldn't place that check here (as I have already searched alot about it but got nothing so I'm assuming that it is not possible right not in winrt to check sim card availability), but a link of documentation/blog/SO question regarding this where it is mentioned that you can't check sim card availability would be helpful.
Thanks.

bool simAvailable = false;
var device = await ChatMessageManager.GetTransportsAsync();
if (device != null && device.Count > 0)
{
foreach (var item in device)
{
if (item.TransportFriendlyName != "No SIM")
{
simAvailable = true;
break;
}
}
}
Just enter this code and Simavailable will be true if phone hase sim card.

Related

Get SIM MSISDN & IMSI number in Windows Phone Application

Is it possible to get the SIM MSISDN & IMSI number in windows Phone app development?
I have gone through some of the Q/A but they all are asked a long time ago.
You could get SIM MSISDN & IMSI number in Windows Phone Application. Please notice that you should manually edit your application Package.appxmanifest as follows:
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
......
<Capabilities>
<rescap:Capability Name="cellularDeviceIdentity" />
</Capabilities>
The cellularDeviceIdentity capability allows apps to access cellular identification data.
Anyone may request access to these capabilities for store submission.
You could use MobileBroadbandModem class to get all CurrentDeviceInformation, and the following is core codes.
using Windows.Networking.NetworkOperators;
......
public IReadOnlyList<SimCard> GetSimCards()
{
var results = new List<SimCard>();
var modem = MobileBroadbandModem.GetDefault();
if (modem == null)
{
return results.AsReadOnly();
}
var account = modem.CurrentAccount;
if (account == null)
{
return results.AsReadOnly();
}
var simCard = new SimCard();
simCard.ICCID = account.CurrentDeviceInformation.SimIccId;
simCard.IMSI = account.CurrentDeviceInformation.SubscriberId;
simCard.MSISDN = modem.DeviceInformation.TelephoneNumbers;
simCard.MCC = ExtractMCC(simCard.IMSI);
simCard.MNC = ExtractMNC(simCard.IMSI);
simCard.MSID = ExtractMSID(simCard.IMSI);
results.Add(simCard);
return results.AsReadOnly();
}
I have uploaded code sample to git hub. Please check!

Get physical screen(display) resolution. Windows Store App

I need current display resolution. How can i get this? I know about Window.Current.Bounds, but application can worked in windows mode.
what do you mean VisibleBounds is not working on Deskptop?
I tried in my win10 UWP program, it works fine. I can get my desktop resotion like below:
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
var size = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);
Besides, if you are using DX in store app, you can create an IDXGIFactory object and use it to enumerate the available adapters. Then call IDXGIOutput::GetDisplayModeList to retrieve an array of DXGI_MODE_DESC structures and the number of elements in the array. Each DXGI_MODE_DESC structure represents a valid display mode for the output. e.g.:
UINT numModes = 0;
DXGI_MODE_DESC* displayModes = NULL;
DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT;
// Get the number of elements
hr = pOutput->GetDisplayModeList( format, 0, &numModes, NULL);
displayModes = new DXGI_MODE_DESC[numModes];
// Get the list
hr = pOutput->GetDisplayModeList( format, 0, &numModes, displayModes);
Please let me know if you need further information.

Windows phone 8.1 using Contact Picker to retrieve both email and phone number

I am using the following code to allow the user to select contacts:
ContactPicker ContactPicker = new ContactPicker();
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
var Contacts = await ContactPicker.PickContactsAsync();
if (Contacts.Count > 0)
{
foreach (Contact contact in Contacts)
{
string telephone = string.Empty;
string email = string.Empty;
if (contact.Phones.Count > 0)
{
telephone = contact.Phones[0].Number;
}
if (contact.Emails.Count > 0)
{
email = contact.Emails[0].Address;
}
PartyPerson person = new PartyPerson(DateTime.Now.ToString("PP_yyMMdd_hhmmss_ffff"), true, contact.DisplayName, 0, 0, 0, email, telephone);
AddPartyPerson(person);
}
}
ContactPicker = null;
However, I only get phone number, the object "contact" does not contain any email addresses even though they are present in the contact information.
One option is to switch:
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
with
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
But then I don't get a phone number... I want to be able to retrieve all the information in one select.
Is there any way to select both information via one select?
(I also tried adding more than one entry to DesiredFieldsWithContactFieldType but then I get an exception...)
Best regards,
Keran
EDIT 07.08.2015:
Since the "ContactPicker.DesiredFieldsWithContactFieldType" can only accept one type of "ContactFieldType", the way I worked around this was first allow the user to get the contacts by ContactFieldType.PhoneNumber and then I programatically retrieve the email addressess of the selected contacts.
From the users point of view, this won't be a problem since everything will be visible correctly in the ContactPicker.PickContactsAsync, we just need to retrieve the missing email information manually in code-behind, which is easy since we know what contacts were selected by the user.
Try this:
ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);
ContactPicker contactPicker = new ContactPicker();
IList<Contact> pickedContacts = await contactPicker.PickContactsAsync();
int pickedCount = pickedContacts != null ? pickedContacts.Count : 0;
if (pickedCount > 0)
{
for (int i = 0; i < count; ++i)
{
Contact c = pickedContacts[i];
Contact realContact = await contactStore.GetContactByIdAsync(c.Id);
//...
}
}
So, you first need to get the "skeleton" of the contact, and then you can get the whole contact entity with all its properties from the ContactStore object.
It works for me on Windows 10 Mobile. There shouldn't be much difference from Windows 8.
Hope it helps.

IconicTile not getting updated in windows phone 8.0

I have defined IconicTile Template as default tile for my Application. Now I wish to update my tile with the notification count. So I have sent following parameters for the update:
backgroundColor,
count,
title,
iconImage,
smallIconImage,
wideContent1,
wideContent2,
wideContent3
Tile update works fine on the test device running on windows phone 8.1 but its not coming up on device and emulators running on windows phone 8.0. What am I missing here? Please help
Are you targeting your application for WP8 or WP8.1?
Try adding this snippet in your class.
IconicTileData TileData = new IconicTileData()
{
Title = "[title]",
Count = [count],
WideContent1 = "[1st row of content]",
WideContent2 = "[2nd row of content]",
WideContent3 = "[3rd row of content]",
SmallIconImage = [small Tile size URI],
IconImage = [medium/wide Tile size URI],
BackgroundColor = [.NET color type of Tile]
};
Hope this live tile is not updating in Windows Phone helps.

HTMLTextBlock for Windows Phone 7

I am trying to include a html textbox into my windows phone 7. I see some sample code here. The problem is that the HTMLPage class doesn't exist in windows phone 7, or more exactly, the System.Windows.Browser does not exist. Do anybody know an alternative for this?
I struggled with this for all the same reasons, and eventually came up with a solution. I need to show a bunch of these inside a ListBox for my Septic's Companion app. Right now my solution only deals with bold or italic (as that's all I cared about) but it would be easy to modify it to deal with more. First, into my ViewModel I wrote a routine to return a TextBlock given an HTML string.
private TextBlock MakeFormattedTextBlock(string shtml)
{
TextBlock tb = new TextBlock();
Run temprun = new Run();
int bold = 0;
int italic = 0;
do
{
if ((shtml.StartsWith("<b>")) | (shtml.StartsWith("<i>")) |
(shtml.StartsWith("</b>")) | (shtml.StartsWith("</i>")))
{
bold += (shtml.StartsWith("<b>") ? 1 : 0);
italic += (shtml.StartsWith("<i>") ? 1 : 0);
bold -= (shtml.StartsWith("</b>") ? 1 : 0);
italic -= (shtml.StartsWith("</i>") ? 1 : 0);
shtml = shtml.Remove(0,shtml.IndexOf('>') + 1);
if (temprun.Text != null)
tb.Inlines.Add(temprun);
temprun = new Run();
temprun.FontWeight = ((bold > 0) ? FontWeights.Bold : FontWeights.Normal);
temprun.FontStyle = ((italic > 0) ? FontStyles.Italic : FontStyles.Normal);
}
else // just a piece of plain text
{
int nextformatthing = shtml.IndexOf('<');
if (nextformatthing < 0) // there isn't any more formatting
nextformatthing = shtml.Length;
temprun.Text += shtml.Substring(0, nextformatthing);
shtml = shtml.Remove(0, nextformatthing);
}
} while (shtml.Length > 0);
// Flush the last buffer
if (temprun.Text != null)
tb.Inlines.Add(temprun);
return tb;
}
Then I just needed a way to build this into my XAML. This may not be the very best solution, but I first made another routine to return a StackPanel containing that TextBlock with the text I wanted.
public StackPanel WordBlock
{
get
{
StackPanel sp = new StackPanel();
TextBlock tbWord = MakeFormattedTextBlock("<b>" + Word + "</b>: " + Desc);
sp.Children.Add(tbWord);
return sp;
}
}
To bind this to a visible control, I then made a DataTemplate for my ListBox which simply read the entire StackPanel out of my view model.
<DataTemplate x:Key="WordInList2">
<ContentControl Content="{Binding WordBlock}"/>
</DataTemplate>
As I say, there may be parts of this that aren't done as elegantly as they might be, but this did what I wanted. Hope it works for you!
Hey I converted the SilverlightHtmlTextBlock to WP7 Here. I
haven't tested it for terribly complex cases and blows up on dtd tags but, it does the job for simpler html cases and sounds like what you were looking for.
WebBrowser can render html.
How to: Display Static Web Content Using the WebBrowser Control for Windows Phone