[Q] Possible? Programatically distinguishing between home screen and phone app. - Android Software Development

I am writing an app for research purposes, it logs what app you're currently using. I have most of it working correctly however I am running into an issue.
I am running into a problem because when the user is using the "Phone" application the process android.process.acore is the process in the Foreground UI (runningAppInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND). Then when the user is on their launcher or home screen the same behavior occurs with the only process in the Foreground UI being android.process.acore.
This means that I can't tell the difference between the two and that I can't properly log what app the user is using.
Any ideas or places in the code I should look?
Thanks

Hi,
have you already tried to look at the intents of the running application?
The following sample looks at the package level, but it could give you a direction.
I've written it for a prototype to test an idea that I've put aside, so I don't have experience with the different behaviors in the real world.
Code:
ActivityManager manager = (ActivityManager)<<CONTEXT>>.getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pMan = <<CONTEXT>>.getPackageManager();
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> homeApps = pMan.queryIntentActivities(homeIntent, PackageManager.GET_ACTIVITIES);
//returns the most recent running task
List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
Iterator<ActivityManager.RunningTaskInfo> iter = runningTasks.iterator();
while(iter.hasNext())
{
ActivityManager.RunningTaskInfo info = iter.next();
Iterator<ResolveInfo> homeAppIterator = homeApps.iterator();
while(homeAppIterator.hasNext())
{
ResolveInfo homeApp = homeAppIterator.next();
if(info.baseActivity.getPackageName().equals(homeApp.activityInfo.packageName))
//we have to deal with a home app
}
}

Thanks! Worked like a charm, here is my code to anyone else with this problem.
Code:
ActivityManager activityManager = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
output = runningTasks.get(0).baseActivity.toShortString();
You have to add the android.permission.GET_TASKS permission in your manifest first.

Oh, I have been so focused on the home screen problem that I didn't notice that the solution to your root problem was solved on the way already.
I'm glad it helped.

Oh, and I noticed you were using iterators. You should check out the for each syntax in java, it would clean up your code a little. Feels very c++ with iterators .
Code:
List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
for (RunningTaskInfo runningTask : runningTasks) {
...
}
Just my personal preference when I'm coding .

GingerEffect said:
Oh, and I noticed you were using iterators. You should check out the for each syntax in java, it would clean up your code a little. Feels very c++ with iterators .
Code:
List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
for (RunningTaskInfo runningTask : runningTasks) {
...
}
Just my personal preference when I'm coding .
Click to expand...
Click to collapse
Thank you for that.
Coming from C# I really missed something like foreach (in addition to other beloved syntactic sugar)

Related

Win32 Mode Failure to set text in static control

