Detect when phone in use - Windows Mobile Development and Hacking General

Is it possible to programmatically detect when telephone is in use on XDA2, and if so how? Examples using API calls would be great as our app is developed in eVB3 and eVC3.
Thanks

Hi,
You can use the ConnectionManager api and make the connection asyncrous so your main window will be notified with connection events, for example, when the event is received do something like this:
LRESULT DoCommMgrEventMain(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {
DWORD dwStatus;
ConnMgrConnectionStatus(hConnection, &dwStatus);
switch(dwStatus) {
case CONNMGR_STATUS_UNKNOWN:
Log(SEVERIDAD_INFO, TEXT("Unknown"));
break;
case CONNMGR_STATUS_CONNECTED:
Log(SEVERIDAD_INFO, TEXT("Connected."));
break;
case CONNMGR_STATUS_DISCONNECTED:
Log(SEVERIDAD_INFO, TEXT("Disconnected"));
break;
case CONNMGR_STATUS_CONNECTIONFAILED:
Log(SEVERIDAD_INFO, TEXT("Connection has failed and cannot be reestablished"));
break;
case CONNMGR_STATUS_CONNECTIONCANCELED:
Log(SEVERIDAD_INFO, TEXT("User-aborted connection"));
break;
case CONNMGR_STATUS_CONNECTIONDISABLED:
Log(SEVERIDAD_INFO, TEXT("Connection is ready to connect but disabled"));
break;
case CONNMGR_STATUS_NOPATHTODESTINATION:
Log(SEVERIDAD_INFO, TEXT("No path could be found to the destination"));
break;
case CONNMGR_STATUS_WAITINGFORPATH:
Log(SEVERIDAD_INFO, TEXT("Waiting for a path to the destination"));
break;
case CONNMGR_STATUS_WAITINGFORPHONE:
Log(SEVERIDAD_INFO, TEXT("Voice call is in progress"));
break;
case CONNMGR_STATUS_WAITINGCONNECTION:
Log(SEVERIDAD_INFO, TEXT("Attempting to connect"));
break;
case CONNMGR_STATUS_WAITINGFORRESOURCE:
Log(SEVERIDAD_INFO, TEXT("Resource is in use by another connection"));
break;
case CONNMGR_STATUS_WAITINGFORNETWORK:
Log(SEVERIDAD_INFO, TEXT("No path to the destination could be found"));
break;
case CONNMGR_STATUS_WAITINGDISCONNECTION:
Log(SEVERIDAD_INFO, TEXT("Connection is being brought down"));
break;
case CONNMGR_STATUS_WAITINGCONNECTIONABORT:
Log(SEVERIDAD_INFO, TEXT("Aborting connection attempt"));
break;
}
if ((dwStatus == CONNMGR_STATUS_CONNECTIONFAILED) ||
(dwStatus == CONNMGR_STATUS_CONNECTIONCANCELED) ||
(dwStatus == CONNMGR_STATUS_DISCONNECTED)){
if (bDesconectar != TRUE) {
Sleep(10000);
DoMainCommandConnect(hWnd, wMsg, wParam, lParam);
}
else {
bDesconectar = FALSE;
}
}
else {
if (dwStatus == CONNMGR_STATUS_WAITINGFORPHONE) {
// ops llamada telefonica.
// Aqui deberiamos dar por terminada la conexion con el servidor
}
}
return 0;
}

Using connection manager I can now get a gprs connection and perform xmlhttp transfers. While this is in progress the calls to the API function ConnMgrConnectionStatus return CONNMGR_STATUS_CONNECTED. However, if I make a telephone call to the XDA and monitor the ConnMgrConnectionStatus, it returns CONNMGR_STATUS_DISCONNECTED rather than CONNMGR_STATUS_WAITINGFORPHONE which I would have expected. Once the phone call is ended ConnMgrConnectionStatus returns CONNMGR_STATUS_CONNECTED once again.
Any ideas as to what is happening?
Thanks.

Related

GSM modem port

Which port should I open for GSM modem?
I remember someone had posted the port allocation for different device before. Can someone shares that information again?
thanks,
- David :shock:
Code:
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HANDLE hCom;
char * xpos;
char rsltstr[5];
DWORD CellId;
int bufpos;
DCB dcb;
COMMTIMEOUTS to;
DWORD nWritten;
DWORD event;
DWORD nRead;
static char outbuf[20], buf[256];
BYTE comdevcmd[2]= {0x84, 0x00};
hCom= CreateFile(L"COM2:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
hCom= NULL;
return -1;
}
/* HANDLE hRil= CreateFile(L"RIL1:",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hRil==NULL || hRil==INVALID_HANDLE_VALUE)
{
hRil= NULL;
return -1;
}
*/
if (!GetCommState(hCom, &dcb))
{
return -2;
}
dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;
if (!SetCommState(hCom, &dcb))
{
return -3;
}
if (!EscapeCommFunction(hCom, SETDTR))
{
return -4;
}
if (!EscapeCommFunction(hCom, SETRTS))
{
return -5;
}
if (!GetCommTimeouts(hCom, &to))
{
return -6;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(hCom, &to))
{
return -7;
}
if (!SetCommMask(hCom, EV_RXCHAR))
{
return -8;
}
DWORD rildevresult=0,nReturned=0;
// DeviceIoControl(hRil, 0x03000314L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// HANDLE Ev=CreateEvent(NULL,TRUE,0,L"RILDrv_DataMode");
// SetEvent(Ev);
if (!DeviceIoControl (hCom,0xAAAA5679L, comdevcmd, sizeof(comdevcmd),0,0,0,0))
{
return -9;
}
bufpos = 0;
strcpy(outbuf,"AT+creg=2\r");
if (!WriteFile(hCom, outbuf, 10, &nWritten, NULL))
{
return -10;
}
if (nWritten != 10)
{
return -11;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -12;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -13;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
strcpy(outbuf,"AT+creg?\r");
if (!WriteFile(hCom, outbuf, 9, &nWritten, NULL))
{
return -14;
}
if (nWritten != 9)
{
return -15;
}
if (!WaitCommEvent(hCom, &event, NULL))
{
return -16;
}
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -17;
}
if (nRead == 0)
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
puts(buf);
rildevresult = 0;
// DeviceIoControl(hRil, 0x03000318L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0);
// ResetEvent(Ev);
// CloseHandle(Ev);
// CloseHandle(hRil);
if (!EscapeCommFunction(hCom, CLRDTR))
{
return -4;
}
if (hCom!=NULL)
{
CloseHandle(hCom);
hCom= NULL;
}
return CellId;
}
the commented lines force RIL to shut up and not send its commands to modem.
To communicate with modem you should open COM2, set 115200/8/N/1, send ioctl 0xAAAA5679.
I had problems when reading data from modem. When it sends a huge block (for example an output to AT%VER command) some bytes are lost and other are changed to garbage. Maybe this is a hardware problem in my imate, because the same program worked on Rover S1 without bugs.
P.S. The code I've posted is taken from this forum.
Post subject: Re: GSM modem port
Thanks for information. I am using iMate too.
Indeed the returned data are very strange. I actually had failure for "EscapeCommFunction(hCom, SETRTS)".
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
- David
Re: Post subject: Re: GSM modem port
davidchu2000 said:
Did you try to dial with a number?
I got "NO CARRIER" while issing a ATD command.
Click to expand...
Click to collapse
I use TAPI functions to establish a data call. I don't think that you can use COM1 for ATD commands and receive data after connection. Internally COM9 is used after data connection is established. But I've successfully used "ATDnumber;" to make a call. Though it is much easier to use SHMakeCall function.
Hi mamaich,
I have to port a modem application for data transfering.
I can make a call using ATD through com2. Are you saying that I cannot use the same port for data communication?
I have to use COM9 instead?
- David
I don't know. You should test this yourself. For some reason TAPI or RIL opens COM9 after data connection.
Are you able to answer a data call by listening to com2? (or thru TAPI)
- David
I answer call through TAPI without problems. You should kill cprog.exe application on the incoming data call so that it does not popup.
Is anyone experience with pick a call? I can make a call but my program couln't detect an incoming call (when dialing with DATAMODEM using TAPI).
Best regards,
A. Riazi
To receive data call you should terminate cprog.exe. Look into cryptophone source code for more information.
I didn't see any code for terminating cprog.exe, only I saw one line of code to hide "Incoming call..." window. Would you please say in which source of the CryptoPhone, they did this?
Best regards,
A. Riazi
I keep refering back to this topic, wishing I were clever enough to make the XDA modem visable under C# - but I have failed miserably!
Has anybody managed to this, either by talking to COM2: or by using TAPI? All I want is to establish a data call (NOT IP!) for a POS application.
I would worship the ground you walk on if you can help me over my blockage!
Can someone explain how TAPI is implemented to do data calls ??? I am programming in MFC / eVC++ ... Thanks for ur help guys !!!
Which TAPI function do u use to establish a data call ??? is there anywhere i can get the list of all of them ?? cheers guys

