Using PowerStatus class in windows phone 7 app - c#

I am new to windows phone app development.
I am trying to use the powerStatus class in a windows phone 7 app. I have searched quite a bit regarding that and learnt that it is necessary to add reference of System.Windows.Forms
But in the add reference of the project 'System.Windows.Forms' is not present.
How can I use the powerStatus class?
Please help.
Thank you.

Please Refer this msdn link that will clearly shows that how can you get the status of the Battery. i.e. The remaining Percentage of charge in phone;s battery.
Know the battery status in windows phone
In this link, use the RemainingChargePercent() Method this will return the value that indicates the percentage of the charge remaining on the phone's battery.
This things will used in windows phone 8 only.
But, you are with windows phone 7. so, currently there is no API available for windows phone 7 to know the remaining charge in phone's battery.
You will get the information like the if your phone is connected to power source or running in battery.
I will show here some important msdn question links that shows that there is no method or the class is available to get the charge level in windows phone 7.
The MSDN Question link: how to get the battery status in windows phone 7.
if you have the need to show the battery charge percentage, then i suggest you to proceed with windows phone 8.

It work for wp8. but I am not sure about wp7.
_battery = Battery.GetDefault();
var remainingCharge = string.Format("{0} %", _battery.RemainingChargePercent);
var remainingTime = _battery.RemainingDischargeTime.TotalMinutes;
_battery.RemainingChargePercentChanged += OnRemainingChargePercentChanged;
private void OnRemainingChargePercentChanged(object sender, object e)
{
var remainingCharge = string.Format("{0} %", _battery.RemainingChargePercent);
var remainingTime = _battery.RemainingDischargeTime.TotalMinutes;
if(Microsoft.Phone.Info.DeviceStatus.PowerSource == Microsoft.Phone.Info.PowerSource.External)
var text = "Charger Connected";
else
var text = "Charger Not Connected";
}

Related

multitouch doesn't work on windows phone 8.1 device

I've got real device Nokia Lumia 730 (windows phone 8.1) for testing my game cocos2d-x. And I've discovered multitouch doesn't work.
First of all sample code:
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = [&](std::vector touches, Event* event){
log("onTouchesBegan: %d", touches.size());
}
listener->onTouchesMoved = [&](std::vector touches, Event* event){
log("onTouchesMoved: %d", touches.size());
}
listener->onTouchesEnded = [&](std::vector touches, Event* event){
log("onTouchesEnded: %d", touches.size());
}
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
No matter how many fingers I'm touching it always says 1.
I ran the same app on Android (samsung galaxy s3) and it's working well.
As I found out there's no need/no way to enable multitouch on windows phone and it's already enabled by default.
Second, I made simple test inside my win8.1-xaml project (didn't test win8.1-universal, can't use it anyway, because of lacking 3rd party libs support like admob):
Touch.FrameReported += Touch_FrameReported;
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
if (Visibility == Visibility.Collapsed)
return;
TouchPointCollection pointCollection = e.GetTouchPoints(this);
Debug.WriteLine("points touched: " + pointCollection.Count);
}
And this actually works and prints correct values.
So running these 2 pieces of code at the same time produces for example this:
onTouchesBegan: 1 <-- cocos2d-x part
points touched: 2 <-- c# project part
Cocos thinks there's only one touch, however wp knows there's more (2).
Help!

Windows phone 8.1 Geo Location does not work unless the phone resides in the geo-location for atleast 2 to 3 seconds

I am creating a windows Phone 8.1 application with the Geo Location. The code works, well pretty much, the one thing that I have noticed in the simulator, if the phone does not reside in the Geo-Fenced area for a 2 .. 3 .. seconds the background code does not fire even though I create my dwell time with no parameters.
MonitoredGeofenceStates mask = 0;
mask |= MonitoredGeofenceStates.Entered;
var geocircle = new Geocircle(position, 100);
gFence = new Geofence(ID, geocircle, mask, false);
I found the following blog but it was not that useful
http://blogs.windows.com/buildingapps/2014/02/25/testing-and-debugging-your-geofencing-apps/
How often does a phone or device check if its in a Geo fenced area? I would like to tell my users for their geo-fence to be active they must reside in the geo-fenced area for a minimum of x seconds...

