Java Android Runtime.getRuntime().exec() - java

I'm working on an app where I want to run an android shell command using:
Process process = Runtime.getRuntime().exec("input keyevent 85");
This should start/stop the music player for me, and it works when I'm currently on my app.
The way I do it is to set a prepared intent beforehand at a certain time, so I can have the music playing in a few minutes.
However, it doesn't work when I have the app running in the background. The intents do print out my Log.i messages in Logcat, so I'm not sure where the problem lies. Perhaps it is a permission problem?

Turns out, using this method, the APK would have to be signed, the device rooted and the APP be placed in the directory of system apps.

Related

Send text strings from Android application/plugin to Unity application

I need to add non-Google offline voice control capability to a Unity3D project. I have started with snips.ai and successfully built an Android app following their tutorial and modified it to output the understood intent from snips to a text box on screen. What I really need is to get this text string to send to my Unity application.
I think I should be building a native Android Java plugin for Unity which will start at runtime and listen for voice commands. Every time it gets a listen event I need it to send a string of the captured intent to the Unity project which is always waiting for these strings.
I know I can use something like this https://gist.github.com/markcastle/a1530efd5278607862fec09df89e59db to make a static call to a native plugin, but I want to basically have Unity listening constantly to the plugin for strings which it can interpret.
Any help, as always, is much appreciated!

How can I make my program keep working in the background?

I can't really show anything here I think.
It's not a problem in my code I think.
What I mean is when I'm running my program directly from my android device, or when it's connected to the USB on my PC through android studio in debug mode, or regular running in all cases when my program is running and then I open a new app on my phone or if I just move to the whatsapp to type something when I want to get back to my program I see it was close. And I need to run the program over again.
How can I keep my program to be running all the time in the background so I can get back to it and no need to run it over again?

How to programmatically check build.prop to verify model

I have an app I'm currently working on based on the HTC Open Sense SDK for android. However my biggest problem is keeping up with the device checker through the Google Play dev console to only allow certain devices to download the app. My biggest reason is that people will rate my app so low on the scale and say it sucks, but the problem is that they don't read the requirements - if you use an Lg G2 to try and launch an app made for an HTC ONE that requires Sense, it's going to crash.
So, how would i go about building a helper class that would check the device's model via build.prop (without needing root privileges) before opening/starting the main activity, and give the user a notification if the device was incapable of launching the app, and with devices that are capable of launching it, just continue the process of opening the app?

Android and PC Communication over USB: What is a safe directory that I can use ADB push/pull on and access from an Android app?

I am writing an application that will allow an android phone and java application on the computer to communicate over the USB cable. Using Bluetooth or Wifi is not an option in this case.
I found it very difficult to find a nice solution to this problem, and the Host/Accessory libariries seemed designed to hook the phone up to docks/cameras/circuitboards rather than simply a PC. This is my solution, let me know if there are better alternatives:
I'm going to create a Java application to use ADB to push files onto the phone, the phone will then check those files for changes and act accordingly.
It seems to work well so far, except I am using the /sdcard/ folder to hold these files. I want this app to work on phones without SD cards too, so I want to know if there is some other safe folder that I can count on being able to access from the PC with ADB and the android app as well.
(I have looked at INTERNAL STORAGE libraries, but I don't know where they store their data and if I can push/pull with them from ADB.)
Thanks in advance for any help!
Read this https://groups.google.com/forum/?fromgroups#!topic/android-developers/tZrxqZQLh98
Nice discussion about holding tmp files.
Do u want to control your application from PC? Cant you use Intents launched by ADB for that?
Another options port forwarding over USB with ADB:
adb forward tcp:6100 tcp:7100
adb forward tcp:6100 local:logd
Personally I end-up doing GET requests to my local Apache server to fetch data.
Or on rooted device many folders become available.

Closing application in Android - delay

I programmed a button into my android app that called the finish() method when I click it. But somehow it does not close until after a 5-6 second delay.
I am recording sensor values for a particular movement of the phone. The problem is when there is a delay after I close, it records those unnecessary values and the analysis is messed up.
So any idea why the UI takes so long to respond? I am very new to Android and I can't find this online. I don't do too much computation- as and when sensors change I record the value onto a file in the sdcard memory. Sometimes if I run the program for too long, it just crashes and I don't know why.
Please help! I would also like to know if there's a manual way to kill through the computer? something like Ctrl+C for DOS?
Is there a keyboard shortcut to close a running Android application?
There is no concept in Android of "close a running Android application".
The Esc key in the emulator behaves as the BACK button to (typically) close the current activity.
I have a button that I use to kill the application in my phone and that has a huge delay.
No, you don't.

Categories