2 Replies - 707 Views - Last Post: 02 July 2016 - 09:18 AM

#1 Leftismer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-February 16

How to open an activity when particular text detected on a webpage?

Posted 30 June 2016 - 12:22 AM

Hello, I want my app to check text on this webpage:
http://advancedmaths.cba.pl/v.txt
and if the integer detected is greater than e.g. 20160625, then the app should open another activity. And here is the problem, because the activity doesn't start.
The code:
package com.example.lenovo.advancedmathspl;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class MainActivity extends AppCompatActivity {

    Button b, b2, b3, b4, b5, b6, b7, bw;
    int a;

    public class Aktualizacja extends AsyncTask <Void, Void, Void>{

        @Override
        protected Void doInBackground (Void... params){
            try {
                URL url = new URL("http", "advancedmaths.cba.pl", 80, "/v.txt");
                URLConnection conn = url.openConnection();
                conn.setDoInput(true);
                conn.connect();
                StringBuilder sb = new StringBuilder();
                InputStreamReader isr = new InputStreamReader(conn.getInputStream());
                BufferedReader in = new BufferedReader(isr);
                String line;

                line = in.readLine();

                a = Integer.parseInt(line);
                final Context context = getApplicationContext();

                if (a > 20160625){
                    Intent i = new Intent(context, Aktualizacja.class);
                    startActivity(i);
                } else {
                    Toast.makeText(getApplicationContext(), "No updates available.", Toast.LENGTH_LONG).show();
                }
            } catch (Exception e){
                e.printStackTrace();
            }
            return null;
        }
    }

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

        final Context context = getApplicationContext();

        b = (Button) findViewById(R.id.button);
        b2 = (Button) findViewById(R.id.button2);
        b3 = (Button) findViewById(R.id.button3);
        b4 = (Button) findViewById(R.id.button4);
        b5 = (Button) findViewById(R.id.button5);
        b6 = (Button) findViewById(R.id.button6);
        b7 = (Button) findViewById(R.id.button7);
        bw = (Button) findViewById(R.id.buttonw);

        ... <-- here is the rest of my app, but it doesn't matter

        View.onclickListener l7 = new View.onclickListener() {
            @Override
            public void onclick(View v) {
                Aktualizacja aktualizacja = new Aktualizacja();
                aktualizacja.execute(null, null, null);
            }
        };

        b7.setonclickListener(l7);
    }
}

To this moment
final Context context = getApplicationContext();
everything goes right, I set a breakpoint on this line and a = 20160626 as expected, but when I run the app, I receive this log:
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.lenovo.advancedmathspl/com.example.lenovo.advancedmathspl.MainActivity$Aktualizacja}; have you declared this activity in your AndroidManifest.xml?
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1900)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1624)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Activity.startActivityForResult(Activity.java:3761)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Activity.startActivityForResult(Activity.java:3722)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Activity.startActivity(Activity.java:4032)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.app.Activity.startActivity(Activity.java:4000)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at com.example.lenovo.advancedmathspl.MainActivity$Aktualizacja.doInBackground(MainActivity.java:45)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at com.example.lenovo.advancedmathspl.MainActivity$Aktualizacja.doInBackground(MainActivity.java:24)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err:     at java.lang.Thread.run(Thread.java:818)

Do You have any idea how to start an activity or not depending on the text detected on webpage? It may also work like the class Aktualizacja sends information to start activity to the MainActivity class, but I also tried to do it and didn't work as well.

Is This A Good Question/Topic? 0
  • +

Replies To: How to open an activity when particular text detected on a webpage?

#2 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 765
  • View blog
  • Posts: 5,762
  • Joined: 25-December 13

Re: How to open an activity when particular text detected on a webpage?

Posted 02 July 2016 - 08:50 AM

The error message asks this question:

Quote

have you declared this activity in your AndroidManifest.xml?

What is in your AndroidManifest.xml file?

This post has been edited by NormR: 02 July 2016 - 08:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 ChrisNt   User is offline

  • cute bug

Reputation: 262
  • View blog
  • Posts: 896
  • Joined: 31-July 13

Re: How to open an activity when particular text detected on a webpage?

Posted 02 July 2016 - 09:18 AM

The error message is clear :

06-30 09:16:44.014 30525-30607/com.example.lenovo.advancedmathspl W/System.err: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.lenovo.advancedmathspl/com.example.lenovo.advancedmathspl.MainActivity$Aktualizacja}; have you declared this activity in your AndroidManifest.xml?


If you want to use an activity you have to declared it in the manifest .

This post has been edited by ChrisNt: 02 July 2016 - 09:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1