хочу показывать уведомления в приложении для Android, когда приложение не запущено, но я удалил данные с веб-сайта и показал элементы в утилите - PullRequest
1 голос
/ 08 июня 2019

я удалил данные с веб-сайта и показал элементы в программе просмотра утилит, и теперь всякий раз, когда новый элемент добавляется в панель утилизации, он должен отображаться как уведомление одновременно, даже если приложение не работает в Android Studio с использованием языка Java

до сих пор я понятия не имел, но это код моего приложения

MainActivity

public class MainActivity extends AppCompatActivity {



    private DrawerLayout mydrawer;

    private ActionBarDrawerToggle mytoggle;

    private ProgressDialog mProgressDialog;
    private String url = "MY URL";
    ArrayList<String> postTitle = new ArrayList<>();
    ArrayList<String> next = new ArrayList<>();
    RecyclerView recyclerView;

    BottomNavigationView bnv;

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

        getSupportActionBar().setTitle("NOTIFICATIONS");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        new Description().execute();
        botmview();
        draw();
    }




    private class Description extends AsyncTask<Void, Void, Void> {


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mProgressDialog = new ProgressDialog(MainActivity.this);

            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                // Connect to the web site
                Document document = Jsoup.connect(url).get();
                // Using Elements to get the Meta data
                Elements links = document.select("table");
                Elements docu = links.select("tr");
                Elements d = docu.select("a[target]");

                // Locate the content attribute
                for (Element link : d) {
                    Elements items = d.select("span");//getting text and urls
                    // Log.d(String.valueOf(next), "doInBackground: ");//showing urls in logcat
                    next.add(link.absUrl("href"));      //getting and setting  urls inside next ArrayList of strings
                    // postTitle.add(link.text());//setting text to recyclerView items

                }

                Elements doc = links.select("span");
                // Locate the content attribute
                for (Element link : doc) {
                    Elements items = doc.select("span");//getting text and urls
                    //Log.d(String.valueOf(next), "doInBackground: ");//showing urls in logcat
                    //next.add(link.absUrl("href"));      //getting and setting  urls inside next ArrayList of strings
                    postTitle.add(link.text());//setting text to recyclerView items

                }



            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }


        @Override
        protected void onPostExecute(Void result) {
            // Set text into RecyclerView

            recyclerView = findViewById(R.id.act_recyclerview);
            PdfPostAdapter mPostAdapter = new PdfPostAdapter(postTitle,next,getApplicationContext());// passing text and urls inside postTitle and next
            RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
            recyclerView.setLayoutManager(mLayoutManager);
            recyclerView.setAdapter(mPostAdapter);

            mProgressDialog.dismiss();
        }
    }
}
public class PdfPostAdapter extends RecyclerView.Adapter<PdfPostAdapter.postViewHolder> {

    private List<String>postTitle;
    private List<String>next;
    Context context;

    public PdfPostAdapter(List<String> postTitle , List<String> next , Context context)   //creation of constructor
    {

        this.postTitle = postTitle;
        this.next = next;
        this.context = context;

    }



    // implementing methodes fo postAdapter . RecyclerView
    @NonNull
    @Override
    public postViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {

        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.post, viewGroup ,false);

        return new postViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(postViewHolder postViewHolder, final int i) {


        postViewHolder.tvTitle.setText(postTitle.get(i));
        postViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {//need to do some changes here to pass url data to next activity

                if (next.get(i).endsWith(".pdf")) {
                    Intent intent = new Intent(context,DetailedView.class);
                    intent.putExtra("link", next.get(i));  //need to do some changes here to pass url data to next activity
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);

                }
                else if (next.get(i).endsWith(".PDF")){

                    Intent intent = new Intent(context,DetailedView.class);
                    intent.putExtra("link", next.get(i));  //need to do some changes here to pass url data to next activity
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);

                }
                else {
                    Intent intent = new Intent(context,OpenDetail.class);
                    intent.putExtra("link", next.get(i));  //need to do some changes here to pass url data to next activity
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return postTitle.size();
    }

    public class postViewHolder extends RecyclerView.ViewHolder{                //creation of view holder

        TextView tvTitle;
        public postViewHolder( View itemView) {
            super(itemView);

            tvTitle = itemView.findViewById(R.id.title);


        }
    }
}

я не знаю, что мне делать, потому что я новичок в Android и Java

...