0
Hello, I posted the full code. The compilation error occurs in the playmusic class. Thank you for your attention!
public class Agendador
{
//Toolkit toolkit;
Timer timer;
public Agendador() {
// toolkit = Toolkit.getDefaultToolkit();
timer = new Timer();
timer.schedule(new RemindTask(),
0, //initial delay
20*1000); //subsequent rate
}
class RemindTask extends TimerTask {
int numWarningBeeps = 3;
public void run() {
if (numWarningBeeps > 0) {
//toolkit.beep();
Log.v("mensagem","Execucao: " + Integer.toString(numWarningBeeps));
new PutMethodDemo().execute();
//System.out.println("Beep!");
numWarningBeeps--;
} else {
//toolkit.beep();
//System.out.println("Time's up!");
//timer.cancel(); // Not necessary because
// we call System.exit
Log.v("mensagem"," fim " + Integer.toString(numWarningBeeps));
System.exit(0); // Stops the AWT thread
// (and everything else)
}
}
}
}
public class PutMethodDemo extends AsyncTask<String , Void ,String>
{
//Declare uma variável de instância para o player
private MediaPlayer mp = null;
HttpResponse response;
String server_content = null;
HttpClient client = getThreadSafeClient();
public DefaultHttpClient getThreadSafeClient() {
DefaultHttpClient client = new DefaultHttpClient();
ClientConnectionManager mgr = client.getConnectionManager();
HttpParams params = client.getParams();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
return client;
}
@Override
protected String doInBackground(String... strings) {
HttpPost post = new HttpPost("http://www.consuladoportugalrjservicos.com/public_html/exec");
Integer statusCode = doGet("http://consuladoportugalrj.org.br");
if(statusCode !=200)
{
Log.e("warn","codigo de erro "+Integer.toString(statusCode));
return "err";
}
statusCode = doGet("http://www.consuladoportugalrjservicos.com/public_html/");
if(statusCode !=200)
{
Log.e("warn","codigo de erro "+Integer.toString(statusCode));
return "err";
}
//post
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("modulo", "modulo.login"));
pairs.add(new BasicNameValuePair("acao", "login101"));
pairs.add(new BasicNameValuePair("txtcpf", "02355180776"));
pairs.add(new BasicNameValuePair("txtusuario","[email protected]"));
try
{
post.setEntity(new UrlEncodedFormEntity(pairs));
}
catch (UnsupportedEncodingException e)
{
Log.e("UnsupportedEncodingException",e.getMessage());
e.printStackTrace();
}
try
{
response = client.execute(post);
}
catch (IOException e)
{
Log.e("IOException",e.getMessage());
e.printStackTrace();
}
// Getting the status code.
statusCode = response.getStatusLine().getStatusCode();
Log.e("Response_code ", "" + statusCode);
if(statusCode !=200)
{
Log.e("warn","codigo de erro "+Integer.toString(statusCode));
return "err";
}
HttpEntity httpEntity = response.getEntity();
try
{
server_content = readStream(httpEntity.getContent());
}
catch (UnsupportedOperationException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
//post 2
pairs.clear();
pairs.add(new BasicNameValuePair("modulo", "modulo.servicos"));
pairs.add(new BasicNameValuePair("acao", "servico990"));
try
{
post.setEntity(new UrlEncodedFormEntity(pairs));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
try
{
response = client.execute(post);
}
catch (IOException e)
{
e.printStackTrace();
}
// Getting the status code.
statusCode = response.getStatusLine().getStatusCode();
Log.e("Response_code ", "" + statusCode);
if(statusCode !=200)
{
Log.e("warn","codigo de erro "+Integer.toString(statusCode));
return "err";
}
httpEntity = response.getEntity();
try
{
server_content = readStream(httpEntity.getContent());
}
catch (UnsupportedOperationException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
Log.v("server_content", server_content);
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s == null)
{
//procurar pelo texto rbtnhora
if(server_content.contains("rbtnhora\" value=\"-1\""))
Log.e("Response_agenda ", "Agenda fechada " + s);
else
{
Log.e("Response_agenda ", "Agenda aberta " + s);
//emite um som.
playMusic();
}
}
}
// Converting Inputstream to String
private String readStream(InputStream in) {
BufferedReader reader = null;
StringBuffer response = new StringBuffer();
try {
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return response.toString();
}
//private HttpResponse doGet(String enderecoGet)
private Integer doGet(String enderecoGet)
{
HttpGet get = new HttpGet(enderecoGet);
try
{
response = client.execute(get);
}
catch (IOException e)
{
e.printStackTrace();
}
// Getting the status code.
int statusCode = response.getStatusLine().getStatusCode();
Log.v("Response_source ", "" + enderecoGet);
Log.v("Response_code ", "" + statusCode);
//return response;
return statusCode;
}
public void playMusic() {
//Se algum som ainda estiver a tocar pára-o
releasePlayer();
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), notification);
!!!!O ERRO ESTÁ NA LINHA ACIMA!!!
//mp = MediaPlayer.create(this, R.raw.ulso);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//No final de tocar liberta o media player para poder ser novamente utilizado
releasePlayer();
}
});
//Toca o som
mp.start();
}
//Método para libertar o media player
private void releasePlayer() {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
}
good morning, I could put the whole code by faovr?
– Luiz Fernando Salvaterra
Hello, posted the full code. Thank you in advance for your attention.
– UltraSeven
@Luizfernandosalvaterra hello, posted the full code. I thank you in advance for your attention.
– UltraSeven