Show Viber, Whatsup in Windows Phone 8.1 share contract

Hi I am developing an app that shares a picture in via Share contract in Windows Phone 8.1. My code is
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
and
private async void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
request.Data.Properties.Title = "Unscramble this";
request.Data.Properties.Description = "";
request.Data.SetText(string.Format("Scrambled word is {0} and clue is {1}. Help me to unscramble this \r\n(via Unscramble Plus for Windows Phone)",scrambledString.ToUpper(),selectedMeanings.ToUpper()));
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
//StorageFile logoFile = await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
StorageFile imagefile = await KnownFolders.PicturesLibrary.GetFileAsync("pic.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(imagefile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
where this show the share contract as below (including only Facebook, Mail apps)
But if you see in Sendtiment app for Windows Phone (http://www.windowsphone.com/en-us/store/app/sendtiment-cards/9c389cc5-5c00-4f8e-8bd4-e6fbb5040c24) it shows many apps like Viber, Whatsapp, Twitter.
How to get these Viber, Whatsapp like apps in my app's share contract?
Edit: (Addition) When I remove
request.Data.SetText(string.Format("Scrambled word is {0} and clue is {1}. \r\n(via Unscramble Plus for Windows Phone)",scrambledString.ToUpper(),selectedMeanings.ToUpper())); line, this shows OneDrive.
http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1/10
this might help, also make sure what kind of data you are sharing, as the app will show only if the Content type matches,
for example whatsapp will show only if you are sharing Video,Images but NOT phone contact.
if you use a Universal-App, Whatsapp will not shown. WhatsApp is a WP8.1 Silverlight-App.
This is the Problem!

Distinguishing between phone and tablet browsers

I know this question as been beaten to death, but I don't want anything super complicated here.
We have a companion app with our site that is only compatible with 7 and 10-inch tablets. We need to only alert users on those devices about our app. Problem is, I can't go by resolution. My Galaxy S3 has a 1280 x 720 screen, but is obviously not a tablet. I also can't for the life of me find out a way to get the physical size of the screen. The only solution I have come up with is detecting whether the device can make calls with MobileCapabilities.CanInitiateVoiceCall. Unfortuantely, by boss isn't happy with that solution.
So... How can I distinguish between a phone and a tablet in my web app (Server or client side)?
UPDATE: So far it seems that the best approach for Android is something from a blog post by the Android team: All Android phones use "Mobile" in the UserAgent string, so checking for "Mobile" *and "Android" will tell you if it's a phone, while just "Android" should be a tablet. iOS devices should be just as simple--checking for "iPhone" vs "iPad" seems to have worked so far.
I know this is a little late, but I was looking for the same thing.
Wurfl has wat you want. You can implement it easily and and even have an api you can query.
For ASP.NET application first you must place the one-off initialization.
public class Global : HttpApplication
{
public const String WurflDataFilePath = "~/App_Data/wurfl.zip";
private void Application_Start(Object sender, EventArgs e)
{
var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
var configurer = new InMemoryConfigurer().MainFile(wurflDataFile);
var manager = WURFLManagerBuilder.Build(configurer);
HttpContext.Current.Cache[WurflManagerCacheKey] = manager;
}
}
And then use it like this.
var device = WURFLManagerBuilder.Instance.GetDeviceForRequest(userAgent);
var isTablet = device.GetCapability("is_tablet");
var isSmartphone = device.GetCapability("is_smartphone");
For more info check ASP.NET implementation
Hope this helps anyone else looking for this.
You can try to do a user agent detection and search for the keywrords, for example, all Non tablet devices have a "Mobile Safari" key words on their user agent.

Open Locations Toggle in Windows Phone 7

I like to know how to open location toogle in c#, for example for wifi i use this:
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
I like a stuff like that but for location.
Though, in Windows Phone 8, this can be done using
Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-location:"))
There is no task to do this for you - each app that uses the location sensors is expected to have this setting in their own settings page.

Categories