I know this has been brought up many times but couldn't find an answer for it.
I am trying to set up push notifications in my app using the below code however I am running into the channel uri null problem.
I have tried the app on 4 different devices + emulator all under the same network conditions (Work WiFi - Home WiFi - 3G) 2 of the devices are Lumia 920 both could not obtain a channel uri, while the other 2 devices an HTC 8X and a Lumia 820 can successfully obtain channel uri and register for push.
The emulator also can obtain a channel uri successfully.
On one of the Lumia 920's it managed to get a channel uri, but I uninstalled and installed the app again and since then couldn't get any channel uri.
Below are my scenarios:
1- Lumia 920 Black installed on 3G worked fine, uninstalled/reinstalled stopped working on any connection (3G - Work WiFi - Home WiFi)
2- Lumia 920 Yellow installed on 3G - Work WiFi - Home WIfi never managed to get a channel uri
3- HTC 8X on 3G - Work WiFi - Home WiFi worked great on all 3 networks
4- Lumia 820 same as HTC 8X worked great
Please note that push notifications on other apps are working fine on all 4 devices.
I'd greatly appreciate any feedback/advice for the channel null uri
Below is the code I used, it is the same code as provided by MSDN
public MainPage()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "ToastSampleChannel";
InitializeComponent();
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for toast events.
pushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
pushChannel.ChannelUri.ToString()));
}
}
I have also experienced the same issue. And it got resolved by setting my HTC windows phone with correct date and time.Once I set the date and time automatically, My hybrid application wp8 successfully registered pushplugin and received MPNS Channeluri.
The ChannelUri was null because the new phone I was developing on would not set it's date and time correctly. Once I switched the time to be set manually, then fixed it's time, date and region and then switched it back to auto, everything worked fine such as ssl certificates, windows phone update and most importantly a ChannelUri ;)
Try going into settings > "phone + SIM" and turning off the "Data connection" option this sometimes does the trick?
Have you tried changing the options in settings > data sense? There are options there that restrict background data?
Is battery saver enabled? This limits usage when battery is low etc.
Also as mentioned above, Have you checked the date and time on the device? Maybe it's caused by the auto setting of date and time. You can fix this manually then switch back to auto. It works.
Try using a local wifi connection rather than the cell phone data connection. Disabling the phones "Data connection" as per one of the comments here will achieve this result. Although I tried this and failed it lead me to noticed that my phone was not connected to our wifi router.
NOTE: In my case we have very bad cell coverage so we use a special vodafone router that redirects all our cell phone data, calls, etc thru our fixed line Internet connection. Once I bypassed the that router I received a ChannelUri. I also tried the phone/app at work which uses a different cell tower and that was fine.
I tried setting the date manually but to no effect. What ended up working for me was to actually start the phone without the SIM card, shut down, re-insert SIM and start again. This allowed me to get a ChannelUri again.
Suspect this could be related to the suggestion of TripVoltage who suggests toggling the SIM's data connection.
Related
I'm trying to send GPS-coordinates from an Android device to the Hololens by BLE-advertisments.
The problem as far as i see, the events from BluetoothLEAdvertisementWatcher do not trigger on the Hololens.
I have tried copy-paste both this implementation
and this on the receiver side, no received event.
This is the current implementation in Unity, i have implementated the same functions in a blank UWP-C# project and deployed directly on the Hololens with the same result.
private void StartWatcher()
{
void OnAdvertisementReceived(object sender, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
void OnAdvertisementStop(object sender, BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
try {
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(GetManufacturerData());
watcher.Received += OnAdvertisementReceived;
watcher.Stopped += OnAdvertisementStop;
watcher.Start();
Debeug.Log("Started"); // switched to Write-line on the C#->UWP implementation
} catch (Exception e){
}
}
private BluetoothLEManufacturerData GetManufacturerData()
{
var manufacturerData = new BluetoothLEManufacturerData();
manufacturerData.CompanyId = 0X06EF;
return manufacturerData;
I know the advertisements are sent, becuase if i debug the native UWP-application directly in Visual Studio on the PC(even as ARM64), everything works. The events are triggered.
The watcher.Status reports "started" on the Hololens
Even if i disable the Bluetooth on the HoloLens while the application are running, the stop-event are not either triggered.
If i check watcher.Status after i disable the Bluetooth, the status reports aborted but the Stoped-event are not recieved.
The capability is activated following this article
Now to where it gets wierd.
During one of my first tries i had my application running on the Hololens as i've tried to remove the pairing between the Android device and HoloLens.
The android devices appears as two devices on the Hololens, device name as one and "LE"+MAC as the other.
Sometime during the time i was in the Bluetooth settings and removed the two adapters from the cellphone, the HoloLens recieved three separate advertisments. The data in the advertisments was also confirmed from my Android device becuase during my inital tries i parsed the data.
But thats it, i have tried to replicate this for 10 hours today, Pair and unpair the different adapters in different stages while listening for recieve events but without luck.
On my PC, it do not matter if the adapters are paired or not.
I have tried both .NET Standard 2.0 and .Net 4.x as API Compatibility Level.
I have set breakpoints in both the receive and Stoped event-handler as i was afraid that the calls from the Event-functions was the problem. As far as i see, we never reach the implemented events.
Any suggestion on what might be the next step to check is appreciated.
The Hololens Build is 19041.1144.
Ok, so i can now recevie advertisments on the HoloLens by running the example provedied by Microsoft.
I could not receive any events at all and no updates was available in the settings, so i've reinstalled all applications in the Microsoft Store and that seems to be the solution for me. After that and a restart of the HoloLens i was able to recieve advertisements from my PC.
Another tip for other tip for people trying to recieve advertisements on the HoloLens 2.
When i was able to receive advertismements from my pc i saw that the advertisments from my Android device was not recieved on the HoloLens, but recieved on the PC.
The advertisments on my PC was of type NonConnectableUndirected and from my Android device ScannableUndirected.
I needed to change to "AdvertisingSet" and in the AdvertisingSetParameters set both isConnectable and isScannable to false to be able to send NonConnectableUndirected.
Now the HoloLens recevies the advertisments from my Android device.
I am developing an app in UWP for connecting my Bluetooth earphone device. I am using DeviceWatcher to serve the connection purpose. some few line of code to understand my procedure to connect with my device is as follows -
blDevice = await BluetoothDevice.FromIdAsync(deviceToConnectId);
.
//some other conditions
.
rfcommDeviceServicesResult = await blDevice.GetRfcommServicesForIdAsync(RfcommServiceId.FromUuid(new Guid(serviceUUID)), BluetoothCacheMode.Uncached);
.
//if we get rfcommDeviceServicesResult.Service.Count > 0
.
deviceServices = rfcommDeviceServicesResult.Services[0];
streamSocket = new StreamSocket();
await streamSocket.ConnectAsync(deviceServices.ConnectionHostName, deviceServices.ConnectionServiceName);
dataWriter = new DataWriter(streamSocket.OutputStream);
dataReader = new DataReader(streamSocket.InputStream);
I have similar app for Android already. both Android app and UWP app were connected with the same device previously. now, I launched Android app and connected my earphone with the app. Launched UWP app too. as the earphone is connected with Android app, its showing disconnected state in UWP app with a "Connect Again" button. I clicked on the button to test the connection. Here is what happened -
1. Disconnected from Android App
2. Starting to connect with UWP App
3. Windows BT Settings jumped from "Paired" to "Connected"
4. Data receiving was complete
5. After some seconds Windows BT Settings jumped from "Connected" to "Paired" automatically
in my UWP app I am using deviceWatcher to handle my connection module. DeviceWatcher.Update event is fired when this happens. I implemented auto reconnection with the help of DeviceWatcher.Update. and (bool)deviceInfoUpdate.Properties["System.Devices.Aep.IsConnected"]becomes false, resulting instant disconnection
And as it seems there are three states in windows BT settings for my earphone. Paired, Connected, Connected music, audio. If windows BT settings is not showing Connected music, audio then I can't listen to music/sound via my earphone.
My questions are -
Why are there three states?
Why did Windows BT Settings jumped from "Connected" to "Paired" automatically? is this Windows OS limitation? is there any easy way to fix this?
NB: Its not a device side issue. I tested the other way around. from UWP to Android. but this issue didn't occur
I'm developing Xamarin application using Visual Studio 2019. I have to connect to another device through Bluetooth and send some data and receive acknowledgement back. Tried these two samples out
https://github.com/msthrax/BLEApp
and
https://github.com/didourebai/BLEPluginDemo.
But didn't help me while scanning for nearby Bluetooth devices, since the below codes are not giving expected result respectively..
1.
listView_DeviceList.ItemsSource = CrossBluetooth.Adaptor.GetListOfDiscoveredDevices();
and
2.
adapter.DeviceDiscovered += (s, a) =>
{
deviceList.Add(a.Device);
};
Both Bluetooth and location turned on in my devices. Can anyone let me know the possibilities of problem here. I don't have any build errors in both of the above samples. Whereas, I have one surprise also. Below line is giving proper result, which is of no use for me currently.
listView_PairedDeviceList.ItemsSource = CrossBluetooth.Adaptor.GetPairedDevices();
After enabling the Location Permission for the app(earlier, I turned on Device Location, but we should allow the app to get device location), all my above problems are solved out.
I am using this code-->https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cson "Blue Gecko bgm13p22" microcontroller BLE device to read its services and characterstics. If I use "BluetoothCacheMode.Uncached" mode it says "Device Unreachable" but when I use "BluetoothCacheMode.Cached" mode it shows already stored characterstics or services, but not in real time.
Why is this happening?
Please help
Thanks
You say "already stored characteristics or services", so I presume you have successfully read them at least once. They have been saved in the Bluetooth Cache.
In your instance, using BluetoothCacheMode.Cached doesn't connect to the device to look for characteristics - it looks in the Bluetooth cache, that's why it doesn't show them "real time". Using BluetoothCacheMode.Uncached attempts a connection and it fails.
With "Device Unreachable" as a response, the first thing to try is to refresh the device object.
BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceId);
.....
I'm new to windows phone development and have started working with push notifications within the emulator in visual studio 2012. We are having a strange problem where we have two apps in visual studio and when we start each one and call the following:
CurrentChannel = HttpNotificationChannel.Find("ChannelName");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("ChannelName");
CurrentChannel.Open();
CurrentChannel.BindToShellTile();
CurrentChannel.BindToShellToast();
}
Even though the ChannelName is different in each app the CurrentChannel.ChannelUri is the same so when we send push notifications they only go to one app.
I am sure we are missing something very obvious or misunderstanding the way this is supposed to work but any insight would be appreciated.
I supposed you didn't get the right Uri according to your piece of codes. Try to Listen on ChannelUriUpdated event to get a fresh Uri.
If you did, maybe try it on a real device, emulator is not always to be trusted enough.
And Push notification channel URi is unique for device & app combination, to be sure you made something different in these two apps. Anyway seems this couldn't be happened.