App won't close (Glass, Unity3d) - java

I have an Android Studio project, generated from a Unity3d Project.
I wanted to run my project on a Google Glass so I followed this tutorial (http://forum.unity3d.com/threads/how-to-build-for-google-glass.219558/).
Everything works fine so far, but I can't close the app via swipe down, even though I added this to the UnityPlayerActivity.java:
#Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){ finish(); }
return true;
}
Again, everything else works just fine.
1st UPDATE:
I tried the application on a tablet - like on the Glass, "Back"-button does not work.
Then I implemented this in Unity:
if(Input.GetKeyDown(KeyCode.Escape)){
Application.Quit();
}
Now it works on the tablet, but the Glass-situation did not change.
2nd UPDATE:
This also didn't work: this.finishAffinity();
3rd UPDATE:
I tried to close my Unity Application using this Coroutine in the Start()-Method:
IEnumerator waitAndExit(int sec)
{
yield return new WaitForSeconds(sec);
Application.Quit();
}
This successfully shuts down my application, so the problem appears to be this:
Unity does not recognize swiping down on Google Glass as a keyEvent in Input and the UnityPlayer object seems to get ALL input from android.
How can I stop that?I wan't to handle touchpad events with java, but my original idea - overriding onKeyDown - did not work.
4th Update:
I tried to recognize a gesture like in this answer and added this to my onCreate():
mUnityPlayer.setFocusable(false);
//mUnityPlayer.requestFocus();
Unfortunately it did not help.

This is not really a solution, but rather a work-around:
Using contextual voice commands works fine, even with the UnityPlayer-object blocking touchpad input.
I now close my app via "OK glass - quit".
If anybody figures out how to solve it properly - I'll test, verify and accept your answer.

Related

Android studio-java focus on listitem doesn't work

I'm trying to reverse engieering a Dialer from a 4.4.4 android device.
I added a onkeydown listener ,so when the user press the '9' button,the listview in the callLogActivity should scroll to top.
Of course I'm editing the smali files,not the java itself,but I'll attach a java code of everything I tried,which didn't give the desired result
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == 16) {
listview.requestFocus();
listview.setSelection(0);
listview.setSelectionAfterHeaderView();
listview.setItemChecked(0, true);
return true;
return super.dispatchKeyEvent(event);
}
}
As you can see,I tried many similar methods, such as setSelection() and setItemChecked() and more....
Actually,The list indeed scrolls to top,but the focus(selected) still stay on the current ListItem..
It's not just a visual effect problem,the focus really stay on the current item(you can see it when you just hit the "ok" button).
If you were wondering what's the meaning of "pressing the ok or '9' button" ,it's the time to expose that device model, it's the xiaomi qin 1s,a feature phone with android OS on it.
Did i miss something?

Yelp API on Android Studio

Been a lurker on this site to help find answers to some of my problems before, but I am currently stuck on this and could not find a recent solution. The closest answers I found to my problem were Yelp API Android Integration and Yelp Integration in Android
I tried following the steps in the 2nd link but they are a bit outdated. I have registered for an API, downloaded the jar files from the github and synced them, and made the YelpAPI.java and TwoStepOAuth.java files and removed the main method from YelpAPI. I am stuck on step 4 on the search part. I tried to call the queryAPI method from inside an onClick method I made for a button
public void getRandom(View view) {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
YelpAPI.YelpAPICLI yelpApiCli = new YelpAPI.YelpAPICLI();
new JCommander(yelpApiCli);
YelpAPI yelpApi = new YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET);
try {
YelpAPI.queryAPI(yelpApi, yelpApiCli);
} catch (JSONException e) {
e.printStackTrace();
}
}
Basically what I want this to do is, when the button is pressed, I want it to go to a second screen that will display what I query Yelp for. I haven't worked on that part yet, right now I just want to get a result back from Yelp. Keep in mind I am a complete noob at Android Studio and at most intermediate at Java.
Any help is greatly appreciated, it seems like its a really simple problem but its taking me forever to figure out on my own.
You can't do blocking task like downloading or image loading in android's Main thread (UI Thread). You can't block UI for more than 5 seconds. If you try it to block for more than 5 seconds than your app will stop working and display "Unfornutaley your app has stopped working" because of error too much work on main thread. So you need to make use of async task.

Android - How can a Service App dispatch KeyEvents to another Foreground App

I want to develop an Android Service app that dispatches KeyEvents to the foreground application.
Somehow, it would be like this
I cant seem to find a way how, I am only familiar with the activity dispatches KeyEvents to itself, like this:
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() == KEYCODE_1) {
// Do something
} else if (event.getKeyCode() == KEYCODE_2) {
// Do something
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
if (event.getKeyCode() == KEYCODE_1) {
// Do something
return false;
} else if (event.getKeyCode() == KEYCODE_2) {
// Do something
return true;
}
}
return super.dispatchKeyEvent(event);
}
but not with another App.
Correct me if I am wrong, according to what I have researched so far, it says that I need to install my application as a System App and send my keyevents directly to the android system, and the android system will be the one who will send it to the FOREGROUND App. Where it would look more like this:
If this is correct, could anyone help me how to do this? Or if otherwise, please give me a good workaround to achieve my goal. Thanks!
PS: It will be installed on a rooted device
You can definitely do this with root only and without installing your application as a system app.
The way this can be accomplished is by using uiautomator framework. This is such a powerful framework available for android with the purpose of black box testing applications.
Obviously you are going to use this framework for a slightly different purpose than black box testing, but that's ok.
UiDevice has the method pressKeyCode(int keyCode) that can be used like this to send input to whatever app happends to be in the forground:
UiDevice dev = UiDevice.getInstance();
dev.pressKeyCode(KeyEvent.KEYCODE_1);
The setup to use uiautomator can be a little complex, see this other answer of mine where I describe in more detail what you need to do.

LibGDX logging not showing up in logcat

I cannot get LibGDX logging to work in Android Studio. First i thought I had the same problem as my previous question but made sure my app updated on debug.
playButton.addListener(new ChangeListener()
{
#Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.debug("BUTTON", "playButton Pressed");
optionButton.addAction(Actions.moveBy(-200, 0, 2));
}
});
The test action on the option button is carried out but i cannot get the debug log to show up.
The default Log level is LOG_INFO. For the Gdx.app.debug call to work, you must first call Gdx.app.setLogLevel(Application.LOG_DEBUG); once (probably the first line in your Game's constructor so you can easily change it).
Use Gdx.app.log or even System.out.println (write sout (syso in eclipse) and enter );

Android Global KeyListener necessary?

I want my app to start, after the back button was pressed 3Times.
So I created this class which is executed in the Launcher.
public class KeyManager extends Activity {
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(KeyEvent == "Back key"){
Log.e("KM", "PRESSED!!!!!"+keyCode);
}
//return super.onKeyDown(keyCode, event);
return false;
}
}
This code works, if it s implemented in the launcher class, but it does not work, if the app is in the background. How or which key listener do I need for listening to background keys or more if the app is working only in the background?
This is not possible due security reasons. It's more likely a keylogger. If you really want to do that use an AccessibilityService which let you capture the KeyHooks even on a non-rooted Device. Warning: This is Dangerous and user must explizit enable it, to get it activated.
You may/can also modify the default keyboard, to capture those.
I want my app to start, after the back button was pressed 3Times.
You are welcome to download the Android source code, alter the operating system to contain this feature, compile it into a ROM mod, and install that ROM mod on your device.
Otherwise, what you want is not supported by Android.

Categories