hi,
i made an application to read sms.
my problem is to update a textview named txtMessaggio
from the class-reader.
the class is like "SmsReader extends BroadcastReceiver"
now i read the message and trow it on display via Toast.
ho i can put in txtMessaggio?
thanks
Related
Hi,
all my lack of Java knowledge is causing pain...
I need to create a listener that takes some actions (including releasing the player instance) after a audio/video clip has finished to playback.
In the Android Dev Guide (description of MediaPlayer class) I found the following:
the player engine calls a user supplied callback method, OnCompletion.onCompletion(), if a OnCompletionListener is registered beforehand via setOnCompletionListener(OnCompletionListener). The invoke of the callback signals that the object is now in the PlaybackCompleted state.
Then in my code i have:
...
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
...
MediaPlayer mp = MediaPlayer.create(this, R.raw.clip);
// Here i get a message that onCompClip cannot be resolved
...
mp.setOnCompletionListener (onCompClip);
mp.start();
...
public void onCompClip (MediaPlayer my_mp) {
...
my_mp.release();
}
Anybody can please explain what i do wrong?
Also, do is it better to always release the MediaPlayer instance before playing another clip?
Thanks in advance,
x70
Hello to all You developers out there.
I hope, that you can help me with understanding the Android Looper.
I have implemented a Service, which is intended to speak to a web Service and a database. This Service has a MainThread where it should do its work. I planned to communicate over Android Handler Objects. So I spend this Service two Handler: One for the Service and One for the Thread which is bound over the Android Looper
The MainThread Looks like this:
Sorry. The Forum seems to disallow me to post Source with the message: as a new user I'm not allowed to post links. But i don't have some in the initially post.
Anyway, let me describe my simple Thread.
It declares a handler which is instansiated in the overridden run Method between looper.prepare and looper.loop.
The it has a simple getHandler Method.
My question now is:
If I call the thread.start in the onCreate method of the Service, do the bloopers start infinitely looping like a while(true) statement? Or only if a message is passed through the handler which is my preferred behavior.
Do I have to use looped.quit to wait, because i don't found a activate method of the looper.
Am happy for any hint since the API for looper doesn't enlightened me
Code:
public class MainThread extends Thread{
private Handler looperHandler;
public MainThread(){
super();
}
@Override
public void run(){
Looper.prepare();
looperHandler = new Handler(){
@Override
public void handleMessage(Message message){
}
};
Looper.loop();
}
public Handler getHandler(){
return this.looperHandler;
}
public void stopThread(){
looperHandler.getLooper().quit();
}
}
Hmm I think if noone knows how this Android.Looper or the HandlerThread is working, how can my Service Communicate with my Activity without using IPC?
I need a simple CallBack from my Handler to my Activity.
The thing I try to do is, to get a Background Thread, which is not infinetly looping, but I can Activate it to do different work. After the work is finished my Service should be able to pass Message or Intent Objects.
I read the hole day Android API and know I'm completely lost.
please give me a hint.
hi everybody!
over the course of 30 years, i've developed software on a lot of hardware platforms and operating systems. so i'm not a noob by any means to programming.
BUT, with that said, my last years of development were on the windows mobile platform. i jumped to the android about 8 months ago with a Droid X. it's been great, but the developer bug in me wants to create something for the droid...
i've spent 2-3 months reading about android development and working my way through several great development books ("Hello Android," The Pragmatic Programmers).
Do any of you have any examples of implementing a timer? i want to create a unique clock as a live wallpaper and i need to setup a 1 second timer that upon completion asynchronously informs another thread to begin processing. there is just so much development data on the web that i'm drowning in it!!!!
any help, pointers, and/or web-site references would be greatly appreciated.
thanks a lot,
marvin
Hi. I'm like you; I've been a C/C++ developer and worked with various hardware (mostly microcontrollers) for 20+ years. I've only recently gotten into java.
Here's a sample I wrote for someone a while back to demonstrate a timer. It isn't quite what you're looking for, but it should be adaptable to your situation.
It creates an activity, then uses a timer task to countdown from 10 to 0 and sends messages to a handler to updates the title of the app to reflect this.
Code:
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class MyTestTimerActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Timer t=new Timer();
t.scheduleAtFixedRate(mTimerTask,1,1000);
}
Handler mHandler=new Handler(){
public void handleMessage(Message msg){
switch(msg.what){
case 0:
setTitle("hello_"+msg.arg1);
break;
case 1:
setTitle("timer_"+msg.arg1);
break;
}
super.handleMessage(msg);
}
};
protected TimerTask mTimerTask=new TimerTask(){
private int count=10;
private Message msg;
@Override
public void run(){
msg=mHandler.obtainMessage(0);
msg.arg1=count;
msg.sendToTarget();
count--;
if(count==-1){
cancel();
}
}
};
Thanks Gene. i'll study what you wrote and work it in as i can.
i spent 15 years writing asynchronous driver software on various VAX/VMS computers. it was so easy to do this task (sigh).
the problem i'm having with learning java, android SDK, and all is that is seems like i'm going around in circles reading about the various ways to do this task. and then i get confused with doing it on java or via xml.....whew. reminds me of the early days of my career.
thanks again.
I want to develop an application through which if the caller calls you, the call should be answered automatically without user's involvement and the caller could hear a pre-recorded voice which is already recorded and saved.The audio file should be in .wav format.I searched for help in google but i came to know that it is not possible in Android but there are some android applications which have the same functionality.So i think there is some possibility for this.Excuse me if the question is wrong.I would be grateful if some one help me.I am using eclipse Helios with ADT Plugin. I've tried the below code but it didn't work out.If someone know the answer please help me out. I've used broadcast receiver to read the phone state changes.In CALL_STATE_OFFHOOK, i wrote the following code.
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(context, "Call Picked..", Toast.LENGTH_LONG) .show();
Log.d("received", "Call Picked....");
final MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.music_file);
mPlayer.setAudioStreamType(AudioManager.STREAM_VOI CE_CALL);
mPlayer.prepareAsync();
mPlayer.start();
mPlayer.setOnErrorListener(new OnErrorListener() {
@override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method
mPlayer.reset();
return true;
}
});
AudioManager am=(AudioManager)context.getSystemService(Context. AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(false);
am.setMicrophoneMute(true);
Log.d("in call","sent audio");
mPlayer.reset();
mPlayer.release();
break;
thanks in advance
I have a doubt.
I read this example where the ontouchevent is been created in the class that extends activity.
http://www.jpct.net/wiki/index.php/Hello_World_for_Android
But is not ontouchevevent method of View's class ?
Depends from Activity ? Can you explain me how does it work ?