Get phone carrier using WP7.1 SDK - windows-phone-7.1

Is there any way to get the phone carrier using WP7.1 SDK?

According to http://msdn.microsoft.com/en-us/library/hh202875%28v=vs.92%29.aspx you can get it from DeviceNetworkInformation.CellularMobileOperator
e.g.
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("Mobile operator: ");
sb.AppendLine(DeviceNetworkInformation.CellularMobileOperator);
MessageBox.Show(sb.ToString());
}

Related

How do you send message using NFC with Xamarin.Android?

I am developing and app to demostrate how NFC works. My goal is to make and app that will work very similary to Android Beam. I am using Xamarin.Android. The goal is to type message to one device, press button and it should be send to another device with the same app where it should be shown. I have tried almost everything even the documentation but it seems like it doesnt work. Does anyone have any experience with this technology? Is this technology even available nowadays?
There is some of my code to get you an idea about what i am trying to do:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
mNfcAdapter = NfcAdapter.GetDefaultAdapter(this);
myButton.Click += (e, o) => {
mNfcAdapter.SetNdefPushMessageCallback(this, this);
mNfcAdapter.SetOnNdefPushCompleteCallback(this, this);
};
}
public NdefMessage CreateNdefMessage(NfcEvent e)
{
DateTime time = DateTime.Now;
var text = (time.ToString("HH:mm:ss") + message2);
NdefMessage msg = new NdefMessage(
new NdefRecord[] { CreateMimeRecord (
text, Encoding.UTF8.GetBytes (text))});
return msg;
}
private NdefRecord CreateMimeRecord(string mimeType, byte[] payload)
{
byte[] mimeBytes = Encoding.UTF8.GetBytes(mimeType);
NdefRecord mimeRecord = new NdefRecord(
NdefRecord.TnfMimeMedia, mimeBytes, new byte[0], payload);
return mimeRecord;
}
public void OnNdefPushComplete(NfcEvent e)
{
Toast.MakeText(this.ApplicationContext, "Message sent", ToastLength.Long).Show();
}
protected override void OnResume()
{
base.OnResume();
if (NfcAdapter.ActionNdefDiscovered == Intent.Action)
{
ProcessIntent(Intent);
}
}
protected override void OnNewIntent(Intent intent)
{
Intent = intent;
}
void ProcessIntent(Intent intent)
{
IParcelable[] rawMsgs = intent.GetParcelableArrayExtra(
NfcAdapter.ExtraNdefMessages);
NdefMessage msg = (NdefMessage)rawMsgs[0];
var textViewMsg = FindViewById<TextView>(Resource.Id.textViewMsg);
textViewMsg.Text = Encoding.UTF8.GetString(msg.GetRecords()[0].GetPayload());
}
Thank you all :)
OnNdefPushComplete and the whole Android Beam was deprecated and removed from Android 10
https://developer.android.com/reference/android/nfc/NfcAdapter.OnNdefPushCompleteCallback
If you want to do Device to Device NFC going forward then it should be possible with one phone doing Host Card Emulation (HCE) and the other using enableReaderMode
But Google recommend using Bluetooth or Wifi Direct as a more reliable replacement for Android Beam. One of the replacement methods Google provided was Android Nearby https://developers.google.com/nearby

Unable to connect BlackBerry phone with Bluetooth SPP device

I am trying to connect to a bluetooth device from the blackberry 9900 phone using the following code;
public final class AppMainScreen extends MainScreen {
private BluetoothspInfo[] spInfo;
private StreamConnection bConn;
private DataInputStream diStream;
private String text;
public AppMainScreen() {
spInfo = BluetoothSerialPort.getSerialPortInfo();
try {
bConn = (StreamConnection) Connector.open(
spInfo[0].toString(), Connector.READ);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
UiApplication.getUiApplication().invokeLater(new TextScanner());
}
// ...
// ...
// ...
}
But its always throwing the exception java.io.IOException: Unable to connect. I am not able to get the full trace.
What is the problem here, can anybody please point me in the right direction.
I am using the BlackBerry Java on BlackBerry Eclipse Plugin with Platform version 4.5.

QR Code Live Scanning in BlackBerry OS 6.0

I want to Implement a QR Code Reader In BlackBerry Os 6. I try the following Code On the Basis of KB Article How to use the Barcode API.
public class ScanScreen extends MainScreen implements BarcodeDecoderListener
{
private LabelField match;
private BarcodeScanner scanner;
public ScanScreen()
{
match = new LabelField("Scanning...");
add(match);
Vector supported = new Vector();
supported.addElement(BarcodeFormat.QR_CODE);
Hashtable hints = new Hashtable();
hints.put(DecodeHintType.POSSIBLE_FORMATS, supported);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
BarcodeDecoder decoder = new BarcodeDecoder(hints);
try
{
scanner = new BarcodeScanner(decoder, this);
add(scanner.getViewfinder());
scanner.startScan();
}
catch (Exception e)
{
e.printStackTrace();
match.setText("Exception");
invalidate();
}
}
public void barcodeDecoded(String rawText)
{
match.setText("Found: " + rawText);
invalidate();
}
public void close()
{
try
{
scanner.stopScan();
}
catch (Exception e)
{
e.printStackTrace();
}
super.close();
}
}
The Code not working. It do not recognize QR codes. I try to focus on different QR codes. But it not decode The qrcodes.Also It not Thrown Any exceptions. Please Help me....
I tried using these Devices: BB pearl 9105 and BB Storm 9530
See the sample from the following link.It will help you
http://aliirawan-wen.blogspot.com/2011/05/barcode-scanner-for-blackberry-os-50.html
I'm painfully new to BB development, but I notice you pass "this" as the decoderlistener parameter, perhaps that's causing a problem?
BarcodeDecoder decoder = new BarcodeDecoder(hints);
BarcodeDecoderListener decoderListener = new BarcodeDecoderListener()
{
public void barcodeDecoded(String rawText)
{
displayMessage(rawText);
}
};
try
{
scanner = new BarcodeScanner(decoder, decoderListener)
add(scanner.getViewfinder());
scanner.startScan();
}
catch (Exception e)
{
e.printStackTrace();
match.setText("Exception");
invalidate();
}
}

