How to check that no one app is recording audio?
public void playerUpdate(Player arg0, String arg1, Object arg2)
{
add(new RichTextField(formattedDate + ": " + arg1 ));
}
this function and p.getState() returns the state of current application player only.
You can call prefetch() which will throw a MediaException if any other application is using the player already
Related
I'm trying to use the twitter4j API to get the stream of tweets on a specific topic.
This is my code:
TwitterStream twitterStream = inizialize();
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
System.out.println(status.getUser().getName() + " ====> " + status.getText());
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
public void onException(Exception ex) {
ex.printStackTrace();
}
#Override
public void onScrubGeo(long userId, long upToStatusId) {
// TODO Auto-generated method stub
}
#Override
public void onStallWarning(StallWarning warning) {
// TODO Auto-generated method stub
}
};
FilterQuery filterQuery = new FilterQuery("GAME");
twitterStream.addListener(listener);
twitterStream.filter(filterQuery);
twitterStream.sample(); // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
}
The stream of tweets works well, but I cannot set any query. So, I wonder, is it possible to do what I'm trying to?
Of course, the inizialize() returns a twitterStream configured with a valid oauth token.
You'll want to manually filter statuses coming from the stream. For example, if you want to show tweets that contains 'vanilla' only then you could approach like this in your onStatus:
public void onStatus(Status status) {
String statusText = status.getText();
if (statusText.toLowerCase().contains("vanilla")) {
System.out.println(status.getUser().getName() + " ====> " + statusText);
}
}
// Expecting a String[] of topics to track:
filterQuery.track(keywords);
// Within a bounding box of geo-coordinates:
filterQuery.locations(new double[][] {{lng1, lat1}, {lng2, lat2}});
// Specifies a language to track:
filterQuery.language("en");
// Number of previous statuses to stream before transitioning to the live stream:
filterQuery.count(10);
I want to check if string is a site or some words that should be searched using a search engine. For example when i use chrome
If i type google and press enter chrome searches the word using google as search engine
But if i type google.com it browses to site
Here i should check it. But how?
editText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
Can do better if uses 2 editText fields.
One for websites and another for google query.
While in that way :
answer to question 1 is
WebView webView=new WebView(Nameofthisactivity.this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl("https://www.google.co.in/search?q="+string);
answer to question 2 is
WebView webView=new WebView(Nameofthisactivity.this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl(string);
Hi friends i am trying to read incoming sms but getting warning like this . Invocation of questionable method: java.lang.String.(String) found in: mypackage.MyApp$ListeningThread.run()
Here is my code is
public class MyApp extends UiApplication {
//private ListeningThread listener;
public static void main(String[] args) {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp() {
invokeAndWait(new Runnable() {
public void run() {
ListeningThread listener = new ListeningThread();
listener.start();
}
});
pushScreen(new MyScreen());
}
private static class ListeningThread extends Thread {
private boolean _stop = false;
private DatagramConnection _dc;
public synchronized void stop() {
_stop = true;
try {
_dc.close(); // Close the connection so the thread returns.
} catch (IOException e) {
System.err.println(e.toString());
}
}
public void run() {
try {
_dc = (DatagramConnection) Connector.open("sms://");
for (;;) {
if (_stop) {
return;
}
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
String address = new String(d.getAddress());
String msg = new String(d.getData());
if(msg.startsWith("START")){
Dialog.alert("hello");
}
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.exit(0);
}
} catch (IOException e) {
System.err.println(e.toString());
}
}
}
}
Please correct me where i am wrong.Is possible give me some code to read incoming sms content in blackberry.
A few points about your code:
That invokeAndWait call to launch a thread makes no sense. It doesn't harm, but is kind of waste. Use that method only to perform UI related operations.
You should try using "sms://:0" as param for Connector.open. According to the docs, a parameter with the form {protocol}://[{host}]:[{port}] will open the connection in client mode (which makes sense, since you are on the receiving part), whereas not including the host part will open it in server mode.
Finally, if you can't get it working, you could use instead the third method specified in this tutorial, which you probably have already read.
The error you quoted is complaining about the use of the String constructor that takes a string argument. Since strings are immutable in Java-ME, this is just a waste. You can use the argument string directly:
Invocation of questionable method: java.lang.String.(String) found in: mypackage.MyApp$ListeningThread.run()
//String address = new String(d.getAddress());
String address = d.getAddress();
// getData() returns a byte[], so this is a different constructor
// However, this leaves the character encoding unspecified, so it
// will default to cp1252, which may not be what you want
String msg = new String(d.getData());
Here is some of the code in my midlet:
the addKeyListener method presents an error as the function is not recognized.
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
public class PhraZApp extends javax.microedition.midlet.MIDlet implements ActionListener{
public PhraZApp {
addKeyListener (new KeyPadListener());
}
protected void keyPressed(int key) {
System.out.println(key);
}
public void actionPerformed(ActionEvent evt) {
System.out.println(evt.getKeyEvent());
}
public final class KeyPadListener implements KeyListener {
public boolean keyChar(char key, int status, int time) {
return false;
}
public boolean keyDown(int keycode, int time) {
if (Keypad.KEY_ESCAPE == Keypad.key(keycode)) {
System.out.println("key: " + keycode);
return true;
}
//let the system to pass the event to another listener.
return false;
}
public boolean keyUp(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean keyRepeat(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean keyStatus(int keycode, int time) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
The keyPressed action is not heard by any of those listeners.
Ive been told to add the keylistner to a GUI component, but none that I try it with accept it.
Furthermore, one of the possible issues is that the addKeyListener method is not declared, but in that case I don't know how to declare it.
If i change extends javax.microedition.midlet.MIDlet to extends UiApplication, the addKeyListener becomes accepted but the entire midlet falls to a RuntimeErrorException.
How can I get my Midlet to hear the escape key? I have searched through many forums and none of the suggestions have worked so far.
Thanks in advance.
You need to create a LWUIT Command and assign it to the parent form using the setBackCommand method. You can handle the command event like you handle every other command in LWUIT. E.g. through a command listener or even just by subclassing it and overriding actionPerformed(ActionEvent).
Thanks to Shai pointing me in the right direction, I solved it.
Here is how I did it.
Command backCommand = new Command("",Keypad.KEY_ESCAPE);
form.setBackCommand(backCommand);
then
public void actionPerformed(ActionEvent evt) {
if (evt.getCommand().getId() ==Keypad.KEY_ESCAPE){
//execution code
}
I didn't try, but if I had included text in the command I imagine it would appear as such when I push the menu button. The important thing is that I finally got the MIDlet to hear out the escape button after MANY hours of trying and searching for solutions.
)
I'm newbie in programming and have problem.
My code:
choiceFieldANTYFM = new ObjectChoiceField("Wybierz stację(6)", new String[]{"Warszawa [96kb]"});
choiceFieldANTYFM.setChangeListener(this);
btnSelectantyfm = new ButtonField("Słuchaj!", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
btnSelectantyfm.setChangeListener(this);
stopplaying = new ButtonField("STOP", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
stopplaying.setChangeListener(this);
add(choiceFieldANTYFM);
add(btnSelectantyfm);
add(stopplaying);
and other:
public void fieldChanged(Field field, int context) {
if (field == btnSelectantyfm)
{
System.out.println("Selected item: " + Integer.toString(choiceField.getSelectedIndex()));
}if (field == btnSelect)
{
switch (choiceField.getSelectedIndex())
{
case 0:
try {
String url = "http://94.23.220.75:6000;deviceside=false;ConnectionUID=GPMDSEU01";
Player player;
player = javax.microedition.media.Manager.createPlayer(url);
player.start();
}
catch (Exception e) {
Dialog.alert(e.toString());
}
break;
Ok,When I push play it goes music in the application.
When push it again looped back. This is the second problem :)
I want to stop the stream when push stop button and even if it was possible to change the volume keys + and - :)
JDE 5.0 :)
Regards.
Rather than do btnSelectantyfm.setChangeListener(this); which would imply that your Screen is implementing FieldChangeListener declare separate FieldChangeListener objects for each button as follows:
btnSelectantyfm.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//start playing code here
player.start();
}
});
stopplaying.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//stop playing code here
player.stop();
}
});
Now you need to declare the Player object as a member variable so that the play and pause FieldChangeListeners can access it. To stop the Player playing just do player.stop().
For changing the volume when the volume keys are pressed you will need to:
Implement a KeyListener to perform actions when the side volume keys are pressed
Get the VolumeControl from the Player by doing player.getControl("VolumeControl");
Update the VolumeControl with the new desired volume