PDA goes to sleep/ Process ID - Windows Mobile Development and Hacking General

Hi,
I am having problems with keeping my application alive as the pda keeps going into 'sleep' mode. I realise that i can't just keep the pda switched on as the battery will just die, so i have a little program which does a RunAppAtTime call, and then checks to see if my application is alive. I expected that i would either have an error or would get a process id of -1 etc if the process wasn't alive. I am using VB.net and OpennetCF to do the code here is a code snippet. Hope someone can help, i need to finish this before friday.
Dim intProcessID As Integer
Dim Process As New OpenNETCF.Diagnostics.Process
Dim NewProcess As OpenNETCF.Diagnostics.Process
Dim info As New OpenNETCF.Diagnostics.ProcessStartInfo
Dim OldProcess As New OpenNETCF.Diagnostics.Process
Try
intProcessID = ReadID()
ldProcess = OpenNETCF.Diagnostics.Process.GetProcessById(intProcessID)
If (OldProcess.Id = -1) Or (OldProcess.Id <> intProcessID) Then
info.FileName = "\Storage\AutoSync.exe"
info.UseShellExecute = False
NewProcess = Process.Start(info)
intProcessID = NewProcess.Id
WriteProcID(intProcessID)
Else
WriteFile("Processexists" & DateTime.Now)
End If

Related

VS.Net and TimeZones...

Hi all,
I'm trying to fix up a long standing timezone issue with KingFetty's CallCalendar - but there seems to be some WEIRD **** happening with DST time...
At the moment, the code works perfectly - however the call gets logged to the calendar with a start time and end time of 1 hour behind the current device time.
This gets weirder when you add a line like this to the start of the program:
msgbox(Now)
The time shown on the messagebox is 1 hour behind what is shown on the clock :|
My idea was to add the following block of code to the FixTime function to try and fix this:
Dim localZone As TimeZone = TimeZone.CurrentTimeZone
If localZone.IsDaylightSavingTime(StartTime) Then
StartTime = StartTime.AddHours("1")
StopTime = StopTime.AddHours("1")
End If
This is all well and good, however IsDaylightSavingTime returns false! Oh joy.
Has anyone run across the VS strangeness with timezones and daylight savings before?
I have attached the current source to this post for budding VB.Net hackers...
Ok - so I managed to find the problem... It looks like after installing the March 2008 Daylight Savings updates, for my particular timezone you need to change to a different timezone, then switch back to the correct timezone for the registry changes to be applied.
Weird behaviour for this kind of thing as multiple hard resets, soft resets, and power off/on reboots didn't have this effect.
This leads me to believe it's a WM issue. Anyone got any ideas on how to fix this properly?
You will have better luck if you post in the appropriate section of the forum. There is a ''Question and Answers'' section to XDA. This section of the forum hereis for posting completed applications, themes, etc.
erm this is a Question Regarding the Development, so i guess it should stay here
I'm not really sure what's your problem but I exprerienced some issues when I had to deal with timezones. This is what helped me:
Code:
System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();
I've sent the following to MS - as it's quite strange behaviour!
I have run some test with the following simple application:
------------------ Start Sample Code ------------------
Imports System.TimeZone
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim localZone As TimeZone = TimeZone.CurrentTimeZone
MsgBox("Time = " & Now & vbCrLf & "StandardName = " & localZone.StandardName & vbCrLf & "DaylightName" & localZone.DaylightName & vbCrLf & "IsDaylight? = " & localZone.IsDaylightSavingTime(Now))
Me.Close()
End Sub
End Class
------------------ End Sample Code ------------------
On freshly booting the Windows Mobile device, I get the following output:
Time = 17/12/08 6:05:20 PM
StandardName =
DaylightName =
IsDaylight? = False
The clock on the device shows 7:05pm when this test was run.
I change the timezone to +10 Brisbane, Click OK, then click Yes to save the changes to the clock.
I then change the timezone back to +10 Sydney, click ok, then click yes to save changes to the clock.
Upon running the sample code above again, I get the following output:
Time = 17/12/08 7:07:38 PM
StandardName = Sydney Standard Time
DaylightName = Sydney Daylight Time
IsDaylight? = True
The clock on the device showed 7:07 PM at the time of this second test.
To me it seems that on boot, the timezone just isn't set - which is just weird!
Click to expand...
Click to collapse