I have a problem in setting controls in a Win32 application.
When I use SendMessage to set a text string in a static control I get error number 120 which translated means: "This function is only valid in Win32 mode."
Here's the background:
I'm using Visual Studio 2005, I've installed the Windows Mobile 5 SDK.
The project was created using the New Project Wizard, with the following settings:
Visual C++/Smart Device
Win32 Smart Device Project
Platform SDK is: Windows Mobile 5.0 Pocket PC SDK
Windows application
I've added a dialog template resource and can bring up a dialog based on that resource. It contains a static control that I can read the text from, but attempting to set the text gives me the above error.
The relevent code (within the WM_INITDIALOG message handler) is:
Code:
char buffer[100];
HWND hCtrl = ::GetDlgItem(hDlg, IDC_TITLE);
LRESULT result = ::SendMessage(hCtrl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
This works, I get the correct text (ie the text I have placed into the static control using the dialog template editor) copied into the buffer. What follows is:
Code:
buffer[0] = 'A'; // Just to set up a different string
result = ::SendMessage(hCtrl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
LPVOID lpMsgBuf;
DWORD error = ::GetLastError();
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
::MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)"LError", MB_OK | MB_ICONINFORMATION);
::LocalFree(lpMsgBuf);
}
The attempt to set the changed text string fails (ie result == 0), and the last error is 120, which is translated to the error message above.
This works the same in both the Windows Mobile 5 emulator, and if I run it on my Atom.
What does this mean? How could it be anything other than Win32 mode?
Is there a function or something I have to call to put it into Win32 mode?
Or is it a project setting in VS2005 that I haven't been able to find?
I'd very much appreciate any help on this.
Peter
Hi Peter.
The only problem I can see in your code is that you are using char instead of WCHAR. Windows Mobile devices only use UNICODE for API calls.
I don't think it is causing the error, but it is strange that you manage to get the correct text out using it.
The only thing I can think of is using GetWindowText and SetWindowText APIs instead of sending the message directly.
Maybe this will solve your problem.
I also notice that you did not initialize the buffer. The string needs to be null terminated so try initializeing all the elements before putting your 'A' in.
I thought 120 was not supported on this system ERROR_CALL_NOT_IMPLEMENTED.
Guys,
Thanks very much for the suggestions.
As for not initializing the buffer, I think the WM_GETTEXT call does that, all I do with the buffer[0] = 'A' call is to modify a single character that now contains the text that was copied out from the control.
But I take your point about using WCHAR, I'll do that when I get a chance.
And I'll try the Get and SetWindowText calls.
Thanks again.
Ok, How about this then?
The buffer is initialized by the WM_GETTEXT message, and it is set to the correct value (ie the initial contents of the control).
Changing the first character works.
The WM_SETTEXT message fails (result == 0) and the translated error (120) as displayed in the message box is "This function is only valid in Win32 mode."
The SetWindowText also fails with the same last error.
Does anyone know what "Win32 mode" is? I have spent time searching the MSDN and googling it. I've seen some references to it as an error message, but I haven't found an explanation.
Thanks,
Peter
Code:
WCHAR buffer[100];
HWND hCtl = ::GetDlgItem(hDlg, IDC_TITLE);
LRESULT result = ::SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
buffer[0] = WCHAR('A');
//BOOL textResult = ::SetWindowText(hCtl, (LPCWSTR)buffer);
result = ::SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
WCHAR errorTitle[] = L"LastError";
LPVOID lpMsgBuf;
DWORD error = ::GetLastError();
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
::MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
::LocalFree(lpMsgBuf);
}
Ok, there is no apparent reason why your code doesn't work. Like OdeeanRDeathshead said according to MSDN error 120 means 'This function is not supported on this system.', something you definitely should not be getting.
One question: is this code inside a class member function? I am asking because of the '::' in front of every API.
Try removing them and see what happens.
Also, no need to use WCHAR('A'), just write L'A' save your self some typing in the long run.
P.S. In my year and a half of programming for Windows Mobile I never heard of a 'Win32 mode' or a function not working because of it. The error may be elsewhere in your code, some problem with name-spaces perhaps?
Are you running this on an actual device or just the emulator?
Hi levenum,
Thanks for the reply. Where to start?
Firstly I tend to use the scope resolution operator wherever possible. In this case ::SendMessage (for example), is meant to be a clear message to the reader that these functions are not member functions of the class, but instead exist in the global namespace. I have tried removing them and there is no difference.
You also asked if the code was in a class member function. Well, yes. It is a static member function of a specialization of a generic dialog class. Both the about box dialog and this setup dialog specialize this generic dialog class. Each has their own static dialog message processing function.
The code is in the part that handles the WM_INITDIALOG message. This is where I would normally (ie in Win32 on good ol' PC type windows) initialize controls before the dialog box is displayed. I have shown the dialog message function, and it is almost identical to the one for the about box that is generated when you create a Win32 project in the wizard.
One other point is that the GetLastError call and the format call are exactly out of the MSDN. If you look up the FormatMessage function, there is example code to translate the error code returned by GetLastError. That's exactly what I have here, and the message it gives is about not being in Win32 mode. So now I'm curious, how do you arrive at the 'This function is not supported on this system' comment. I looked for error and 120, and the only thing I could find was something about ARM messages "improper line syntax; wrong use of local label".
By the way, the SetWindowText function (commented out) gives exactly the same error code. As you say, surely both of these are allowed on this system.
I also appreciate you comment about not having heard of a Win32 mode.
But you have got me wondering if I can simplify the problem further. I will try the initial small project you get generated from the wizard, and in the about box dialog message processing function I will try to set the text in one of the two static controls on the about box.
Thanks again,
Peter
Code:
// Message handler for the setup dalog.
INT_PTR CALLBACK
DialogSetup::DialogSetupDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
// Set up strings
//LRESULT result = ::SendDlgItemMessage(hDlg, IDC_TITLE, WM_SETTEXT, 0, (LPARAM)"Setup");
WCHAR buffer[100];
HWND hCtl = ::GetDlgItem(hDlg, IDC_TITLE);
LRESULT result = ::SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
buffer[0] = WCHAR('A');
//BOOL textResult = ::SetWindowText(hCtl, (LPCWSTR)buffer);
result = ::SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
WCHAR errorTitle[] = L"LastError";
LPVOID lpMsgBuf;
DWORD error = ::GetLastError();
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
::MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
::LocalFree(lpMsgBuf);
}
}
return (INT_PTR)TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog
(
GetInstance(),
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_SETUP_WIDE) : MAKEINTRESOURCE(IDD_SETUP)
);
}
break;
#endif
}
return (INT_PTR)FALSE;
}
Hi levenum,
Thanks for the reply. Where to start?
Firstly I tend to use the scope resolution operator wherever possible. In this case ::SendMessage (for example), is meant to be a clear message to the reader that these functions are not member functions of the class, but instead exist in the global namespace. I have tried removing them and there is no difference.
You also asked if the code was in a class member function. Well, yes. It is a static member function of a specialization of a generic dialog class. Both the about box dialog and this setup dialog specialize this generic dialog class. Each has their own static dialog message processing function.
The code is in the part that handles the WM_INITDIALOG message. This is where I would normally (ie in Win32 on good ol' PC type windows) initialize controls before the dialog box is displayed. I have shown the dialog message function, and it is almost identical to the one for the about box that is generated when you create a Win32 project in the wizard.
One other point is that the GetLastError call and the format call are exactly out of the MSDN. If you look up the FormatMessage function, there is example code to translate the error code returned by GetLastError. That's exactly what I have here, and the message it gives is about not being in Win32 mode. So now I'm curious, how do you arrive at the 'This function is not supported on this system' comment. I looked for error and 120, and the only thing I could find was something about ARM messages "improper line syntax; wrong use of local label".
By the way, the SetWindowText function (commented out) gives exactly the same error code. As you say, surely both of these are allowed on this system.
I also appreciate you comment about not having heard of a Win32 mode.
But you have got me wondering if I can simplify the problem further. I will try the initial small project you get generated from the wizard, and in the about box dialog message processing function I will try to set the text in one of the two static controls on the about box.
Thanks again,
Peter
Code:
// Message handler for the setup dalog.
INT_PTR CALLBACK
DialogSetup::DialogSetupDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
// Set up strings
//LRESULT result = ::SendDlgItemMessage(hDlg, IDC_TITLE, WM_SETTEXT, 0, (LPARAM)"Setup");
WCHAR buffer[100];
HWND hCtl = ::GetDlgItem(hDlg, IDC_TITLE);
LRESULT result = ::SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
buffer[0] = WCHAR('A');
//BOOL textResult = ::SetWindowText(hCtl, (LPCWSTR)buffer);
result = ::SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
WCHAR errorTitle[] = L"LastError";
LPVOID lpMsgBuf;
DWORD error = ::GetLastError();
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
::MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
::LocalFree(lpMsgBuf);
}
}
return (INT_PTR)TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog
(
GetInstance(),
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_SETUP_WIDE) : MAKEINTRESOURCE(IDD_SETUP)
);
}
break;
#endif
}
return (INT_PTR)FALSE;
}
That error message comes from the free evc compilers. In the tool "error lookup" and in the help, it gives that mesage to correspond to that number.
I have just tested everthing you did. My dialog also uses a class with static methods for its routine. I used your exact code in the initial dialog handler and experimented with the origional contents of the controll. I tested on 2002 2003 2005 devices and can't make it fail. The worst i can get to happen is if there is no text to start with, just a square character displays after the A.
the only thing different is that you say two dialogs use that routine, but I am guessing that you are not doing bothe at once at this time.
Guys, thanks again for anything you can give me.
Lets see, I don't have the situation where two dialogs are using the same function. They both use a different message handling function (different name).
As I said in my last post (sorry I seem to have posted it twice), I was going to simplify the example. I've done that and I get the same problem.
I created another project with the same settings I described above, called "TestSetText". I made a change in only one place. In the function called "About", the message handling function for the about box dialog, I have inserted my example code to get and set the text for one of the static controls called IDC_STATIC_2. I have made no other changes to the code. So the modified About function is as below, and I have commented the section I have added:
Code:
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
// Code to check setting text - only change
//LRESULT result = SendDlgItemMessage(hDlg, IDC_STATIC_2, WM_SETTEXT, 0, L"Example");
WCHAR buffer[100];
HWND hCtl = GetDlgItem(hDlg, IDC_STATIC_2);
LRESULT result = SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Text from control", MB_OK | MB_ICONINFORMATION);
// Modify the extracted text
buffer[0] = L'A';
//BOOL textResult = SetWindowText(hCtl, (LPCWSTR)buffer);
result = SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
WCHAR errorTitle[] = L"LastError";
LPVOID lpMsgBuf;
DWORD error = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
// End of my change
}
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog(
g_hInst,
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
}
break;
#endif
}
return (INT_PTR)FALSE;
}
So now there are no double colons, no second dialog, no base class, nothing else to confuse the issue. When the app starts all I have to do is invoke the Help|About menu.
When the WM_GETTEXT message is complete, buffer contains exactly the text I would have expected "TestSetText Version 1.0", and this is what is displayed in the message box. So in principle the SendMessage function works and the control handle (hCtl) is correct. This leads me to suspect that all necessary controls are created by the time the WM_INITDIALOG message is processed, and SHOULD be a good place to modify the controls prior to displaying the dialog box.
Modifying the first character in the buffer (setting it to 'A') succeeds as I can see in the debugger.
The attempt to send the WM_SETTEXT message fails (ie result == 0) and GetLastError returns 120 again. The code as I have it there translates this to "This function is only valid in Win32 mode." And this is displayed in the next message box.
When you see the about box, the first character in the IDC_STATIC_2 control has not been changed.
I've also tried using the SetWindowText call which returns non zero (a failure), and the same thing happens (GetLastError returns 120).
One final comment is that if you look up in the MSDN the FormatMessage function, it gives you code (that I have copied) to translate the GetLastError into a string. This gives the Win32 mode message above.
On the other hand, I have found the 120 error in the section "System Errors - Numerical Order" and 120 is listed there as "This function is not valid on this platform." which both of you guys have mentioned.
Ok, two different error messages. The Win32 mode error I don't understand. The not valid error is much more understandable, but how could these functions not be valid?
If you have stayed with me this far then you have a lot of patience.
Thanks
Peter
perhaps you could work around this. Define a value to use as your own message like #define MY_SETUP_MESSAGE ...some value.
Then do nothing in the handler for WM_INITDIALOG except post your own setup message. Do all your normal stuff there. If that succeeds then take a closer look at the timing of WM_INITDIALOG, else there is something waky going on.
Hang on a second, you wrote:
I've also tried using the SetWindowText call which returns non zero (a failure), and the same thing happens (GetLastError returns 120).
Click to expand...
Click to collapse
Is that correct or is it a typo? According to MSDN non zero return for SetWindowText means success, not failure.
One thing you should try is calling SetLastError(0) before calling SetWindowText. Last error is no automatically reset in any way, so it is possible that error 120 is a result of a previous function. Although that still wouldn't account for not seeing the change text in the control.
In any case this is strange. I always initialize controls in WM_INITDIALOG handler and it never failed before.
Ah, you're right. Sorry, I screwed that up. I misread the MSDN there and did a GetLastError anyway, which returned 120.
SetWindowText returns a value of 1, which implies success, but it wasn't successful in the sense of setting the text, when you see the about box it is unchanged.
I also did a SetLastError to zero before the call, and did a GetLastError after it (even though the return code said success), and it was zero. So by all accounts (return code and GetLastError) it should have worked but didn't. The about box is unchanged.
I have also SetLastError to zero before the SendMessage to set the text. That returns zero, and I am sure that the MSDN says should be TRUE if the text is set, so an error. Trouble is, GetLastError then gives zero implying that there was no failure. When you see the about box, the text is not changed so it did fail.
I will have to experiment some more. Maybe I can't set text in a static for some reason. Do I need to call InitCommonControls for that or something (which I haven't done)?
I will also have to try setting text in an edit control.
I used the format message and got the same win32 mode stuff now. However, the text was modified to the new value. I think the win32 mode error message is a bug. Put the same code into the emulator and the error returned is invalid handle. At least invalid handle is something more definite. In both cases, emulator and real device, even though the returned value is 0 for WM_SETTEXT, and the error message is there, I do not think there is an error. Have you just tried it without any error checking?
Are you creating the dialog using creatdialog/dialogbox?
Hi OdeeanRDeathshead, thanks for the reply.
I don't think the invalid handle error is right here because I have used the same control window handle (hCtl) a couple of statements before to retrieve the text and that worked. I guess what I haven't checked is whether the control window handle is changed somehow as a result of the first call, but that would be really weird.
You said that even though SendMessage/WM_SETTEXT returned 0, you thought it probably wasn't an error. Well, there is support for that in that when I SetLastError to zero just prior to calling it, and call GetLastError just after, the error code was zero, thus no error. But the reason I think that there WAS an error is that it did not modify the static control. This is what I get if I effectively don't do any error checking.
As for how I am creating the dialog, the only code I have modified from the original project created from the application wizard is in the WM_INITDIALOG section of the About function that I showed you above. The dialog is created in the WndProc message handling function for the main window, part of which is below. If it is the IDM_HELP_ABOUT command, from the menu, it calls DialogBox specifying the dialog message processing function 'About' where my modified code is.
The code below is produced by the application wizard.
Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
[b]case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;[/b]
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
etc
I think I am going to have to experiment some more on the weekend. Try some other controls etc.
By the way I meant to mention that exactly the same thing happens in both the emulator as well as my Atom. So far, in all of the combinations of code, I have not been able to programmatically change the text content of a static control on a dialog.
And I've just noticed that my attempt to highlight (bold) the relevent part of the code above didn't work.
D'oh!
Actually I have just thought of something that may be relevent.
The emulator and SDK that came by default with VisualStudio2005 is WindowsCE 2003. When I first tried my code in the emulator, it worked. I could not only set text in a static control, I was also successfully manipulating a date/time picker in a separate dialog. I did lots of GDI rendering in the main window as well. And this code also worked on a friend's WindowsCE2003 PDA.
Things looked good until I tried it on my Atom which is WindowsMobile 5.
None of the above worked (except the GDI rendering). I thought it may have been a problem with the development environment. So I downloaded the WindowsMobile 5 SDK which includes a WM5 emulator. I thought this is bound to fix the problem, ie generate the code with the WM5 SDK.
All of my problems above are with WM5 project and emulator. And I said I was using this way back in the first post.
OdeeanRDeathshead, I had a quick look at your profile and you seem to have some earlier XDA machines. Are you using Windows Mobile 5?
If the problem does turn out to be Windows Mobile 5 related, then that says something very bad about backwards compatibility for that platform. Could it also be a WM5 bug? Surely not something so fundamental as this?
I use evc++3 for a compiler, mainly because I am the kind of person who thinks - if its not broaken why change. I have an Atom and do use it to run code on. I have all os, ie 2002,2002pe,2003,2003se,2005, so I don't think this problem is with the device. It may be vis studio 2005, but others have said it works OK.
PPC operating systems have a nasty history of backwards compatibility issues. I could not say that this is the issue here, but it is definately one reason I stick to a lowest common denominator approach. Why not just get evc3 or evc4 and give them a try. They are free.
I guess I was hoping to do it with Visual Studio 2005 because that is what I use at work. These days I mainly program in C#/.NET.
I kind of miss the low level stuff that I used to do on windows a long time ago. But I reminisce.
I'm assuming that evc++ is embedded visual c++? It sounds like really good advice, I'll look for it and it sounds like it will fix all my problems. Especially if as you say, it works for WindowsMobile 5. Can you tell me if you are supposed to use the WindowsMobile 5 SDK with it?
So OdeeanRDeathshead and levenum, thanks a lot for your help guys.
Peter

