Display Camera output in Windows Phone 7 - windows-phone-7

I'm writing an augmented reality app for Windows Phone 7 as a school project. I want to get the camera output and then add a layer of data over it. Is there a way to have the camera output displayed in a panel?

FYI: In Windows Phone SDK 7.1 (a.k.a. "Mango") you can now write apps that use the device camera as you describe. See App Hub for a link to the latest 7.1 development tools. The documentation describes how to do this at the following link:
How to: Create a Base Camera Application for Windows Phone
But basically, add a videobrush to display the camera feed (a.k.a. the "viewfinder"). For example, here a rectangle control is used display the camera viewfinder:
<!--Camera viewfinder >-->
<Rectangle Width="640" Height="480"
HorizontalAlignment="Left"
x:Name="viewfinderContainer">
<Rectangle.Fill>
<VideoBrush x:Name="viewfinderBrush" />
</Rectangle.Fill>
</Rectangle>
To use the camera in the code-behind for the page, add a reference to Microsoft.XNA.Framework and put the following Using statements at top of the page:
// Directives
using Microsoft.Devices;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media;
Note: you may not need all of these, I just copied it from the docs. In Visual Studio (Pro, at least), you can clean them up after you're done by right-clicking your code file and clicking: Organize Usings | Remove Unused Usings.
Then, basically you apply the camera image to the rectangle in the OnNavigatedTo handler...
//Code for initialization and setting the source for the viewfinder
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Initialize camera
cam = new Microsoft.Devices.PhotoCamera();
//Set the VideoBrush source to the camera.
viewfinderBrush.SetSource(cam);
}
...and dispose of the camera object in the OnNavigatingFrom.
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
// Dispose camera to minimize power consumption and to expedite shutdown.
cam.Dispose();
// Good place to unhook camera event handlers too.
}
The 7.1 docs also describe an augmented reality app in the following topic. Note that you'll need to scroll-down to the section titled Creating a Silverlight-based Augmented Reality Application, to find the instructions for building it with Mango.
How to: Use the Combined Motion API for Windows Phone
Hope that also helps others seeking information about PhotoCamera in Windows Phone OS 7.1.
Cheers

According to Microsoft's UI Design and Interaction Guide [PDF], They do not allow developers to access the camera with any UI Elements.
This comes from page 127:
There are no direct UI elements
associated with the Camera, but
developers have access to the Camera
in the Microsoft.Phone.Tasks
namespace.

As of today (1/19/2010) you only officially have access to photos taken using the CameraCaptureTask. If you do not plan to submit your application to the marketplace then you can use the PhotoCamera class from the Microsoft.Phone.Media.Extended namespace as outlined by Dan Ardelean and Kevin Marshall. See this post for a video demo and his blog for more details. Please note that your application will not pass marketplace certification if you use these assemblies as they are not part of the official SDK.

The short answer to your question is: no.
You can capture photos using the CameraCaptureTask provided by the Windows Phone 7 API (here), but, to the best of my knowledge, you cannot capture a live stream of data from the camera.
Microsoft has not announced whether this functionality will be augmented in a future release of the platform.
Example of using CameraCaptureTask:
public partial class MainPage : PhoneApplicationPage
{
// Declare the CameraCaptureTask object with page scope.
CameraCaptureTask cameraCaptureTask;
// Constructor
public MainPage()
{
InitializeComponent();
// Initialize the CameraCaptureTask and assign the Completed handler in the page constructor.
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
}
// In this example, the CameraCaptureTask is shown in response to a button click.
private void button1_Click(object sender, RoutedEventArgs e)
{
cameraCaptureTask.Show();
}
// The Completed event handler. In this example, a new BitmapImage is created and
// the source is set to the result stream from the CameraCaptureTask
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;
}
}
}

As noted here, we're limited to CameraCaptureTask Functionality for the moment.
Information has been released recently to indicate functionality to support AR is on the roadmap.

Related

Load startup model in platform project code and pass it to PCL on Xamarin Forms Initialization