Make Option for Today Plugin ?

I made a Today Plugin with option to change the heigh. It run OK when I make option in Today seting. But I want to show option dialog by tap in to my Today Item and change Option from that.
There is the code in WndPro
//Our main WndProc. Does everything after initialization.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_TIMER:
//Recalculate and paint the time for the count down.
TimeUpdate(hWnd);
return TRUE;
case WM_ERASEBKGND:
//We return true here since we handle our own background painting.
return TRUE;
case WM_TODAYCUSTOM_CLEARCACHE :
//We have no cache to clear so we ignore this message.
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
//If the cyp member is set to 0 then you must set it to your windows height.
//This makes sure the shell gives you a certain amout of room for your painting.
if (g_bDayView)
{
g_ItemHeight = 26;
}
if (g_bMonthView)
{
g_ItemHeight = 105;
}
if (g_bClockView)
{
g_ItemHeight = 100;
}
//g_curTime = 0;
if (((TODAYLISTITEM*)wParam)->cyp == 0)
{
((TODAYLISTITEM*)wParam)->cyp = g_ItemHeight; //the shell draws a line at the bottom of our window.
return 1;
}
break;
case WM_PAINT:
//Paint like you would in any other application.
hdc = BeginPaint(hWnd, &ps);
PaintAll(hWnd, hdc);
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONUP:
g_stylusPt.x = LOWORD(lParam); g_stylusPt.y = HIWORD(lParam);
if((g_stylusPt.x < 32)&&(g_stylusPt.y < 32))
DialogBox(g_hInstance, (LPCTSTR)IDD_TODAY_CUSTOM, hWnd, (DLGPROC)CustomItemOptionsDlgProc);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Click to expand...
Click to collapse
And there is the code in Custom Dialog
BOOL WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
SHINITDLGINFO shidi;
HWND hCurrentRadioButton;
switch (message)
{
case WM_INITDIALOG:
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
// select both as the radio button default
if(!g_bUserSet)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_MONTH_VIEW, IDC_DAY_VIEW);
}
// determine what the current config is and preserve it
else
{
if(g_bDayView)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_MONTH_VIEW, IDC_DAY_VIEW);
}
if(g_bMonthView)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_DAY_VIEW, IDC_MONTH_VIEW);
}
if(g_bClockView)
{
CheckRadioButton(hDlg, IDC_DAY_VIEW, IDC_MONTH_VIEW, IDC_CLOCK_VIEW);
}
}
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
// check to see if both is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_DAY_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = TRUE;
g_bMonthView = FALSE;
g_bClockView = FALSE;
}
// check to see if only program is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_MONTH_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = FALSE;
g_bMonthView = TRUE;
g_bClockView = FALSE;
}
// check to see if only storage is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_CLOCK_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = FALSE;
g_bMonthView = FALSE;
g_bClockView = TRUE;
}
g_bUserSet = TRUE;
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
Click to expand...
Click to collapse
It shows Dialog, change all value of variable. But the Today Item's is not change.
Could anyone tell me how to do.
Thanks
Try this...
Instead of your line:
Code:
if (((TODAYLISTITEM*)wParam)->cyp == 0)
check for cyp not being set to desired height (g_ItemHeight), i.e.:
Code:
if (((TODAYLISTITEM*)wParam)->cyp != g_ItemHeight)
That should work for you.
It works OK
Thank you very, very much
nncuong said:
It works OK
Thank you very, very much
Click to expand...
Click to collapse
My pleasure