Help with POOM(Pocket Outlook contacts) code in VB .NET (SOLVED)

What I am trying to do is create code that will cycle through all my contacts and add the same category to each one until it reaches the last contact.
Here is my code:
Code:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.WindowsMobile.PocketOutlook
In my Form Load:
Code:
Dim outlookSession As New OutlookSession()
Dim intCount As Integer
Dim myContact As ContactCollection = outlookSession.Contacts
For intCount = 0 To myContacts.Count - 1
contact.categories = "Holiday"
contact.update
myContact = myContacts.Item(intCount)
Next
outlookSession.Dispose()
Any idea's why its failing? Thanks.
jdiperla said:
What I am trying to do is create code that will cycle through all my contacts and add the same category to each one until it reaches the last contact.
Here is my code:
Code:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.WindowsMobile.PocketOutlook
In my Form Load:
Code:
Dim outlookSession As New OutlookSession()
Dim intCount As Integer
Dim myContact As ContactCollection = outlookSession.Contacts
For intCount = 0 To myContacts.Count - 1
contact.categories = "Holiday"
contact.update
myContact = myContacts.Item(intCount)
Next
outlookSession.Dispose()
Any idea's why its failing? Thanks.
Click to expand...
Click to collapse
In which row it fail?
Give me what you want do!
Bye
Try this instead. I've never used it before, but it should work
Dim outlookSession As New OutlookSession()
Dim myContacts As ContactCollection = outlookSession.Contacts
Dim myContact As Contact (***check this for correct object type***)
For each myContact in myContacts
myContact.categories = "Holiday"
myContact.update
Next
outlookSession.Dispose()
OK, I figured it out. I had it backwards:
Code:
Dim outlookSession As New OutlookSession()
Dim intCount As Integer
Dim myContacts As ContactCollection = outlookSession.Contacts.Items
Dim session As OutlookSession = New OutlookSession()
Dim contacts As ContactCollection = session.Contacts.Items
Dim contact As Contact = contacts.AddNew
For intCount = 0 To myContacts.Count - 1
contact = myContacts.Item(intCount)
contact.Categories = myContacts.Item(intCount).Categories & ",Holiday"
contact.Update()
Next
MsgBox("Done")
outlookSession.Dispose()
Me.Dispose()

Need help for making small application

I wanted to make myself an application for switching between profiles for my ringtones.
I'm new at programming but i've been looking for 6 hours now since i'm stuck.
I was thinking of connecting the buttons with a change in the register on the "Ring0"
This is what i have for a vibrating button:
RegistryKey Ourkey = Registry.CurrentUser;
Ourkey = Ourkey.OpenSubKey("ControlPanel", true);
Ourkey = Ourkey.OpenSubKey("Sounds", true);
Ourkey = Ourkey.OpenSubKey("Ring0", true);
Ourkey.SetValue("script",av3w3);
Ourkey.Close();
problem is the av3w3. he gives me an error with it.
Hope someone can help
"Ourkey.SetValue("script",av3w3);"
of av3w3 a varible ?
if so is it the correct type?
if you mean to set the script as a string you need to add ""

InTheHand Bluetooth - Weird stream problems

