Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling NSApplication -hideOtherApplications from Java JNI not working.



I am trying to get a simple native Cocoa API method to work via JNI. I want to try to hide all other applications.

I seem to have two choices, by calling -hideOtherApplications on either NSApplication or NSWorkspace. But neither seems to be working for me.

I'm calling them from a JNI native method, called from a Java class. Here's my Java class:

public class ApplicationTesting
{
    public native void hideOtherApps();


public static void main(String[] args) { final ApplicationTesting app = new ApplicationTesting(); app.hideOtherApps(); }

static
{
System.loadLibrary("StringProcessing"); //all libraries in this test package are included in this
}


}

My native method is :

JNIEXPORT void JNICALL Java_ApplicationTesting_hideOtherApps(JNIEnv *env, jobject ojb)
{
//test one : can we get a reference to an NSApplication?
NSApplication *app = [NSApplication sharedApplication];
if (app == nil || app == NULL)
{
printf("NSApplication object is nil\n");
return;
}


//show some info on the app
BOOL isActive = [app isActive];
printf( (isActive == YES) ? "app is active\n" : "app is NOT active\n" );


BOOL isRunning = [app isRunning];
printf( (isRunning == YES) ? "app is running\n" : "app is NOT running\n" );


BOOL isHidden = [app isHidden];
printf( (isHidden == YES) ? "app is hidden\n" : "app is NOT hidden\n" );


//try to hide other apps
printf("Calling hideOtherApplications\n");
[[NSApplication sharedApplication] performSelectorOnMainThread:@selector(hideOtherApplications:) withObject:NULL waitUntilDone:NO];
[[NSWorkspace sharedWorkspace] performSelectorOnMainThread:@selector(hideOtherApplications) withObject:NULL waitUntilDone:NO];
}


running my Java main() from the Terminal app (command line) results in this output:

app is NOT active
app is running
app is NOT hidden
Calling hideOtherApplications


but alas, no other apps actually get hidden.

What might I be doing wrong?

Thanks,

Rob Ross, Lead Software Engineer
E! Networks
email@hidden
---------------------------------------------------
"Beware of he who would deny you access to information, for in his heart he dreams himself your master." -- Commissioner Pravin Lal





_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.