The application I'm currently working on requires data to be retrieved from a web service during app startup that roughly takes 1.5 seconds. After the data is retrieved, it needs to be displayed on the MainPage and that is another 1.5 - 2 seconds since the data is mostly URLs of images that have to be displayed, in my case, using ffimageloading library; which means actually downloading those images first to be displayed.
I have splash startup screens for both Android and iOS implemented separately in platform projects but splash screen only stays up for the amount of time Xamarin Forms needs to load and afterwards disappears not waiting for my actual model to load from the web service. I have searched for solutions to extend the splash screen duration and mostly every solution I have read involves creating another splash screen page, loading page if you will, that is already controlled in PCL project but having two separate splash loading screens just seams not feasible to me at the moment.
So I was wondering, how would one load the initial model in platform projects, during the actual splash screen, and then later pass it to PCL project when Xamarin Forms has finished initialization, presumably to App.xaml.cs 's App() constructor function?
There is no code or enough details so I am assuming this is what you want to do.
Call the APIs asynchrnously , till then show splash screen.
Before assigning MainPage in your App.xaml.cs you should call these APIs asynchronously with await and then you use the same for binding of your mainpage
public App()
{
InitializeComponent();
//do all my prefetch stuff for app initialization.
// API and what not
var viewmodel = new AppMainViewModel();
await viewmodel.CallFooFetchAsync();
await viewmodel.BlahBlahAsync();
MainPage = new NavigationPage(new AppMainPage(viewmodel));
}
In Page
public AppMainPage(AppMainViewModel vm)
{
BindingContext =vm;
}
So by the time page loads it has all the data handy.
You can explore adding this code in OnAppearing of the page.
Note that the concept of default Splash screen is just to show an image(with different theme in Android) and setting image in iOS. You need to have conventional UI technically its not splash screen anymore.
Alternatively you can get shared project handle in native
Android Sp
protected override void OnCreate(Bundle bundle)
{
...
var app = new App(); //this will be shared project App object
Device.BeginInvokeOnMainThread(async () => await app.DoPrefetchStuffFirst()); //API calls if needed in this async method
//then
LoadApplicationm(app)
}
You can do similar thing in iOS AppDelegate
And if you call native specific methods in platforms (may be for API calls) then you would use DependencyService feature , that will pass it to shared project or Custom renderer based on where you want to use it.

Push Notification to specific devices on xamarin forms android/ios

I have successfully set up push notification using firebase and linked it up Azure notification hub using this guide from the Microsoft docs:
https://learn.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-push-notifications-android-gcm
However I am now trying to push notification to specific devices using tags. There isn't currently a xamarin c# document. I have done some research around the area and found people solving what seems to be the same problem using dependency injection (which feels a little complex?). I have also found these two questions/answers:
How to push notification to specific users in Xamarin.Forms Android?
https://forums.xamarin.com/discussion/85935/how-to-push-notification-to-specific-users-in-xamarin-forms-android
Both of which point to the method "OnRegistered" which i don't seem to have? i've had another look through the documentation I followed to set up notifications in the first place and I seem to have followed it correctly?
I have the following code for android:
private void SendRegistrationToServer(string token)
{
// Register with Notification Hubs
hub = new NotificationHub(ApplicationConstants.NotificationHubName,
ApplicationConstants.ListenConnectionString, this);
var tags = new List<string>() { };
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
}
I can obviously set the tags manually there, however how do i 'call' this Method again if the tags need to be changed?
So bottom line, my question is how do i set up push notification to specific devices on xamarin.forms android/ios?
Thanks.

Xamarin Forms - How to open specific page after clicking on notification when the app is closed?

