Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:47+00:00 2026-06-13T09:22:47+00:00

I am using this code to create a BroadcastReceiver that has to run even

  • 0

I am using this code to create a BroadcastReceiver that has to run even the application is not running.

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

public class ReminderClass extends BroadcastReceiver {
    SharedPreferences myPrefs;
    String prefuName, pref_usr_fname, prefdev_id, pref_usr_lname, pref_uid,
            pref_usr_email, ret, dates_btw;;
    String event_desc, e_time, s_time, event_title, day_event_id;
    ArrayList<String> day_data = new ArrayList<String>();
    ArrayList<String> st_time = new ArrayList<String>();
    ArrayList<String> et_time = new ArrayList<String>();
    ArrayList<String> day_eve_id = new ArrayList<String>();
    ArrayList<String> day_eve_title = new ArrayList<String>();
    int MILLIS_IN_FIFTEEN_MINS = 1000 * 60 * 15 ;

    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
    @Override
    public void onReceive(Context con, Intent _intent) {
        // TODO Auto-generated method stub
        Log.v("inside the broadcast receiver1 >>","broadcast1");
        if (_intent.getAction().equals("REMINDER")) {

        Log.v("inside the broadcast receiver2 >>","broadcast2");
        myPrefs = con.getSharedPreferences("myPrefs", 1);
        prefuName = myPrefs.getString("u_name", "");
        pref_usr_fname = myPrefs.getString("fname", "");
        prefdev_id = myPrefs.getString("dev_id", "");
        pref_usr_lname = myPrefs.getString("lname", "");
        pref_uid = myPrefs.getString("id", "");
        pref_usr_email = myPrefs.getString("email", "");

        Log.v("pref name>>> ", prefuName);
        Log.v("pref pass >>", pref_usr_fname);
        Log.v("prev devid >>", prefdev_id);
        Log.v("pref_usr_fname", pref_usr_fname);
        Log.v("pref_usr_lname", pref_usr_lname);
        Log.v("pref_uid", pref_uid);
        Log.v("pref_usr_email", pref_usr_email);

        try {
            HttpClient client = new DefaultHttpClient();
            HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
                                                                                    // Limit

            HttpResponse response;
            HttpPost post = null;
            JSONObject json = new JSONObject();

                post = new HttpPost("my_url");
                json.put("user_id", pref_uid);

                post.setHeader("Content-Type", "application/json");
                post.setHeader("Accept", "application/json");
                StringEntity se = new StringEntity(json.toString());
                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                        "application/json"));
                post.setEntity(se);
                response = client.execute(post);
                Log.v("Response >>>", response + "");
                ret = EntityUtils.toString(response.getEntity());
                Log.v("My calendar response", ret);
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (ClientProtocolException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (org.apache.http.ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }           
    }
        else
        {
            Log.v("Broadcast not working >>","broadcast not working");
        }
    }

}

In my manifest,

<receiver
            android:name=".ReminderClass"
            android:enabled="true"   android:permission="android.permission.INTERNET">
            <intent-filter>
                <action android:name="REMINDER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

My Broadcast is not been called. what I have done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:22:47+00:00Added an answer on June 13, 2026 at 9:22 am

    I solved my problem. I have added a Service, and called that service in a BroadcastReceiver, which checks when boot complete. In Oncreate() method of the service, I implemented a thread which runs every minute. I used my code inside the run method of the thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a vcf file that contains contacts by using this code ContentResolver
I'm using this code to create a custom Event class: package evt { import
Using this Java code: // create the items list List<Item> items = new ArrayList<Item>();
I tried using this code inside Create() witch creates the listbox that contains the
I am using this code to create an Alarm in a activity that can
I'm using this code to create multiple functions wrappers using variadic templates: // Compile
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
i have this function in my code and I'm using throw to create meaningful
I want to create an item to sitecore using code behind. I found this
i am trying to create slider movement graphics. The code explain better this. using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.