Skip to content

Instantly share code, notes, and snippets.

@agrocholski
agrocholski / hub-send-to-android-tags.cs
Last active August 29, 2015 13:56
Use Windows Azure Notification Hubs to send a message to targeted Android devices via GCM using tags
public static async Task<NotificationOutcome> SendToAndroid(string hubName, string hubConnectionString, string message, string tags)
{
//create a list of tags from a comma delimited string
var tagList = new List<string>();
if(tags.Contains(","))
{
var split = tags.Split(new char[] { ',' });
foreach(var item in split)
@agrocholski
agrocholski / hub-send-to-android.cs
Last active August 29, 2015 13:56
Use Windows Azure Notification Hubs to send a message to an Android devices via GCM
public static async Task<NotificationOutcome> SendToAndroid(string hubName, string hubConnectionString, string message)
{
//instantiate the notification hub
var hub = NotificationHubClient.CreateClientFromConnectionString(hubConnectionString, hubName);
//create the json payload
var json = new StringBuilder(); //string.Format("{ \"data\" : {\"msg\":\"{0}\"}}", message);
json.Append("{ \"data\" : {\"msg\":\"");
json.Append(message);
json.Append("\"}}");
@agrocholski
agrocholski / NetworkConnectionManager.vb
Created June 12, 2013 19:19
Shows how to get the current network connection status and subscribe to network status changed events.
Public Class NetworkConnectionManager
'ctor
Public Sub New()
'add a handler to pick up when network connectivity has changed
AddHandler Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged, AddressOf OnNetworkStatusChanged
'get the current connection status
GetConnectionStatus()
@Override
public void onCreate(Bundle savedInstanceState) {
...
getActionBar().setDisplayHomeAsUpEnabled(true);
...
}
@agrocholski
agrocholski / App.xaml.cs
Created February 21, 2013 16:27
MainPage wire up for default blank Windows Store app
//code ommitted for brevity
//...
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
//...
//code ommitted for brevity
@agrocholski
agrocholski / DefaultActivity.xml
Created February 21, 2013 16:23
Default activity wire up for Android
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
private void Load()
{
object meteredConnectionPrompt = this.GetRoamingValue("meteredConnectionPrompt");
if (meteredConnectionPrompt != null)
this.MeteredConnectionPrompt = (bool)meteredConnectionPrompt;
else
this.MeteredConnectionPrompt = true;
}
@agrocholski
agrocholski / MediaControlSoundLevelChanged.cs
Last active December 13, 2015 17:19
Handles the SoundLevelChanged event of the MediaControl class
MediaControl.SoundLevelChanged += MediaControl_SoundLevelChanged;
private void MediaControl_SoundLevelChanged(object sender, object e)
{
if ((MediaControl.SoundLevel == SoundLevel.Muted || MediaControl.SoundLevel == SoundLevel.Low) && MediaControl.IsPlaying)
{
this.mediaElement.Pause();
_isPlaying = false;
MediaControl.IsPlaying = false;
}
@agrocholski
agrocholski / MediaControlPlayPauseTogglePressed.cs
Last active December 13, 2015 17:19
Handle the PlayPauseTogglePressed event of the MediaControl class.
MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
private void MediaControl_PlayPauseTogglePressed(object sender, object e)
{
if (_isPlaying)
{
this.mediaElement.Pause();
_isPlaying = false;
MediaControl.IsPlaying = false;
}
@agrocholski
agrocholski / MediaControlPausePressed.cs
Last active December 13, 2015 17:18
Handle the PausePressed event of the MediaControl class.
MediaControl.PausePressed += MediaControl_PausePressed;
private void MediaControl_PausePressed(object sender, object e)
{
this.mediaElement.Pause();
_isPlaying = false;
MediaControl.IsPlaying = false;
}