I am currently working on my "SciLor's WiMoBlue". The new protocol is ready. Everything works fine, until I send much data at the same time.
For example if I try to send an image in that way:
Code:
Public Sub SendImage(ByVal Image As Bitmap, ByVal Position As Point, ByVal Format As ImageFormat)
Dim PosX, PosY, Width, Height As Byte()
Dim ImageStream As New IO.MemoryStream
Dim ImageLength As Integer
Dim ImageLengthBytes As Byte()
Dim ImageBuffer(MaxChunkSize - HeaderSize - 1) As Byte
PosX = BitConverter.GetBytes(Position.X)
PosY = BitConverter.GetBytes(Position.Y)
Width = BitConverter.GetBytes(Image.Width)
Height = BitConverter.GetBytes(Image.Height)
Image.Save(ImageStream, ImageFormat2ImagingFormat(Format))
ImageStream.Seek(0, SeekOrigin.Begin)
ImageLength = ImageStream.Length
ImageLengthBytes = BitConverter.GetBytes(ImageLength)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Initiate, CombineBytes(PosX, PosY, Width, Height, ImageLengthBytes)))
Thread.Sleep(2000)
Dim DataPos As Integer
For DataPos = 0 To ImageStream.Length - MaxChunkSize - HeaderSize - 1 Step MaxChunkSize - HeaderSize
ImageStream.Read(ImageBuffer, 0, MaxChunkSize - HeaderSize)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Data, ImageBuffer))
'WaitForNextChunk = True
'Do While WaitForNextChunk = True
'Loop
'Thread.Sleep(2000)
Next
ImageBuffer = New Byte(ImageLength - DataPos - 1) {}
ImageStream.Read(ImageBuffer, 0, ImageBuffer.Length)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.End, ImageBuffer))
End Sub
SendData:
Code:
If Data.Length > MaxChunkSize Then
MsgBox("Data to long... " & vbNewLine & "SendSize:" & Data.Length & vbNewLine & "MaxSize:" & MaxChunkSize)
Else
If btClient.Connected = True And isRecieving = True Then
btStream.Write(Data, 0, Data.Length)
btStream.Flush()
End If
End If
Recieving Part:
Code:
While isRecieving = True
If btStream IsNot Nothing And btStream.DataAvailable = True Then
Try
Recieved = btStream.Read(myHeader, 0, myHeader.Length)
If myHeader(0) = HeaderIdentifier And myHeader(1) = OtherModeHeader Then
btStream.Read(myDataSize, 0, 2)
DataLength = BitConverter.ToInt16(myDataSize, 0)
myBuffer = New Byte(DataLength - 1) {}
Recieved = 0
Do Until Recieved = DataLength
If btStream.DataAvailable = True Then
Recieved += btStream.Read(myBuffer, Recieved, DataLength - Recieved)
End If
Loop
ExecuteCommand(myHeader(2), myHeader(3), myBuffer)
Else
Debug.WriteLine("WrongData")
Exit While
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
If Recieved = 0 Then
Exit While
End If
End Try
End If
End While
If I send the image, without Thread.Sleeps (huighe ones). The recieving stream gets weird. The gets btStream.DataAvailable = False forever. If I remove that ckeck, it hangs at the btStream.Read.
I also tried to fix that with waiting for the answer of the server, but the problem doesn't get solved.
Do you have any idea how to fix that problem?. In that speed the image sending is worthless
SciLor

[SL4A] running sl4a script don't put back phone to sleep

