How you notify in the Jsoup function

Asked

Viewed 31 times

1

I have to notify an action that occurs within the site , I have the following code that. It appears in a texview and wanted to notify enves of sending the name to textview. Textview txv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     txv = (TextView) findViewById(R.id.hello);

    new RequestTask().execute("http://sites.ecomp.uefs.br/perta/");
}

class RequestTask extends AsyncTask<String, String, String>{

    @Override
    protected String doInBackground(String... uri) {
        String text = null;
        try {
            // pega o codigo html de um site
            Document doc = Jsoup.connect(uri[0]).get();
            // pega um elemento do codigo
            Elements newsHeadlines = doc.select("#sites-header-title");
            // pega o texto dentro do codigo
            text = newsHeadlines.text();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return text;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if(result != null){
            txv.setText(result);
        }else{
            txv.setText("FALHA!");
        }
    }
}
  • Notify in what sense?! A push notification?!

  • Type I log in to a game page and if you have points available to pick up notifies ,

  • Because when you have points available a different div appears on this page

  • The answer I gave will probably help you if it’s just a notification in the status bar. Instead of textView, you put the notification. It’s something extremely simple.

1 answer

1


You can create a method using the Notificationmanager. As simple as possible, you would pass as parameter the title and subtitle of the notification. See an adaptation of your code:

if(result != null){
    simplesNotificacao("Notificação", result);    
}else{
    simplesNotificacao("Notificação","FALHOU TUDO!!!");
}  

See below how the method would look simplesNotificacao():

private void simplesNotificacao(String title, String subtitle) {
  NotificationCompat.Builder builder =
     new NotificationCompat.Builder(this)
     .setSmallIcon(R.drawable.abc)
     .setContentTitle(title)
     .setContentText(subtitle);

  Intent notificationIntent = new Intent(this, MainActivity.class);
  PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
     PendingIntent.FLAG_UPDATE_CURRENT);
  builder.setContentIntent(contentIntent);

  NotificationManager manager = (NotificationManager) 
      getSystemService(Context.NOTIFICATION_SERVICE);
  manager.notify(0, builder.build());
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.