WM6 - how to Query WLAN "connection" status

I am desperately trying to work around some unknown problem caused by our NDIS IM driver on WM6 and HTC TyTn ( TyTn at least, but most likely other devices as well ). I started some other threads regarding different facets of this problem, and no help is coming. Now I am just trying to work around it.
in short the problem is when power events happen the WLAN will never connect.
The work around is programmatically open the control panel with STControlPanel class and press the down button 1 time then the f1 key ( right dash ). This "presses connect" on the last configured access point. This works around my problem, however, I need to detect when the access point has connected. There is a "connecting" and "connected" message for the access point in this control panel dialog ( control panel # 17 ).
My Question: Is there some way to get this text "connecting" or "connected" from the control panel #17?
I have tried wzc, ndisuio, winsock, and other "non control panel" ways to detect connected state, but the IM problem fools all these methods. The only thing I have ever seen that successfully shows when the problem has occurred is the "connecting"/"connected" status in the control panel 17.
Please Help Someone.
p.s. If I can get this worked around, we sell a commercial grade ndis intermediate driver toolkit letting you easily write plugins without any of the hard driver details. We have redirectors, transparent proxy, tunnelers, virtual adapters, lots of good stuff. Also the same plugin will work on all windows desktop platforms vista - 98, WM5/6 and CE and also linux and solaris...
Hello skk
What about notification API?
Here is the solution (simple concept) for Your problem. Interesting parts are in bold.
SNapiTest.cpp
Code:
#include "stdafx.h"
#include "SNapiTest.h"
#include <windows.h>
#include <commctrl.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
[b]
const DWORD WM_WIFISTATUS = WM_USER + 1;
bool g_connecting;
bool g_connected;
HREGNOTIFY g_hNotify;
HREGNOTIFY g_hNotify2;
[/b]
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SNAPITEST));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SNAPITEST));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SNAPITEST, szWindowClass, MAX_LOADSTRING);
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
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)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
[b]
g_connecting = false;
g_connected = false;
{HRESULT hr = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTING_PATH, SN_WIFISTATECONNECTING_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify);}
{HRESULT hr2 = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTED_PATH, SN_WIFISTATECONNECTED_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify2);}
[/b]
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
[b]
case WM_WIFISTATUS:
{
DWORD newValue = (DWORD) wParam;
WCHAR caption[] = L"Wifi Status";
if ((newValue & SN_WIFISTATECONNECTED_BITMASK) == SN_WIFISTATECONNECTED_BITMASK)
{
if (!g_connected)
{
g_connected = true;
g_connecting = false;
MessageBox(hWnd, L"Connected!!", caption, MB_OK);
}
break;
}
if ((newValue & SN_WIFISTATECONNECTING_BITMASK) == SN_WIFISTATECONNECTING_BITMASK)
{
if (!g_connecting)
{
g_connecting = true;
g_connected =false;
MessageBox(hWnd, L"Connecting...", caption, MB_OK);
}
}
break;
}
[/b]
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
[B]
RegistryCloseNotification(g_hNotify);
RegistryCloseNotification(g_hNotify2);
[/B]
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// 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);
}
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;
}
return (INT_PTR)FALSE;
}
Needed includes:
// TODO: reference additional headers your program requires here
#include <snapi.h>
#include <regext.h>
snapi.h
Thank you so much for your post. I just found snapi.h, I assume this is snapitest.h?
IT WORKS!
It works! You are my hero RStein. You are a god among men.
Great. ) Thanks for sharing the results.

