Related
A simple photochooser task application throws a Nullrefference exception(Invalid pointer) and pixel height and width is 0 on mango, on nodo it worked alright.
Am I missing a cast? or this is a bug in mango, and will be fixed?
Here's the code:
Code:
private PhotoChooserTask photo;
// Constructor
public MainPage()
{
InitializeComponent();
photo = new PhotoChooserTask();
photo.Completed += new EventHandler<PhotoResult>(photo_Completed);
}
void photo_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.ChosenPhoto);
//////////////////////////////////////////////////////////////////////////////////////
var wb = new WriteableBitmap(bi);//Exception here
/////////////////////////////////////////////////////////////////////////////////////
// bi.PixelHeight and bi.PixelWidth == 0;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
photo.Show();
}
}
Hope someone can help.
Thanks in advance
This is because you need to set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap.
The default 'create' option on WP7 is DelayCreation (it may be BackgroundCreation in some of the 7.1 betas, but the mango RTM I think is DelayCreation) but either way the problem you're having is that your image has not been initialised yet at the point you use it in the WriteableBitmap's constructor (hence the null reference exception).
The options (depending what you set) let images be only initialised when needed, and downloaded on separate threads / asynchronously, which can help performance (or at least stop the phone blocking other things happening whilst images are loaded). Users also have the ability with the photo chooser to pick images from online ablums, so as you can imagine you also have to handle perhaps a second or two waiting for a download to complete, and of course downloads can also fail when connections drop etc. which you can handle too.
So in answer to your question (off the top of my head, not confirmed it with code) set the createoptions to none, and use the Bitmap's ImageOpened event to construct the WritableBitmap (you may also want to handle the Bitmap's ImageFailed event). Make sure you set up the ImageOpened event before you set the source, i.e.
BitmapImage bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
bi.ImageOpened += new (some event name)
bi.ImageFailed += new (some event name)
bi.SetSource(e.ChosenPhoto);
Hope that helps,
Ian
Thank you very much
Problem solved
otherworld said:
This is because you need to set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap.
The default 'create' option on WP7 is DelayCreation (it may be BackgroundCreation in some of the 7.1 betas, but the mango RTM I think is DelayCreation) but either way the problem you're having is that your image has not been initialised yet at the point you use it in the WriteableBitmap's constructor (hence the null reference exception).
The options (depending what you set) let images be only initialised when needed, and downloaded on separate threads / asynchronously, which can help performance (or at least stop the phone blocking other things happening whilst images are loaded). Users also have the ability with the photo chooser to pick images from online ablums, so as you can imagine you also have to handle perhaps a second or two waiting for a download to complete, and of course downloads can also fail when connections drop etc. which you can handle too.
So in answer to your question (off the top of my head, not confirmed it with code) set the createoptions to none, and use the Bitmap's ImageOpened event to construct the WritableBitmap (you may also want to handle the Bitmap's ImageFailed event). Make sure you set up the ImageOpened event before you set the source, i.e.
BitmapImage bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
bi.ImageOpened += new (some event name)
bi.ImageFailed += new (some event name)
bi.SetSource(e.ChosenPhoto);
Hope that helps,
Ian
Click to expand...
Click to collapse
Hello, I have the same problem (NullReferenceException) and have read you response, which from what I see it is the solution, but I have a problem; not where I have to go to do I change them that you propose. I would be so kind of explaining to me that I have to continue steps. It English me is very bad and I am using a translator.
I have HTC Trophy the v.th 7740.16 with chevrom and U2M7740 of Ansar.
Thank you in advance and greetings.
Hi,
If you upload your code / project I will take a look and see where the error is.
Si me muestras su código / proyecto, puedo ver por qué recibiras una excepción NullReference
Ian
otherworld said:
Hi,
If you upload your code / project I will take a look and see where the error is.
Si me muestras su código / proyecto, puedo ver por qué recibiras una excepción NullReference
Ian
Click to expand...
Click to collapse
Hello,
The question is that it is not any project, applications do not develop (although I would like). This type of errorr (nullreferenceexception) happens to me since I updated to Mango, so much in v.7720.68 as in v.7740.16 and happens in apps as Morfo, Fantasy Painter, and at the time of choosing fund in Touchxperience. Not if these apps are not conditioned to Mango or if, perhaps, from the record it might change some type of configuration or entering the Xaml of the app to be able to change some fact, end not...
For the little that, an error of the photochooser seems to be, the question is if it is possible to gain access to him and as doing it.
Anyhow thank you very much and a cordial greeting.
Hi,
If it is not a code issue then I do not know what it could be. Are you using a custom rom?
Good luck with it.
Ian
otherworld said:
Hi,
If it is not a code issue then I do not know what it could be. Are you using a custom rom?
Good luck with it.
Ian
Click to expand...
Click to collapse
Hello. Not, I am with official Mango the v.th 7740.16. I have already restored to factory and it continues the error. I believe that it is a question of the update, it must have a mistake in the pitcher of photos or some error with the librerie, do not know...
Thank you anyhow and greetings.
Hello, otherworld.
I continue with the same problem, 'nullreferenceexception' related with 'chooserphoto' in some application. The curious thing is that someone of them me work correctly, I gain access to me librery and it takes the photos, and in others not, as for example Morfo. I do not know if the problem is in the code source of these applications or phone is in me. Is this the code source of Morfo, is it possible to correct so that this does not happen?
Thank you in advance and greetings.
Device Reset
powered by fiinix's DllImport Project
description
--- restart or shutdown device
recognition
--- XDA Portal
pre-installed
--- Rataplan ROM
release log
--- Device Reset v3.0.0.0
------ see Post #31 or click here
--- Device Reset v2.0.1.0
------ see Post #25 or click here
--- Device Reset v2.0.0.0
------ see Post #16 or click here
--- Device Reset v1.2.0.0
------ see Post #15 or click here
--- Device Reset v1.1.0.0
------ see Post #14 or click here
does soft reset wipe the device?
soft reset restarts back your phone.
power will shutdown your phone thoroughly(no need to press the power switch button)
Nice app, THX (+)
Thanks sh4d0w86!!
congratulations for first wp7 development!!
will keep my power button intact much longer! that was needed
I'm sure hard-reset is a good idea, but if a bad manip occurs it can be upsetting...or with a flashy red background color for warning purpose...
would it be possible to have all restart options? i mean one which start with the tricolors screen, another for usb update (the one used to load goldcarded .nbh)...?
NebZoNe said:
I'm sure hard-reset is a good idea, but if a bad manip occurs it can be upsetting...or with a flashy red background color for warning purpose...
Click to expand...
Click to collapse
+1 !!!
Just a small notification to confirm Hard-Reset please ...
Thankx for developpement
will it be possible to have a sleep button as a tile?
if possible pinnable tiles on the homescreen...
Magpir said:
does soft reset wipe the device?
Click to expand...
Click to collapse
soft reset = restart, reboot
hard reset = [factory] restore
Ttblondey said:
soft reset restarts back your phone.
power will shutdown your phone thoroughly(no need to press the power switch button)
Click to expand...
Click to collapse
exactly.
NebZoNe said:
Thanks sh4d0w86!!
congratulations for first wp7 development!!
will keep my power button intact much longer! that was needed
I'm sure hard-reset is a good idea, but if a bad manip occurs it can be upsetting...or with a flashy red background color for warning purpose...
would it be possible to have all restart options? i mean one which start with the tricolors screen, another for usb update (the one used to load goldcarded .nbh)...?
Click to expand...
Click to collapse
thanks, NebZoNe.
those were my thoughts exactly when wanting to build this app.
i will, of course, have notification pop up to execute a hard reset.
actually, that is the main reason it isn't implemented in first release...
unsure how to exactly do that, yet.
that is an awesome idea. will look into it.
poloche said:
+1 !!!
Just a small notification to confirm Hard-Reset please ...
Thankx for developpement
Click to expand...
Click to collapse
already on my to-do list.
glad you like the app.
Magpir said:
will it be possible to have a sleep button as a tile?
if possible pinnable tiles on the homescreen...
Click to expand...
Click to collapse
already on my to-do list.
unsure how to do, though, yet, which is why it wasn't already included.
sh4d0w86 said:
already on my to-do list.
unsure how to do, though, yet, which is why it wasn't already included.
Click to expand...
Click to collapse
put this in your MainPage.xaml.cs
could work
Code:
private string tag;
//If the app navigates to the MainPage.Xaml this function tries to read a a tag-property from the Uri.
//You use the Uri to navigate between pages by calling the NavigationServices.Navigate(new Uri("/MainPage.xaml",UriKind.Relative)).
//To push a parameter to the site you can add them to the uri as following:
//"/MainPage.xaml?tag=tagnvalue&otherproperty=othervalue"
//If you launch the app these settings are empty
//If you launch it with the pinned tile you can set this Uri to submit the parameters
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
//get the value.
NavigationContext.QueryString.TryGetValue("tag", out tag);
//restart, shutdown... depending on the tagvalue. if tag is empty nothing happens (you can add a case default: "your code" break; to perform a default action)
switch(tag)
{
case "soft":
softreset(); //your void to perform the softreset
break;
case "hard":
hardreset();
break;
case "shotdown"
shotdown();
break;
}
}
//the functions performing the different restart modes
private void softreset()
{
}
private void hardreset()
{
}
private void shutdown()
{
}
//this action creates a softreset tile by calling PinToStart("soft");
private void PinToStart(string tag)
{
string title = "";
//set the title of the tile
switch (tag)
{
case "soft":
title = "soft reset";
break;
case "hard":
title = "hard reset";
break;
case "shotdown"
title = "shutdown";
break;
}
//search the tile with the title given by the tag in the step before
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=" + tag));
//if it's not existing this creates a new one
if (TileToFind == null)
{
//the data for the tile
StandardTileData NewTileData = new StandardTileData
{
//you can create different images for the tiles called "softTile.jpg", "hardTile.jpg", etc. in you "Images" folder
BackgroundImage = new Uri("Images/" + tag + "Tile.jpg", UriKind.Relative),
Title = title,
//Count = 12,
//BackTitle = "",
//BackContent = "",
//BackBackgroundImage = new Uri("Blue.jpg", UriKind.Relative)
};
//create a new tile with the tiledata
ShellTile.Create(new Uri("/MainPage.xaml?tag=" + tag, UriKind.Relative), NewTileData);
}
Does anyone notice/try change background to white while accent color to blueberry and when you open the Device Reset you can't see anything. Is it a bug?
ne0cr0n said:
put this in your MainPage.xaml.cs
could work
Click to expand...
Click to collapse
thanks for that bit of code. unfortunately... i have no idea what it does exactly. :/
Ttblondey said:
Does anyone notice/try change background to white while accent color to blueberry and when you open the Device Reset you can't see anything. Is it a bug?
Click to expand...
Click to collapse
not a bug, an overlook on my part. everything still there and works, it is just white font on white background. fixed for next release. good catch. next release, app will match Theme & Accent choice.
sh4d0w86 said:
thanks for that bit of code. unfortunately... i have no idea what it does exactly. :/
Click to expand...
Click to collapse
I added some comments to the code
sh4d0w86 said:
thanks for that bit of code. unfortunately... i have no idea what it does exactly. :/
not a bug, an overlook on my part. everything still there and works, it is just white font on white background. fixed for next release. good catch. next release, app will match Theme & Accent choice.
Click to expand...
Click to collapse
Just an 'accidentally' catch. Well, will wait for the next release.
Device Reset v1.1.0.0 released
--- Added/Updated
------ Accent & Theme support
------ Message Boxes
--------- Hard Reset
--------- Shutdown
--- Fixed
------ White Theme bug
--- Issue(s)
------ Hard Reset
--------- still not working
Device Reset v1.2.0.0 released
--- Added/Updated
------ removed DLLImport hyperlink(s)
------ revised Application Icons
--- Removed
------ Hard Reset
Device Reset v2.0.0.0 released
--- Added/Updated
------ Double Tap to execute actions
------ Pinnable Soft Reset/Shutdown Tile(s)
--------- Hold button
--------- pinned actions execute from Tile
auto on/off airplane mode
Hi,
Can you add a feature in your app to auto on/off airplane mode at scheduled time??? It could be a great battery saver...
updated Post #1. also, added additional pictures; Tiles, Tile Actions
kushal3110 said:
Hi,
Can you add a feature in your app to auto on/off airplane mode at scheduled time??? It could be a great battery saver...
Click to expand...
Click to collapse
sorry, but that would be a total random feature...
Thanks for this apps
Nikolo33 said:
Thanks for this apps
Click to expand...
Click to collapse
welcome and thank you for using and supporting it.
Today I found very annoying and strange bug (or, may be, MS call it "feature" ). Seems like directories on isf can hold 1024 files only...
Try code below:
Code:
Random rnd = new Random();
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
byte[] data = new byte[1024];
isf.CreateDirectory("test");
for (int i=0; i<1025; i++)
{
string fileName = "test\\" + i.ToString("D4") + ".bin";
using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
{
rnd.NextBytes(data);
fs.Write(data, 0, data.Length);
}
}
}
After loop completed, resulting directory "test" will be empty! But change i<1024 and you'll get all yours 1024 files...
Tested on emulator and HTC Surround, same results. Can't find any documentation about this limitation... Shame on you, MS!
Update: another strange behavior ('cause of this bug) - if you already have 1024 files and try to add one more, the whole directory content is "magically" disappear But exception isn't thrown...
Interesting, I'll try it as well. This would be lame to have to work around.
Dbeattie said:
Interesting, I'll try it as well.
Click to expand...
Click to collapse
Yes, please, confirm...
I can't test this at the moment but I know I write well over 1000 files to /shared/media so I'm curious to tet this.
sensboston said:
Yes, please, confirm...
Click to expand...
Click to collapse
Hey just tried it out, wrote 2k items to a folder called "Data".
While it didn't show up in the Windows Phone Power tools, the file does exist in the folder itself.
bool success = storage.FileExists(Path.Combine("data", "1999"));
So it's either a problem with the WPConnect api or with the power tools, haven't tried the command line tool.
Yep, fortunately you are right, it's a ISETool.exe (or drivers) bug, not a WP7 ISF.
sensboston said:
Yep, fortunately you are right, it's a ISETool.exe (or drivers) bug, not a WP7 ISF.
Click to expand...
Click to collapse
Could you therefore edit the title of the thread please?
Thanks.
Hello,
I want to use HTML5 + jQueryMobile in combination with PhoneGap to develop a multi platform app.
In the app I need a solution to save login information (e.g. password) on the device and I will use PhoneGap to solve this problem.
I found an example which use the PhoneGap File API and I tested it in an Android project.
Code:
window.onload = function() {
document.getElementById("write").addEventListener('click', function() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFSW, fail);
}, false);
}
function gotFSW(fileSystem) {
fileSystem.root.getFile("test.txt", {
create : true,
exclusive : false
}, gotFileEntryW, fail);
}
function gotFileEntryW(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.write(document.getElementById("txt").value);
}
It works but the code save the file "test.txt" in the root of the filesystem (mnt/sdcard/test.text) and this is a problem because the file will contain passwords and login information.
How can I define that the file will saved in the app root or in a directory where only the app have access.
Or is there another secure solution to save information like passwords on the device file system with PhoneGap?
Thanks
Andi
AndiS84 said:
How can I define that the file will saved in the app root or in a directory where only the app have access.
Click to expand...
Click to collapse
I suggest you use a Sqlite database file, it will be stored in the same directory your application has been installed (and therefore, no other application has access to this file unless it's rooted).
Check this out: https://github.com/lite4cordova/Cordova-SQLitePlugin
I hope you're not saving the credentials human-readable...
Have you considered simply using html5 localstorage?
Sent from my Xperia Arc S using xda app-developers app
@ HoPi`
But so far as I know SQLite is not available for Windows Phone. Is it right?
So i have a problem if i develop my PhoneGap App also for Windows and not only for Android and iOS
Can you recommend a method for PhoneGap to save the credentials no human-readable?
@ lubber!
Yes, but is this a really secure solution to save credentials?
AndiS84 said:
@ HoPi`
But so far as I know SQLite is not available for Windows Phone. Is it right?
So i have a problem if i develop my PhoneGap App also for Windows and not only for Android and iOS
Can you recommend a method for PhoneGap to save the credentials no human-readable?
@ lubber!
Yes, but is this a really secure solution to save credentials?
Click to expand...
Click to collapse
You can use the local storage in html5 to store the credentials .only thing to take care is that make sure the credentials are encrypted before saving. Apps which i was in the development team uses a different mechanism. we wont save the credentials instead we set flags to define whether user checked remeber username check box and act accordingly. Something like a user token is added.
Sent from my Nexus 4 using Tapatalk
I made an phonegap app, which is using websql for storing data. Everything works fine, it is on Google Play. The problem is when I update it (from the market) it erases all of the data which is stored in the websql. My question is, how can I solve this problem? How can I solve it, not to erase all of the data, when I update is?
badcoke.com said:
I made an phonegap app, which is using websql for storing data. Everything works fine, it is on Google Play. The problem is when I update it (from the market) it erases all of the data which is stored in the websql. My question is, how can I solve this problem? How can I solve it, not to erase all of the data, when I update is?
Click to expand...
Click to collapse
The data associated with the app should only be deleted when you either uninstall the app or delete it manually (of course). Do you have anything in your code that initialises the database? I assume you create a database & table structure somewhere - are you sure you're not running that again?
Archer said:
The data associated with the app should only be deleted when you either uninstall the app or delete it manually (of course). Do you have anything in your code that initialises the database? I assume you create a database & table structure somewhere - are you sure you're not running that again?
Click to expand...
Click to collapse
I am sure, that that the database is not running again.
Here is my code:
Code:
function databaseFunction () {
var db,
len,
bx,
res = [];
this.open = function(levelDone) {
db = openDatabase('worderDd', '1.0', 'Test DB', 5 * 1024 * 1024);
var msg;
}
this.create = function() {
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS worderDd (id INTEGER PRIMARY KEY AUTOINCREMENT, level)');
});
}
this.addData = function (levelDone) {
db.transaction(function (tx) {
tx.executeSql('INSERT INTO worderDd (level) VALUES (?)', [levelDone]);
alert('AWWWWWWESOME! LEVEL COMPLETED');
window.location.replace("index.html");
});
}
Unfortunately the stored data is missing from this section of the code when update it through the market