Danny Lauwers
[WM19] Android Alarmmanager and BroadcastReceiver do not work ? November 19, 2014 02:55PM |
public static void JKeepAliveAlarm() { try { AlarmManager alarm; Calendar cal; PendingIntent alarmIntent; // Retrieve the current activity Activity tmpActivity = getCurrentActivity(); // Retrieve the current Context Context tmpContext = getApplicationContext(); cal = Calendar.getInstance(); alarm = (AlarmManager)tmpContext.getSystemService(tmpContext.ALARM_SERVICE); Intent myIntent = new Intent(tmpContext,AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(tmpContext, 0, myIntent, 0); // Start every 30 seconds alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, alarmIntent); Toast.makeText(tmpContext, "Keep Alive Alarm SET", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } }
public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { Toast.makeText(context, "Alarm - Start", Toast.LENGTH_LONG).show(); // Try to start the app if not allready running // TODO Toast.makeText(context, "Alarm - End", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } } }
Danny Lauwers
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] December 10, 2014 03:26PM |
public static class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { // Retrieve the current Context Context tmpContext = getApplicationContext(); Toast.makeText(tmpContext, "test - Start", Toast.LENGTH_LONG).show(); // Stuff todo Toast.makeText(context, "Awake CareApp - End", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } } }
public static void JKeepAliveAlarm() { try { AlarmManager alarm; Calendar cal; PendingIntent alarmIntent; // Retrieve the current activity Activity tmpActivity = getCurrentActivity(); // Retrieve the current Context Context tmpContext = getApplicationContext(); cal = Calendar.getInstance(); alarm = (AlarmManager)tmpContext.getSystemService(tmpContext.ALARM_SERVICE); Intent myIntent = new Intent(tmpContext,AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(tmpContext, 0, myIntent, 0); // Start every 30 seconds alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, alarmIntent); Toast.makeText(tmpContext, "Keep Alive Alarm SET", Toast.LENGTH_LONG).show(); } catch(Exception e) { e.printStackTrace(); } }
Popoy
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] December 12, 2014 12:27AM |
Danny Lauwers
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] December 12, 2014 09:27AM |
import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream;
public static class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { // Retrieve the current Context Context tmpContext = getApplicationContext(); //// Do your stuff here } catch(Exception e) { e.printStackTrace(); } } }
popoy
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] December 12, 2014 11:20AM |
import android.content.Context; import android.content.BroadcastReceiver; import android.content.Intent; import android.widget.Toast; import java.util.Calendar; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent;
Danny Lauwers
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] December 12, 2014 04:00PM |
KenKnight
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] February 10, 2015 02:10PM |
Danny Lauwers
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] February 10, 2015 03:38PM |
KenKnight
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? February 25, 2015 02:12PM |
Danny Lauwers
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? February 25, 2015 11:01PM |
public static class PhoneStateMonitor extends PhoneStateListener { Context context; public PhoneStateMonitor(Context context) { super(); // TODO Auto-generated constructor stub this.context=context; Toast.makeText(context, "Init PhoneStateMonitor",Toast.LENGTH_LONG).show(); } //This Method Automatically called when changes is detected in Phone State // Various states are - CALL_STATE_IDLE, CALL_STATE_OFFHOOK, and CALL_STATE_RINGING // IDLE – when there is no incoming call // OFFHOOK – when the line is busy // RINGING – when call is incoming public void onCallStateChanged(int state, String incomingNumber) { // TODO Auto-generated method stub super.onCallStateChanged(state, incomingNumber); Toast.makeText(context, "Phone State - "+state+" Incoming Number - "+incomingNumber, Toast.LENGTH_LONG).show();//Giving the Message that Phone State Changed //Checking The phone state switch(state) { case TelephonyManager.CALL_STATE_IDLE: //Phone is in Idle State Toast.makeText(context, "Phone State is IDLE", Toast.LENGTH_LONG).show(); break; case TelephonyManager.CALL_STATE_RINGING: //Phone is Ringing Toast.makeText(context, "Phone State is RINGING", Toast.LENGTH_LONG).show(); break; case TelephonyManager.CALL_STATE_OFFHOOK: //Call is Received Toast.makeText(context, "Call State is OFFHOOK",Toast.LENGTH_LONG).show(); break; } } }
Ruben Sanchez Peña
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? [SOLVED] September 13, 2016 02:29PM |
Ruben Sanchez Peña
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? September 14, 2016 07:04PM |
MJ
Re: [WM19] Android Alarmmanager and BroadcastReceiver do not work ? November 18, 2019 12:43PM |
import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ActivityNotFoundException; import android.support.annotation.Nullable; import android.app.Activity; import android.widget.Toast; public static class Beta extends Activity{ Context ctx; Context fofo = this; Activity act = getCurrentActivity(); public void find() { //Toast.makeText(fofo, "class entered", Toast.LENGTH_SHORT).show(); //try the variation of touchprovider try{ Intent i = new Intent(); ComponentName cn = new ComponentName("com.example.provider", "com.example.till.shopper.FindShopperActivity"); i.putExtra("ByPassAuth", true); i.setComponent(cn); act.startActivityForResult(i, 10); } catch(ActivityNotFoundException e) { Intent i = new Intent(); ComponentName cn = new ComponentName("com.example.provider.debug", "com.example.till.shopper.FindShopperActivity"); i.setComponent(cn); i.putExtra("ByPassAuth", true); act.startActivityForResult(i, 10); } } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); Toast.makeText(ctx, "result", Toast.LENGTH_SHORT).show(); try{ //call external global Windev Procedure to check if there is an update boolean valReturn = false; valReturn = callWLProcedure_boolean("responseEh"); //success code = 1010 if(resultCode==1010) { String name = data.getStringExtra("name"); String shopperSurname = data.getStringExtra("surname"); String shopperGuid = data.getStringExtra("guid"); int shopperCashback = data.getIntExtra("cashback", 0); } }catch(Exception e){ Toast.makeText(ctx, "result error", Toast.LENGTH_SHORT).show(); } } }