[Q]To create android app for consuming OData services via Netweaver Gateway

Hi,
I need to develop an android application using Eclipse and Netweaver Gateway plugin. When I run my code as a console application, it works fine. However, I'm unable to consume the OData services from the android application. I need to call an OData service, which is hosted on an ECC on an organization's server and display the details and whatever on the application screen (in text-fields or whatever). The "android.permission.INTERNET" is defined in the AndroidManifest.xml, already. See the code below: (Url & credentials have been omitted)
private void readExample() throws RestClientException, ParserException
{
String reqUri = "http://<some url>";
IServerConnectionParameters gateway = new ServerConnectionParameters("<host name>","<port>","<client>",false);
IAuthentication credentials = new UsernamePasswordCredentials("<username>","<password>");
IRestClient restClient = RestClientFactory.createInstance(gateway, credentials,Representation.ATOM);
IRestRequest request = new RestRequest(reqUri);
IRestResponse response = restClient.execute(request);
// Convert the response body XML into an ODataCollection object
ODataEntry collection = ODataUtil.parseODataEntry(response.getBody());
ODataProperty[] properties = collection.getProperties();
for (ODataProperty oDataProperty : properties)
{
Context context = getApplicationContext();
CharSequence text = oDataProperty.getValue();
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
This is the function which gets called on a button click event and for example here, the details should be fetched from the service and shown as toast messages. This block works very fine using command line, but I'm unable to consume this via android. The debugger gets stuck on the "IRestResponse response = restClient.execute(request);" line and after a while returns an error of "Connection ETIMEDOUT" and could not connect to the host.
I'm using two reference libraries : com.sap.nw.gateway.odata.client_2.6.400.201211111531.jar, odata4j-0.7.0-clientbundle.jar.
Could somebody please shed some light on this?? I'm deeply stuck and need this urgently!! :crying:
Nobody ready to help, guys?? :'( :'(
bugnotch said:
Nobody ready to help, guys?? :'( :'(
Click to expand...
Click to collapse
Hi,
Please use Gateway Productivity Accelerator (tools.hana.ondemand.com/#gateway) instead of the Netweaver Gateway plugin for Eclipse.
Also, in general, make sure you don't call to a very large amount of data in a single request, but rather use paging or other.
Regards

[Q] Need help with a program.

public void click(View view) {
String one = "one";
EditText et = (EditText)findViewById(R.id.editText1);
String entered_text = et.getText().toString();
if(et.getText().toString() == one){
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Correct!");
}
else{
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(one+entered_text); }
}
This is a code snippet extracted from my program, i didn't post the whole program because it wasn't necessary, as the program runs fine without any runtime exceptions.
So, the program when executed on eclipse doesn't show any errors and runs fine, but when run the "if" condition "et.getText().toString() == "one"" always returns false even when the "entered_text" is "one" i.e.; it never prints "correct!" and the code always prints "one+entered_text" that is the statement in the else clause. And the interesting thing is, if you enter "one" the output will be "oneone", that is the else statement.
Please help me where i went wrong.
Thanks in advance.
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
panwrona said:
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
Click to expand...
Click to collapse
Thanks for the reply.
I did what you said and got a runtime exception.
You're running it in fragment or activity?
panwrona said:
You're running it in fragment or activity?
Click to expand...
Click to collapse
Activity.
Are you initializing it in oncreate or somewhere else?
That's easy. Instead of == use text.equals(one)
String are not compared by mathematical signs
Sent from my XT1033 using XDA Premium 4 mobile app

Need help in making a simple app

Hello everyone ^_^
Ive been making zooper themes for some time, as well as Themer themes. What i would love to do now is to create an app that can install a zip file to a specific folder on the storage. I wish to make a Material themed app for installing the zip, that can show scereenshots or other shots which i use to display my themes. Also, I wish to include a link for the wallpaper for that specific theme. Ive scoured the internet a bit for this type of thing, and so far, ive been unable to find anything that would suit my requirement.
help would be appreciated a lot
PS, i havent done app developing or coding in a few years so you could say that im kinda noob to this now so guidance from scratch would be very helpful ^_^
You can use below code to create a zip and place it wherever you want.
Code:
private static void zipFolder(String inputFolderPath, String outZipPath) {
try {
FileOutputStream fos = new FileOutputStream(outZipPath);
ZipOutputStream zos = new ZipOutputStream(fos); File srcFile = new File(inputFolderPath);
File[] files = srcFile.listFiles();
Log.d("", "Zip directory: " + srcFile.getName());
for (int i = 0; i < files.length; i++) {
Log.d("", "Adding file: " + files[i].getName());
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(files[i]); zos.putNextEntry(new ZipEntry(files[i].getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length); }
zos.closeEntry();
fis.close();
}
zos.close();
}
catch (IOException ioe) { Log.e("", ioe.getMessage());
}
}
And for the second one.
You can simple use intent to open your link in browser.
Intent n = new Intent(Intent.ACTION_VIEW , Uri.parse("link to your wallpaper"));
Sent from my A0001 using Tapatalk 2
Android Application Development Request
I am in need of some help I have a great idea for a new app that may change the face of advanced research. This will allow for the user to search all day and all night. While they are handling everyday life issues and events with family and what not. Yet still, allowing them to locate what they are looking for. Also will allow people with artifacts in there home. That the user may think is not worth anything yet it may be a goldmine. So instead of the user having to do research trying to locate these specific artifacts to see if they are worth money. This app will allow them to do advanced research all day with a touch of a button my idea is revolutionary when it comes to the advanced research that needs to be done. Please, I am looking for somebody to help me develop this app and bring it to life. So that I may present this idea to google for a possible sale. Thank you for your consideration ahead of time on helping me with this application.

Trying to expand notifications programmatically

Hey, I have this code to expand the notifications:
Code:
try{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method expand = statusbarManager.getMethod("expand");
expand.invoke(service);
}
catch(Exception ex) {
}
But I get some long errors under the expression "statusbar" in line
Code:
Object service = getSystemService("statusbar");
here is the errors:
Code:
Must be one of: Context.POWER_SERVICE,
Context.WINDOW_SERVICE,
Context.LAYOUT_INFLATER_SERVICE,
Context.ACCOUNT_SERVICE,
Context.ACTIVITY_SERVICE,
Context.ALARM_SERVICE,
Context.NOTIFICATION_SERVICE,
Context.ACCESSIBILITY_SERVICE,
Context.CAPTIONING_SERVICE,
Context.KEYGUARD_SERVICE,
Context.LOCATION_SERVICE,
Context.SEARCH_SERVICE,
Context.SENSOR_SERVICE,
Context.STORAGE_SERVICE,
Context.WALLPAPER_SERVICE,
Context.VIBRATOR_SERVICE,
Context.CONNECTIVITY_SERVICE,
Context.NETWORK_STATS_SERVICE,
Context.WIFI_SERVICE,
Context.WIFI_P2P_SERVICE,
Context.NSD_SERVICE,
Context.AUDIO_SERVICE,
Context.FINGERPRINT_SERVICE,
Context.MEDIA_ROUTER_SERVICE,
Context.TELEPHONY_SERVICE,
Context.TELEPHONY_SUBSCRIPTION_SERVICE,
Context.CARRIER_CONFIG_SERVICE,
Context.TELECOM_SERVICE,
Context.CLIPBOARD_SERVICE,
Context.INPUT_METHOD_SERVICE,
Context.TEXT_SERVICES_MANAGER_SERVICE,
Context.APPWIDGET_SERVICE,
Context.DROPBOX_SERVICE,
Context.DEVICE_POLICY_SERVICE,
Context.UI_MODE_SERVICE,
Context.DOWNLOAD_SERVICE,
Context.NFC_SERVICE,
Context.BLUETOOTH_SERVICE,
Context.USB_SERVICE,
Context.LAUNCHER_APPS_SERVICE,
Context.INPUT_SERVICE,
Context.DISPLAY_SERVICE,
Context.USER_SERVICE,
Context.RESTRICTIONS_SERVICE,
Context.APP_OPS_SERVICE,
Context.CAMERA_SERVICE,
Context.PRINT_SERVICE,
Context.CONSUMER_IR_SERVICE,
Context.TV_INPUT_SERVICE,
Context.USAGE_STATS_SERVICE,
Context.MEDIA_SESSION_SERVICE,
Context.BATTERY_SERVICE,
Context.JOB_SCHEDULER_SERVICE,
Context.MEDIA_PROJECTION_SERVICE,
Context.MIDI_SERVICE less... (Ctrl+F1)
This inspection looks at Android API calls and ensures that the correct type of resource is passed to an int-parameter expecting resources of a given type; it checks that APIs which expect an RGB color integer are passed actual colors rather than color resources; it checks that APIs which require a certain permission have the permission declared in the manifest; it checks that parameters expected to fall within a given range actually do; it checks that results of certain method calls are looked at by the caller, and so on.
JusTeN_ said:
Hey, I have this code to expand the notifications:
Code:
try{
Object service = getSystemService("statusbar");
Class statusbarManager = Class.forName("android.app.StatusBarManager");
Method expand = statusbarManager.getMethod("expand");
expand.invoke(service);
}
catch(Exception ex) {
}
But I get some long errors under the expression "statusbar" in line
Code:
Object service = getSystemService("statusbar");
here is the errors:
Code:
Must be one of: Context.POWER_SERVICE,
Context.WINDOW_SERVICE,
Context.LAYOUT_INFLATER_SERVICE,
Context.ACCOUNT_SERVICE,
Context.ACTIVITY_SERVICE,
Context.ALARM_SERVICE,
Context.NOTIFICATION_SERVICE,
Context.ACCESSIBILITY_SERVICE,
Context.CAPTIONING_SERVICE,
Context.KEYGUARD_SERVICE,
Context.LOCATION_SERVICE,
Context.SEARCH_SERVICE,
Context.SENSOR_SERVICE,
Context.STORAGE_SERVICE,
Context.WALLPAPER_SERVICE,
Context.VIBRATOR_SERVICE,
Context.CONNECTIVITY_SERVICE,
Context.NETWORK_STATS_SERVICE,
Context.WIFI_SERVICE,
Context.WIFI_P2P_SERVICE,
Context.NSD_SERVICE,
Context.AUDIO_SERVICE,
Context.FINGERPRINT_SERVICE,
Context.MEDIA_ROUTER_SERVICE,
Context.TELEPHONY_SERVICE,
Context.TELEPHONY_SUBSCRIPTION_SERVICE,
Context.CARRIER_CONFIG_SERVICE,
Context.TELECOM_SERVICE,
Context.CLIPBOARD_SERVICE,
Context.INPUT_METHOD_SERVICE,
Context.TEXT_SERVICES_MANAGER_SERVICE,
Context.APPWIDGET_SERVICE,
Context.DROPBOX_SERVICE,
Context.DEVICE_POLICY_SERVICE,
Context.UI_MODE_SERVICE,
Context.DOWNLOAD_SERVICE,
Context.NFC_SERVICE,
Context.BLUETOOTH_SERVICE,
Context.USB_SERVICE,
Context.LAUNCHER_APPS_SERVICE,
Context.INPUT_SERVICE,
Context.DISPLAY_SERVICE,
Context.USER_SERVICE,
Context.RESTRICTIONS_SERVICE,
Context.APP_OPS_SERVICE,
Context.CAMERA_SERVICE,
Context.PRINT_SERVICE,
Context.CONSUMER_IR_SERVICE,
Context.TV_INPUT_SERVICE,
Context.USAGE_STATS_SERVICE,
Context.MEDIA_SESSION_SERVICE,
Context.BATTERY_SERVICE,
Context.JOB_SCHEDULER_SERVICE,
Context.MEDIA_PROJECTION_SERVICE,
Context.MIDI_SERVICE less... (Ctrl+F1)
This inspection looks at Android API calls and ensures that the correct type of resource is passed to an int-parameter expecting resources of a given type; it checks that APIs which expect an RGB color integer are passed actual colors rather than color resources; it checks that APIs which require a certain permission have the permission declared in the manifest; it checks that parameters expected to fall within a given range actually do; it checks that results of certain method calls are looked at by the caller, and so on.
Click to expand...
Click to collapse
HTML:
Object sbservice = context.getSystemService("statusbar");try { Class statusbarManager = Class.forName("android.app.StatusBarManager"); Method collapse = statusbarManager.getMethod("expand");collapse.setAccessible(true) collapse.invoke(sbservice); }} catch (Exception e) { e.printStackTrace();}
It may be wrong in typs or something else wrong pls fix it bcoz I am from mobile
Sent from my SM-G530H using XDA Free mobile app
AndroidFire said:
HTML:
Object sbservice = context.getSystemService("statusbar");try { Class statusbarManager = Class.forName("android.app.StatusBarManager"); Method collapse = statusbarManager.getMethod("expand");collapse.setAccessible(true) collapse.invoke(sbservice); }} catch (Exception e) { e.printStackTrace();}
It may be wrong in typs or something else wrong pls fix it bcoz I am from mobile
Sent from my SM-G530H using XDA Free mobile app
Click to expand...
Click to collapse
thx but it doesn't matter at all.. just the first line doing me a lot of troubles.
JusTeN_ said:
thx but it doesn't matter at all.. just the first line doing me a lot of troubles.
Click to expand...
Click to collapse
No need to say just hit
Could you upload full java source here main one where you are trying to do stuff on status bar
Sent from my SM-G530H using XDA Free mobile app

Categories

Resources