I'm actually working on a Xamarin Forms application that need push notifications. I use the Plugin.PushNotification plugin.
When the app is running in the foreground or is sleeping (OnSleep), I have no problem to open a specific page when I click on a notification that I receive. But I was wondering how can I do that when the app is closed. Thanks!
I finally found the answer by myself and I want to share it in case someone needs it.
Nota bene: according to the official documentation of the plugin, it's Xam.Plugin.PushNotification that is deprecated. I use the new version of this plugin, Plugin.PushNotification which uses FCM for Android and APS for iOS.
There is no significant differences to open a notif when the app is running, is sleeping or is closed. Just add the next callback method in the OnCreate method (MyProject.Droid > MainApplication > OnCreate) and FinishedLaunching method (MyProject.iOS > AppDelegate > FinishedLaunching):
CrossPushNotification.Current.OnNotificationOpened += (s, p) =>
{
// manage your notification here with p.Data
App.NotifManager.ManageNotif(p.Data);
};
Common part
App.xaml.cs
// Static fields
// *************************************
public static NotifManager NotifManager;
// Constructor
// *************************************
public App()
{
...
NotifManager = new NotifManager();
...
}
NotifManager.cs
public class NotifManager
{
// Methods
// *************************************
public void ManageNotif(IDictionary<string, object> data)
{
// 1) switch between the different data[key] you have in your project and parse the data you need
// 2) pass data to the view with a MessagingCenter or an event
}
}
Unfortunately there is no succinct answer for either platform. Generally speaking, you need to tell the OS what to do when it starts the app as a result of the push notification. On both platforms, you should also consider what API level you are targeting, otherwise it won't work or even crash the app.
On iOS, you will need to implement this method in AppDelegate appropriately: FinishedLaunching(UIApplication application, NSDictionary launchOptions). The launchOptions will have the payload from the push notification for you to determine what to do with it (e.g. what page to open). For more information on iOS, Xamarin's documentation is a good place to start.
Android has a more complicated topology in terms of more drastic differences between API levels, whether you are using GCM/FCM, as well as requiring more code components. However, to answer the question directly, you will need to handle this in OnCreate(Bundle savedInstanceState) of your main Activity. If you are using Firebase, the push notification payload is available in Intent.Extras. Again, Xamarin's documentation has a good walkthrough.
Finally, note that the Plugin.PushNotification library you are using has been deprecated. I suggest you either change your library and/or your implementation soon. Part of the reason that library has been deprecated is because Google has deprecated the underlying Google Cloud Messaging (GCM) service, which will be decommissioned on April 11, 2019.

Getting AppID for Windows Phone in Unity3d

I am developing game for windows phone in unity3d, I have inserted Rate me button in game but on run time in windows phone it didn't work, is there any method to access AppID for the current application running in windows phone developed in Unity3d. I need code in unity3d CSharp for getting AppID.
I tried this C# code in Unity but It didn't work and having error no keywork found windows.
string appId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
LinkUri = new Uri("http://www.windowsphone.com/s?appid=" + appId, UriKind.Absolute)
Here I needed AppID to complete my link for rate me.
As far as i know Unity can not access the Windows namespace but you can make use of EventHandler to call 'Review Task' from Unity. You can do this by following below steps(visit Unity Expert for detailed explanation).
In Unity Game Engine-
Create Event -
using UnityEngine;
using System;
public static class events
{
//Create a new event
public static event EventHandler RateUs;
public static void FireRateUs()
{
Debug.Log ("Opening Rate Task......");
//If event is subscribed than fire it
if(RateUs!=null)
RateUs(null,null);
}
}
Fire Event -
using UnityEngine;
public class RateUs : MonoBehaviour
{
void OnMouseDown()
{
events.FireRateUs();
}
}
In Visual Studio IDE
Subscribe Event -
public MainPage()
{
.
.
.
.
events.RateUs += events_RateUs;
}
Call Function -
void events_RateUs(object sender, EventArgs e)
{
String AppId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + AppId));
}
You have to get your AppID from your developer's portal on Microsoft Create's web page. You can then hardcode it into your app or save it as a static/globally available variable for accessing purposes. This would mean you would have to begin the process of creating your app entry prior to the programming of the rating game feature. Just create the entry, and don't submit it! Or create it, and add Rate app as an update. I'd choose the former method, personally!
For Apple and Google rating/submit information you have to create the entry ahead of time to get a SKU number. Also in iTunes/Apple/iOS/OSX you have to create the app and give it a unique name, etc in the developer's portal/certificate store.

Accessing phone gallery and camera

How to access Phone gallery and camera in windows phone7 through code
there are Launchers and Choosers which allow you to call these options and they also allow you to call other things such as map,sms compose,search etc.
here is an example of one (camera)
Creating Object
CameraCaptureTask cvt = new CameraCaptureTask();
Registering event
cvt.Completed += new EventHandler<PhotoResult>(cv_Completed);
cvt.Show();
Creating callback method
private void cv_Completed(object sender, PhotoResult r)
{//Your Code Here
}
also read here - MSDN- Launchers and Choosers
You want to see many good samples in the good Nokia Developer Windows Phone Website. They're good tutoriel with many samples.

Resources