Login to another website and parse data

There is php page, let's call it http://www.aaaa.org/login.php which has two textboxes (name="username" and name="password") and a button.
And there is my .aspx page from which I want to login to that .php page. Once logged in I want to retrieve and parse some content of a subpage http://www.aaaa.org/details.php?id=1234.
I tried some code but it always retrieves the content of the login.php page so I assume I can't login at all.
Can you show me the exact code how to do this?
The language is C#.
To do this, you can use an HTTPClient library. Something like this:
http://www.codescales.com/
This will enable you to login and access the client application. Note that your application will be fragile and subjected to the web app and it's changes. So if they change the field names, your app will have to change as well. But it will work for what you are trying to achieve.
I would also suggest writing this as a separate library and not directly in your ASPX code.
protected void Page_Load(object sender, EventArgs e)
{
WebClient req = new WebClient();
CredentialCache myCache = new CredentialCache();
//myCache.Add(new Uri("http://www.aaaa.org/login.php"), "Basic", new NetworkCredential("login", "passw"));
myCache.Add(new Uri("http://www.aaaa.org/login.php"), "Digest", new NetworkCredential("login", "passw"));
req.Credentials = myCache;
string results;
results = System.Text.Encoding.UTF8.GetString(req.DownloadData("http://www.aaaa.org/login.php"));
}
protected void Button1_Click(object sender, EventArgs e)
{
string TheUrl = "http://www.aaaa.org/details.php?id=2923";
string response = GetHtmlPage(TheUrl);
TextBox2.Text = response;
}
---------------- updated: -----------------
protected void Page_Load(object sender, EventArgs e)
{
WebClient req = new WebClient();
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri("http://www.aaaa.org/login.php"), "Basic", new NetworkCredential("login", "passw"));
NameValueCollection postData = new NameValueCollection();
postData.Add("username", "login");
postData.Add("password", "passw");
req.UploadValues("http://www.aaaa.org/login.php", postData);
req.Credentials = myCache;
string results;
results = System.Text.Encoding.UTF8.GetString(req.DownloadData("http://www.aaaa.org/login.php"));

Problem with SaveFileDialog in Silverlight 3

i have weird exception by SaveFileDialog in Silverlight 3. I don't really have a idea where the problem is.
I create instance of SaveFileDialog in Loaded event of user control. After Download button is clicked and dialogResult is true asynchronous file download is started. After file download is completed, method OpenFile() is called. This works fine once, but second time I get exception:
Exception message:
"No file was selected"
Details:
{System.InvalidOperationException: No file was selected.
at System.Windows.Controls.SaveFileDialog.OpenFile()
at Spaces.Client.Views.Dialogs.FileDialog.BL_DownloadFileCompleted(Object sender, EventArguments`1 e)
at Spaces.Client.BL.Interface.DownloadFileCompletedEventHandler.Invoke(Object sender, EventArguments`1 e)
at Spaces.Client.BL.WebService.SpacesService._spacesService_DownloadFileCompleted(Object sender, DownloadFileCompletedEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Spaces.Client.BL.SpacesServiceReference.ServiceClient.OnDownloadFileCompleted(Object state)}
Stack:
at System.Windows.Controls.SaveFileDialog.OpenFile()
at Spaces.Client.Views.Dialogs.FileDialog.BL_DownloadFileCompleted(Object sender, EventArguments`1 e)
at Spaces.Client.BL.Interface.DownloadFileCompletedEventHandler.Invoke(Object sender, EventArguments`1 e)
at Spaces.Client.BL.WebService.SpacesService._spacesService_DownloadFileCompleted(Object sender, DownloadFileCompletedEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Spaces.Client.BL.SpacesServiceReference.ServiceClient.OnDownloadFileCompleted(Object state)
Here code snippet:
private void _userControlFileDialog_Loaded(object sender, RoutedEventArgs e)
{
_comboBoxVersions.ItemsSource = _file.Versions;
if (_comboBoxVersions.Items.Count > 0)
_comboBoxVersions.SelectedIndex = 0;
String extension = "*." + _file.Extension;
_sfd = new SaveFileDialog();
_sfd.DefaultExt = _file.Extension;
_sfd.Filter = extension + "|" + extension;
}
private void _hyperlinkButtonDownload_Click(object sender, RoutedEventArgs e)
{
string path = ((FileVersion)_comboBoxVersions.SelectedItem).Url;
bool? dialogResult = _sfd.ShowDialog();
if (dialogResult == true)
{
AppContext.BL.DownloadFileCompleted += new Spaces.Client.BL.Interface.DownloadFileCompletedEventHandler(BL_DownloadFileCompleted);
AppContext.BL.DownloadFileAsync(AppContext.AuthenticatedUser, path);
}
}
void BL_DownloadFileCompleted(object sender, Spaces.Client.BL.Interface.EventArguments<byte[]> e)
{
byte [] data = e._result;
using (Stream fileStream = (Stream)_sfd.OpenFile())
{
fileStream.Write(data, 0, data.Length);
fileStream.Flush();
fileStream.Close();
}
}
Have anybody idea what is wrong?
Regards
Anton Kalcik
There was problem with multiple event handlers. On each click is event handler attached and never detached. Event handler stays attached also after UserControl is closed. So it is on developer to detach event handler on properly way.
Regards
AKa

Resources