Hi,
I have a problem of draining battery with SL4A.
First, what i do :
I use Tasker to run SL4A script during night. I repeat script all 10 min. The script give back phone orientation to tasker. if phone don't move during 30min, i put phone in airplane mode and stop to repeat script all 10 min. I do this action only if screen is off, so phone in sleep mode.
The battery draining don't come from tasker, i test it without run SL4A script, no problem. I sure it's because of SL4A.
So with this script, i get battery drain during all night, and battery drain stop when alarm ring on morning (so when phone awake, it's important, remind this)
My script is this one :
Code:
import android, time
droid = android.Android()
class Task():
SET_VARIABLE = 547
def new_task(self):
self.action_cnt = 0
self.extras = {'version_number': '1.0', 'task_name': 'task' + str(time.time()), 'task_priority': 10 }
def set_var(self, varname, value):
self.action_cnt += 1
self.extras['action' + str(self.action_cnt)] = {'action': self.SET_VARIABLE, 'arg:1': varname, 'arg:2': value, 'arg:3': False, 'arg:4': False, 'arg:5': False}
def run_task(self):
taskIntent = droid.makeIntent('net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
droid.sendBroadcastIntent(taskIntent)
def set_var_now(self, varname, value):
self.new_task()
self.set_var(varname, value)
self.run_task()
temps = 20
droid.startSensingTimed(1,500)
while temps > 0:
time.sleep(0.5)
x, y, z = droid.sensorsReadOrientation().result
temps = temps - 1
if x is not None:
break
droid.stopSensing()
t = Task()
t.new_task()
if x is not None:
t.set_var("%ORIENTATION_X", str(x))
t.set_var("%ORIENTATION_Y", str(y))
t.set_var("%ORIENTATION_Z", str(z))
t.set_var("%ORIENTATION", "Done")
t.run_task()
What i do in this script :
I read orientation (max 20 time in case of none result) and i send information to tasker.
I d'ont think i do error in this script.
So i think SL4A don't allow phone to back to sleep mode after finished is script.
Because i find a solution, turn on screen during one second after running script (i do this in tasker) and now, i don't have battery drain.
But this solution is not clean.
Any help to solve this problem ?
thanks a lot
I''m still kinda new to java coding but I really think you need to reffer to:
PARTIAL_WAKE_LOCK
like this:
Code:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
//WAIT here
wl.acquire();
// action here
wl.release();
full reference:
http://developer.android.com/reference/android/os/PowerManager.html
releases the wake lock after the process is finished. I hope that that info is correct, as im note sure.
Have you tried running your script on the emulator to make sure it's exiting properly?
I'm a bit worried about while code (python or not).
Sent from my HTC One X using xda premium
My code work properly, no error in console. Code is in Python (i'm not specialist but if i understand well, the "wend" is do by indentation)
And if code have error, turn on screen 1s after script will don't have any effect, i thinks.
About power management: after read, it's can be this problem. May be if do my own wake lock, SL4A will do one automatically (and forgot to close it)
I will try.
I don't arrive to get powerManager function :crying:
i try to add
Code:
pm = droid.powerManager()
pm.goToSleep(droid.sytemClock.uptimeMillis())
but no way goToSleep function is unknow.
Some help for syntax, i don't find any example. Thanks
i do like this
Code:
import android, time
droid = android.Android()
droid.wakeLockAcquirePartial()
class Task():
SET_VARIABLE = 547
def new_task(self):
self.action_cnt = 0
self.extras = {'version_number': '1.0', 'task_name': 'task' + str(time.time()), 'task_priority': 10 }
def set_var(self, varname, value):
self.action_cnt += 1
self.extras['action' + str(self.action_cnt)] = {'action': self.SET_VARIABLE, 'arg:1': varname, 'arg:2': value, 'arg:3': False, 'arg:4': False, 'arg:5': False}
def run_task(self):
taskIntent = droid.makeIntent('net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
droid.sendBroadcastIntent(taskIntent)
def set_var_now(self, varname, value):
self.new_task()
self.set_var(varname, value)
self.run_task()
temps = 20
droid.startSensingTimed(1,500)
while temps > 0:
time.sleep(0.5)
x, y, z = droid.sensorsReadOrientation().result
temps = temps - 1
if x is not None:
break
droid.stopSensing()
t = Task()
t.new_task()
if x is not None:
t.set_var("%ORIENTATION_X", str(x))
t.set_var("%ORIENTATION_Y", str(y))
t.set_var("%ORIENTATION_Z", str(z))
t.set_var("%ORIENTATION", "Done")
t.run_task()
droid.wakeLockRelease()
But i still have problem. No effect to use wakeLock

Categories

Resources