[Q] How to call an mothod from another class using an service

Hello xda,
I have the following code into the MainActivity to figure out the orientation of the device:
Code:
public int getScreenOrientation() {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int orientation=0;
// if the device's natural orientation is portrait:
if ((rotation == Surface.ROTATION_0
|| rotation == Surface.ROTATION_180) && height > width ||
(rotation == Surface.ROTATION_90
|| rotation == Surface.ROTATION_270) && width > height) {
switch(rotation) {
case Surface.ROTATION_0:
//orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
Toast.makeText(getApplicationContext(),"portrait",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_90:
Toast.makeText(getApplicationContext(),"landscape",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_180:
Toast.makeText(getApplicationContext(),"reverse portrait",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_270:
Toast.makeText(getApplicationContext(),"reverse landscape",Toast.LENGTH_SHORT ).show();
break;
default:
Toast.makeText(getApplicationContext(),"portrait",Toast.LENGTH_SHORT ).show();
break;
}
}
// if the device's natural orientation is landscape or if the device
// is square:
else {
switch(rotation) {
case Surface.ROTATION_0:
Toast.makeText(getApplicationContext(),"landscape",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_90:
Toast.makeText(getApplicationContext(),"portrait",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_180:
Toast.makeText(getApplicationContext(),"reverse landscape",Toast.LENGTH_SHORT ).show();
break;
case Surface.ROTATION_270:
Toast.makeText(getApplicationContext(),"reverse portrait",Toast.LENGTH_SHORT ).show();
break;
default:
Toast.makeText(getApplicationContext(),"landscape",Toast.LENGTH_SHORT ).show();
break;
}
}
return orientation;
}
I created an service that runs in background and overrided OnConfigurationChanged so that i can call getScreenOrientation whenever the device orientation is changed.
I tried to call the method using, but the app crashes:
Code:
MainActivity main = new MainActivity();
main.getScreenOrientation();
I tried to implement getScreenOrientation right in the service class but it says "Cannot resolve method getWindowManager()"
Can someone help me out? Or is any other way I can accomplish this?
Thanks!!
Try using this to get it directly from your service:
Code:
window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
zalez said:
Try using this to get it directly from your service:
Code:
window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Click to expand...
Click to collapse
thanks!! It worked flawlessly...Although it's strange that I can't call the method...

Radiogroup and radiobutton selection in ExpandableListView

i've an ExpandableListView, where i can select different radiobutton choice in a radiobuttongroup. My problem: not all radiobuttons are selected...the behaviour is random.
this is my code
Code:
void prepareMainList(String data)
{
Document doc;
NodeList nl;
newsNotificationData = new ArrayList<Map<String, String>>(); //set this struct in other case
groupData = new ArrayList<Map<String, String>>();
childData = new ArrayList<List<Map<String, String>>>();
if ((data.compareTo("") != 0) && (data != null) )
{
doc = parser.getDomElement(data); // getting DOM element
nl = doc.getElementsByTagName(KEY_GROUP);
categoryList = new HashSet<CategoryClass>();
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++)
{
// creating new HashMap
Map<String, String> curGroupMap = new HashMap<String, String>();
Map<String, String> curNewsMap = new HashMap<String, String>();
Element el = (Element) nl.item(i);
CategoryClass myCat = new CategoryClass();
myCat.id = parser.getValue(el, "id");
myCat.name = parser.getValue(el, KEY_NAME);
myCat.subCategory = new HashSet<TournamentClass>();
// adding each child node to HashMap key => value
curGroupMap.put(CATEGORY, parser.getValue(el, KEY_NAME));
Log.d("test", "category id added: " + myCat.id);
// adding HashList to ArrayList
groupData.add(curGroupMap);
//notification
curNewsMap.put("CID_" + myCat.id, getValueFromCategory(myCat.id));
newsNotificationData.add(curNewsMap);
NodeList ls = el.getElementsByTagName("girone");
//Log.d("test", "getDataFromWebService get children count : " + ls.getLength());
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < ls.getLength(); j++)
{
Element elc = (Element) ls.item(j);
Map<String, String> curChildMap = new HashMap<String, String>();
TournamentClass myTournament = new TournamentClass();
myTournament.id = elc.getAttribute("id");
myTournament.name = parser.getValue(elc, KEY_CHILD_NAME);
curChildMap.put(TOURNAMENT, parser.getValue(elc, KEY_CHILD_NAME));
children.add(curChildMap);
myCat.subCategory.add(myTournament);
//notification
curNewsMap.put("TID_" + myTournament.id, "-1");
newsNotificationData.get(i).put("TID_" + myTournament.id, getValueFromTournament(myTournament.id));
}
childData.add(children);
categoryList.add(myCat);
//newsNotificationData.add(curNewsMap);
}
}
catList = (ExpandableListView) findViewById(R.id.expandableSettings);
catList.setClickable(true);
catList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Log.d("test", "GROUP PRESSED");
return false;
}
});
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
R.layout.settings_header,
new String[] { CATEGORY, TOURNAMENT },
new int[] { R.id.settingsCatTitle, android.R.id.text2 },
childData,
R.layout.settings_child,
new String[] { CATEGORY, TOURNAMENT },
new int[] { android.R.id.text1, R.id.settingsSubTitle }
){
@Override
public View getGroupView (final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
//final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
//Log.d("test", "get tournament selected");
TextView tv = (TextView)v.findViewById( R.id.settingsCatTitle );
String catSel = tv.getText().toString();
//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);
RadioGroup groupNN;
// *** Gestisce l'header della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN);
groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Header chk", "id" + checkedId);
if(!isDataLoaded) return;
for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}
//-----change data to send
String notifValue = "0";
//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;
case R.id.button_Notif:
notifValue = "1";
break;
case R.id.button_All:
notifValue = "2";
break;
case R.id.button_no:
notifValue = "-1";
break;
default:
break;
}
//set graphics on selected radio button
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
//radio.setTextSize(30);
// Marco Moscatelli 28/11/2013 - imposto il check a true
//radio.setChecked(true);
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}
updateNewsNotificationCenter(groupPosition, myCat.id, null, notifValue);
isDataLoaded = false;
//Log.d("test", "------END SET CATEGORY------- ");
}
});
//-----data to send changed
isDataLoaded = false;
//set default schema
//String defaultbtnValue = null;
String defaultbtnValue = newsNotificationData.get(groupPosition).get("CID_" + myCat.id);
//Log.d("test", "check current cat id : "+ myCat.id);
RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
if (defaultbtnValue == null)defaultbtnValue = "-1";
switch(Integer.parseInt(defaultbtnValue))
{
case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;
case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;
default:
break;
}
//set default button
for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}
if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);
}
return v;
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
Log.d("test", "getChildView");
RadioGroup groupNN;
// *** gestisco i gironi della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN_child);
//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);
Map<String, String> childName = childData.get(groupPosition).get(childPosition);
final TournamentClass myTournament = getTournamentFromName(groupName, childName.get("TOURNAMENT"));
groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Item chk", "id" + checkedId);
if(!isDataLoaded) return;
Log.d("test", "------INIT SET TOURNAMENT------- : " + myTournament.id);
for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);
}
//-----change data to send
String notifValue = "0";
//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;
case R.id.button_Notif:
notifValue = "1";
break;
case R.id.button_All:
notifValue = "2";
break;
case R.id.button_no:
notifValue = "-1";
break;
default:
break;
}
//Get Tournament and keep id of it...after save notification mode in a struct and send all on POSTS
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
// Marco Moscatelli 28/11/2013 - Imposto il check a true
//radio.setChecked(true);
//group.check(radio.getId());
// end
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}
//prepare data
updateNewsNotificationCenter(groupPosition, myCat.id, myTournament.id, notifValue);
Log.d("test", "------END SET TOURNAMENT------- ");
}
//}
});
//set default schema
String defaultbtnValue = newsNotificationData.get(groupPosition).get("TID_" + myTournament.id);
RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
if (defaultbtnValue == null)defaultbtnValue = "-1";
switch(Integer.parseInt(defaultbtnValue))
{
case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;
case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;
}
for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);
}
//set default schema
if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);
}
//isDataLoaded = true;
return v;
}
thanks in advance

Categories

Resources