Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Detect foreground application when typing

Detect foreground application when typing

Put your problem here if it does not fit any of the other categories.

Detect foreground application when typing

Postby marthijnh » Tue Feb 22, 2011 9:43 am

Hi all,
I'm developing my own keyboard (basically a modification of com.android.inputmethod.latin), and I want to store the application name in which the user is typing. I found a solution to detect the visible application, but unfortunately it's always the keyboard application since it's on top.
Any ideas?
marthijnh
Freshman
Freshman
 
Posts: 5
Joined: Tue Feb 22, 2011 9:35 am

Top

Re: Detect foreground application when typing

Postby blundell » Thu Feb 24, 2011 11:18 pm

Could you post your solution code? And we could see if we can fix it
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Detect foreground application when typing

Postby marthijnh » Fri Feb 25, 2011 10:53 am

This is de code I have for detecting the foreground application:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public String getActiveProgramName()
  2.     {
  3.         ActivityManager activityManager = (ActivityManager) this.getSystemService( Context.ACTIVITY_SERVICE );
  4.         List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
  5.         for(RunningAppProcessInfo appProcess : appProcesses){
  6.             if(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE){
  7.                 Log.d("Foreground App", appProcess.processName);
  8.                 return appProcess.processName;
  9.             }
  10.         }
  11.         return "";
  12.     }
  13.  
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


It always returns the name of the keyboard application since it's on top. I already tried to call this function in the function that display the keyboard, but I think the process context is already switched to the keyboard application..
marthijnh
Freshman
Freshman
 
Posts: 5
Joined: Tue Feb 22, 2011 9:35 am

Re: Detect foreground application when typing

Postby blundell » Fri Feb 25, 2011 1:49 pm

Have you tried the other constants like IMPORTANCE_FOREGROUND & IMPORTANCE_PERCEPTIBLE?

You would think IMPORTANCE_VISIBLE would return two results. Not just one. Have you tried doing this:
Code: Select all

public String getActiveProgramName()
    {
      String result = "";
        ActivityManager activityManager = (ActivityManager) this.getSystemService( Context.ACTIVITY_SERVICE );
        List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
        for(RunningAppProcessInfo appProcess : appProcesses){
            if(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE){
                Log.d("Foreground App", appProcess.processName);
                result += appProcess.processName + "|";
            }
        }
        return result;
    }

User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Detect foreground application when typing

Postby marthijnh » Fri Feb 25, 2011 2:16 pm

Thanks for your answer. IMPORTANCE_VISIBLE always returns one result, but I see IMPORTANCE_FOREGROUND returns more results including the program name I'm looking for. It looks like the active program is always the last entry in the process list. I think this is suitable for my application, thanks!
marthijnh
Freshman
Freshman
 
Posts: 5
Joined: Tue Feb 22, 2011 9:35 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], MSNbot Media and 12 guests