How can I get the current input device in my application in java? I want to know is the remote or the game controller, that is being used.
It is an android application that I want to run on Amazon FireTV. Unlike the Amazon Kindle there is no touchscreen but you can use a remote or a game controller. I would like to know if it is possible to detect what kind of input device the user is currently using.
The code I have until now is a standard Cordova Application code, but when I know how to detect the current input device I would make a plugin to pass the value to the javascript code. That is not the problem.
As mentioned in the comments you should provide steps you have already taken or code you have already written to address this functionality as that will help us tweak the most appropriate answer.
As a general rule, you can look at the official docs to identify controllers on Fire TV.
https://developer.amazon.com/public/solutions/devices/fire-tv/docs/identifying-controllers
Basically, you need to write the identification code in your Cordova plugin as follows:
int hasFlags = InputDevice.SOURCE_GAMEPAD | InputDevice.SOURCE_JOYSTICK;
boolean isGamepad = inputDevice.getSources() & hasFlags == hasFlags;
This will allow you to find out if it's a gamepad. For a Fire TV remote the code you need is:
int hasFlags = InputDevice.SOURCE_DPAD;
bool isRemote = (inputDevice.getSources() & hasFlags == hasFlags)
&& inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC;
The InputDevice class is available on the Android developer site:
http://developer.android.com/reference/android/view/InputDevice.html
So you basically need to import that in your plugin class to ensure the above code works fine.
import android.view.InputDevice;
Related
I am working on a GUI application that uses JavaFX(not fxml) and exported as a JAR. For slow machine, impatient user click more than once on JAR, and multiple instances of application started.
I'm looking for a solution to let only one instance can be run at a time on a system and if the user clicks again while the application is running nothing happens. I think it's called singleton but don't know how to implement it.
You could try JUnique. It's an open source library doing exactly what you ask for. Import junique-1.0.4.jar to your project as a library. It's just 10kb file.
It's manual neatly describes how to implement it on a project. For a JavaFX application, implementation would look something like this:
Make sure to import these classes to your main
import it.sauronsoftware.junique.AlreadyLockedException;
import it.sauronsoftware.junique.JUnique;
public static void main(String[] args) {
String appId = "myapplicationid";
boolean alreadyRunning;
try {
JUnique.acquireLock(appId);
alreadyRunning = false;
} catch (AlreadyLockedException e) {
alreadyRunning = true;
}
if (!alreadyRunning) {
launch(args); // <-- This the your default JavaFX start sequence
}else{ //This else is optional. Just to free up memory if you're calling the program from a terminal.
System.exit(1);
}
}
One easy solution that I've used is, when you start the application, it creates a file (I named it .lock but you can call it whatever you want), unless the file already exists, in which case the application terminates its execution instead of creating the file.
You will need to bind your application with a resource. It can be a file, port etc.
You can change the code on startup to check if the file is locked. The below code will give you some idea
FileOutputStream foStream = new FileOutputStream("/tmp/testfile.txt");
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.lock();
If you'd properly package your JavaFX code as a real application instead of just throwing it into a jar, you might get that functionality for free and without all these hacks. If I package my JavaFX code on my Mac with the jpackage tool, the result will be a full featured macOS application. That means that when I double-click its icon somewhere several times, only one instance of the application will be started. This is the default behaviour on Macs and properly packaged JavaFX applications just stick to that rule too. I can't say however what the behaviour on Windows or Linux is because I currently don't have such a box running. Maybe someone who knows can add this as a comment.
I have built a simple app with Xcode 5, using very basic functions. As my app is going to have a large target audience, I want it to support different languages. I have done the translation part, but what I want is a view controller which displays language selection only the first time the app is opened. I am new to developing apps, so please explain me in detail. Thanks in advance.
Use NSUserDefaults to store data between app launches. You will need something like:
static NSString * const kShowIntroductionKey = #"ShowIntroductionKey";
- (void)showOnFirstLaunch
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL wasIntroductionShowed = [userDefaults boolForKey:kShowIntroductionKey];
if (!wasIntroductionShowed){
// Show your screen here!
[userDefaults setBool:YES forKey:kShowIntroductionKey];
[userDefaults synchronize];
}
}
Also may be it will be better to use native iOS localization mechanism.
I've seen how the GMOTE 2.0 runs on Android. The accessing of media files on computer is really cool and making them play makes it much cooler and the other features of it.
Now, I would like to make a program for android and for PC. What I want to make is like the GMOTE 2.0 but i only want the way it plays mp3 files over the PC. And my PC and Android is on the same newtork (same router).
Can someone give me advice on how this will be started and what would I be needing?
Please help me I don't know how will this be started. Is it possible communicating thru ports? (Like TCP?)
It shouldn't be difficult. Basically, you need to create two components:
Remote control driver: This application will be running on the computer. It should be able to do at least these things:
Export list of all songs. It depends on you, how sophisticated it should be. I would
suggest to export all songs from the computer in a XML. It may look like this:
<?xml version="1.0" encoding="UTF-8" ?>
<list>
<artist name="Fear Factory">
<album name="Demanufacture" year="1995">
<song name="Demanufacture" track="01" filename="C:\MyMusic\FearFactory\01. Demanufacture.mp3" />
<song name="Self-bias resistor" track="02" filename="C:\MyMusic\FearFactory\01. Self-bias resistor.mp3" />
</album>
</artist>
<artist name="Sybreed">
<album name="Slave design">
<song name="Bioactive" track="01" filename="C:\MyMusic\Sybreed\bioactive.mp3" />
</album>
</artist>
</list>
To generate such a list, you'll need to define path to some local folder(s). Now you
can go through the whole folder and read name of each file. Then you can use some
library and read ID3 tags (which contains name of the artist etc) from these files.
It should be very easy to generate this list.
Create an network interface, which will be listening on some TCP port and waiting for
commands. If it receive some command, it'll just proceed some action or send response.
You'll probably need these types of commands:
UPDATE_DATABASE: It will create XML as shown above and send it to your mobile
mobile phone.
PLAY_SONG: Receive full filename (as shown in the XML) and start playing of that
song in the background. There exists some libraries which can do this for you.
Example with Slick2D:
new Sound("some_music.wav").play();
It's automatically started in another thread, so you don't have to worry about
that. However, Slick2D is primary for game development, so it would be better to
look for something else.
Another possibility is to just start some media player (or console media player).
But I wouldn't recommend that as it will be much more difficult to control
whether the song is playing or not, or to pause it.
PAUSE_SONG
GET_CURRENT_SONG: It'll just look for the name of currently playing song and send
it back.
This application doesn't have to be graphical (but it'd be nice). The simplest and ugliest
version might be something like this:
public static void main(String args[]) {
TCPServer server = new TCPServer(999);
Sound sound = null;
for (;;) {
String command = server.accept();
if (command.equals("UPDATE_DATABASE)) {
// generate xml
server.sendData(xml.getRawContent());
} else if (command.equals("PLAY_SONG")) {
String filename = server.accept();
sound = new Sound(filename);
sound.play();
} else if (command.equals("PAUSE_SONG")) {
if (sound.playing()) {
sound.pause();
} else {
sound.play();
}
}
}
}
Most of classes I've used probably doesn't exist. Remember, that this is just a very
simplified example.
Application for mobile phone. And that's up to you. You'll need to create a
network client, which will be able to communicate with computer. It's simplest as it can be.
You'll just send something like "UPDATE_DATABASE" and receive some data as XML. Then
you'll use some library (probably DOM parser) and show list of songs to the user (it
may be also sorted into categories).
When user click to some song, it'll read it's filename (see that attribute in XML above).
And what's more easy than just send something like: "PLAY_SONG C:\MyMusic...."? Well,
maybe one thing - pausing the song. You'll maybe figure out by yourself how to do that.
:-)
That should be all. I hope I haven't forgotten something important.
I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.
I am developing an application in blackberry.The application has got list field items.So when i click any list-field item,it should open the default email client of the device,so that the person can share that item.Can anyone provide sample code for sharing item via email in blackberry?
It's pretty easy, actually. Call the Invoke.invokeApplication method, as shown in this example:
http://docs.blackberry.com/en/developers/deliverables/11935/Invoke_BB_device_software_app_565421_11.jsp
You can use this to make phone calls, open the calendar, etc.