I have read through a lot of answers regarding this and still cannot figure out a way to do it.
I have an app which sets a reminder for a meeting and shows a pop up activity 15 minutes before the appointment and getting an input from the user about the appointment.
I use an AlarmManager to set the alarm, and start an activity from the broadcast reciever. Works fine when the device is on, but if it is a sleep it doesn't turn on my phone (However I do manage to get the lock screen on, on my emulator). In either case I cannot unlock the phone and display my activity without the user unlock his phone manually.
My main activity
public class Start extends Activity {
public static int no;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
System.out.println("On create. After content set.");
LinearLayout l = (LinearLayout) findViewById(R.id.startlayout);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, new GregorianCalendar().getTimeInMillis()+10000, PendingIntent.getBroadcast(this, 0, new Intent(this, AlarmReciever.class), Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
My broadcast reveiver
public class AlarmReciever extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent arg1) {
Log.i("Alarm recieved", "Executing on receive");
PowerManager pm = (PowerManager)arg0.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Tag");
wl.acquire();
Intent i = new Intent();
i.setClassName("com.example.attendogram", "com.example.attendogram.Reminder");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
Log.i("Alarm recieved", "Executed on receive");
}
}
Activity started by broadcast receiver
public class Reminder extends Activity {
private Context context;
public Reminder() {
// TODO Auto-generated constructor stub
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.i("Reminder created", "Executing onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Log.i("Reminder", "Screen tunred on");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Log.i("Reminder", "Dismissed");
setFinishOnTouchOutside(false);
TextView rem = (TextView) findViewById(R.id.reminder_sna);
rem.setText(getIntent().getStringExtra("id"));
context = this;
}}
And my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.attendogram"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.attendogram.Start"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="SubPage"></activity>
<activity android:name="NewSub"></activity>
<activity android:name="Timetable" >
</activity>
<receiver android:name=".AlarmReciever" />
<activity
android:name="Reminder"
android:theme="#android:style/Theme.DeviceDefault.Dialog.NoActionBar.MinWidth"
android:excludeFromRecents="true" >
</activity>
</application>
</manifest>
If the phone is alseep, your phone will only wake up for the time to execute Broadcast receiver. It might or might not remain wake when the activity executes.
To solve this, you should acquire the wake lock in the Receiver itself and then start the activity...
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, App.TAG);
wl.acquire();
Log.i("Alarm recieved", "Executing on receive");
Intent i = new Intent();
i.setClassName("com.example.attendogram", "com.example.attendogram.Reminder");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
Related
I am currently trying to call a BroadCastReceiver with an AlarmManager to ouput a notification on a certain time! On Android SDK Level 19+ my method works, but on Android 17 my approach leads into nothing!
There are no errors outputted, nor are there any logs in the monitor of Android Studio. The BroadcastReceiver is simply not called by the AlarmManager.
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button mButton = (Button) findViewById(R.id.btn);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setNotification();
}
});
}
public void setNotification() {
Intent resultIntent = new Intent(this, NotificationPublisher.class);
resultIntent.setData(Uri.parse("notification://1995-" + System.currentTimeMillis()));
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent resultPendingIntent =
PendingIntent.getBroadcast(
this,
1995,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 30 * 1000, resultPendingIntent);
Log.d("Test", "Alarm started");
}
}
NotificationPublisher.java
public class NotificationPublisher extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "What", Toast.LENGTH_SHORT).show();
}
}
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nbaye.apptesting">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".NotificationPublisher"
android:process=":remote"
android:enabled="true" />
</application>
</manifest>
Min SDK: 17
Target: 23
EDIT:
I have looked into the AlarmManager with "adb shell dumpsys alarm":
The alarm is created by the app, but the "when" variable of the alarm is counting down from +30 seconds to an infinite negative number!
I am struggling to make my basic lockscreen app.starting, the app displays a basic activity screen, with an image view (displaying an image from storage) and a TextView (displaying date & time).On swiping up, the activity goes back. What I am struggling with is, when screen is turned off & turned on, the event receiver should send out this event & my activity should come to foreground again. That's not what's happening. I am not completely sure how to use my service & broadcastreceiver to achieve this. Any help would be appreciated please.
My AndroidManifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kjtest2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<receiver
android:name="com.example.kjtest2.EventsReciever"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service
android:enabled="true"
android:name="com.example.kjtest2.myService"/>
<activity
android:name="com.example.kjtest2.MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
My receiver:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class EventsReciever extends BroadcastReceiver {
public boolean wasScreenOn = true;
#Override
public void onReceive(Context context, Intent recievedIntent) {
Log.i("Check","[BroadCastReciever] onRecieve()");
if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
wasScreenOn = false;
Log.i("Check","[BroadCastReciever] Screen went OFF");
} else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
wasScreenOn = true;
Log.i("Check","[BroadCastReciever] Screen went ON");
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}
else if(recievedIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}
}
}
My onCreate code in the activity:
protected void onCreate(Bundle savedInstanceState) {
Log.i("event", "activity onCreate");
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, EventsReciever.class);
setContentView(R.layout.activity_main);
/** REMOVING KEYGUARD RECEIVER **/
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
setTime();
changeImage();
ImageView img2 = (ImageView)findViewById(R.id.imageView);
img2.setOnTouchListener(new OnSwipeTouchListener(this) {
#Override
public void onSwipeLeft() {
Toast.makeText(MainActivity.this, "Swipe left", Toast.LENGTH_SHORT)
.show();
changeImage();
Log.i("event","onSwipeLeft");
}
#Override
public void onSwipeRight() {
TextView tvDisplayDate = (TextView)findViewById(R.id.date1);
CustomDigitalClock cdc = (CustomDigitalClock)findViewById(R.id.dc1);
if (tvDisplayDate.getVisibility()==View.VISIBLE) {
tvDisplayDate.setVisibility(View.GONE);
cdc.setVisibility(View.GONE);
} else {
tvDisplayDate.setVisibility(View.VISIBLE);
cdc.setVisibility(View.VISIBLE);
}
}
#Override
public void onSwipeUp() {
Toast.makeText(MainActivity.this, "Swipe up", Toast.LENGTH_SHORT)
.show();
MainActivity.this.moveTaskToBack(true);
}
#Override
public void onSwipeDown() {
Toast.makeText(MainActivity.this, "Swipe down", Toast.LENGTH_SHORT)
.show();
}
});
}
And finally my service:
public class myService extends Service{
private NotificationManager mNM;
private int NOTIFICATION = R.string.local_service_started;
private final IBinder mBinder = new MyBinder();
private Messenger outMessenger;
#Override
public void onCreate() {
/** INITIALIZE RECEIVER **/
//RegisterReciever();
Log.i("event", "ServiceStarted");
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// Display a notification about us starting. We put an icon in the status bar.
showNotification();
}
}
As of now, the receiver & service aren't starting. I had been able to start them by registering the event dynamically, but I don't think that should be required. Registering the event in manifest should be sufficient for my application, isn't it?
Thanks for helping.
make sure your service is running by including startService(new Intent(this,MyService.class)); statement in your activity onCreate()
it is actually required to register receiver programmatically, manifest declaration will not work for Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON, register the receiver instance in service onCreate(), unregister in onDestroy()
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
receiver = new EventsReciever();
registerReceiver(receiver, filter);
I have to schedule invoking of an already install test project on the device after 10 sec once the button is click. For that I have created an AlarmReceiver and my TaskService which actually is invoking the test project.
After running the app, nothing happens after the button is clicked. I don't know what is wrong but service doesn't performs the job even after 10 sec.
Below is my code which I am trying. The Activity class:
// Create an anonymous implementation of OnClickListener
private OnClickListener HTListener = new OnClickListener() {
public void onClick(View v) {
btnStartSchedule(v);
}
};
public void btnStartSchedule(View v) {
try {
AlarmManager alarms = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class);
intent.putExtra(AlarmReceiver.ACTION_ALARM, AlarmReceiver.ACTION_ALARM);
final PendingIntent pIntent = PendingIntent.getBroadcast(this, 1234567, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 10000, pIntent);
Toast.makeText(ScrapeActivity.this, "Alarm Started", Toast.LENGTH_LONG).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The AlarmReceiver class :
public class AlarmReceiver extends BroadcastReceiver {
public static String ACTION_ALARM = "com.alarmmanager.alarm";
#Override
public void onReceive(Context context, Intent intent) {
Log.i("Alarm Receiver", "Entered");
Toast.makeText(context, "Entered", Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras();
String action = bundle.getString(ACTION_ALARM);
if (action.equals(ACTION_ALARM)) {
Log.i("Alarm Receiver", "If loop");
Intent inService = new Intent(context, LaunchService.class);
context.startService(inService);
} else {
Log.i("Alarm Receiver", "Else loop");
Toast.makeText(context, "Else loop", Toast.LENGTH_SHORT).show();
}
}
}
And finally the LaunchService class:
public class LaunchService extends IntentService {
public LaunchService(String name) {
super(name);
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.my.testproject");
startActivity(LaunchIntent);
}
}
I have also mention the receiver and service inside the manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.pb.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/PB_APP"
android:theme="#style/AppTheme" >
<activity
android:name="com.my.pb.activity.ScrapeActivity"
android:label="#string/PB_APP" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".AlarmReceiver"
android:process=":remote" >
</receiver>
<service android:name=".LaunchService" >
</service>
</application>
I don't understand whats the issue coz there's no exception in the Logcat. As I click the button, i just see the toast message saying Alarm Started. Please help.
You have a typo at the Manifest, you declared AlaramReceiver instead of .AlarmReceiver there.
Currently i am working on a Broadcast Receiver application, in which i am making an Alarm which should display a message after we enter the seconds. I used RTC_WAKEUP, which means it should display the message when the device is on and it is supposed to turn on the device and then display the message when the device is off. MY PROBLEM IS THAT IT RTC_WAKEUP DOESN'T ON MY DEVICE but it is working properly when device is on. i am pasting the code of my application. In my application there are two classes.
MainActivity
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startAlert(View view) {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 23432424, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (i * 1000), pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",
Toast.LENGTH_LONG).show();
}
}
and other is
MyBroadcastReceiver
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Jaago Mohan Pyarreee!!!!.",
Toast.LENGTH_LONG).show();
}
}
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyBroadcastReceiver" >
</receiver>
</application>
</manifest>
RTC_WAKEUP will not switch on the screen, all it does is wakes up thee cpu so that your job is done. For the Screen to be turned on you need a FULL wakelock to be acquired.
PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE,
"wakeup");
wl.acquire();
// ... do work...
//show toask
wl.release();
Do yo have the permission in your Manifest?
<uses-permission android:name="android.permission.WAKE_LOCK" />
Fix your manifest. Instead of
<receiver android:name="MyBroadcastReceiver" >
you need:
<receiver android:name=".MyBroadcastReceiver" >
Checked the google DeskClock app:
com.android.deskclock.alarms.AlarmStateManager (it's a BroadcastReceiver)
In its onReceive function used goAsync():
#Override
public void onReceive(final Context context, final Intent intent) {
final PendingResult result = goAsync();
final PowerManager.WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context);
wl.acquire();
AsyncHandler.post(new Runnable() {
#Override
public void run() {
handleIntent(context, intent);
result.finish();
wl.release();
}
});
}
You should take a shot with that.
Code of Receiver:
public class OnBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
try {
BufferedReader in=new BufferedReader(
new FileReader(MainNote.log));
String AlarmString;
int i = 0;
while ((AlarmString = in.readLine())!=null)
{
Long AlarmTime = Long.parseLong(AlarmString.substring(0, AlarmString.indexOf(" ")));
if (AlarmTime < System.currentTimeMillis()) i++;
else {
String AlarmArray[] = AlarmString.split("\\s");
Intent AlarmIntent = new Intent(context, AlarmReceiver.class);
if (AlarmArray[1].equals("null")) AlarmIntent.putExtra("alarm_message", "");
else AlarmIntent.putExtra("alarm_message", AlarmArray[1]);
if (AlarmArray[2].equals("true"))
AlarmIntent.putExtra("Vibration", true);
else AlarmIntent.putExtra("Vibration", false);
if (AlarmArray[3].equals("true"))
AlarmIntent.putExtra("Sound", true);
else AlarmIntent.putExtra("Sound", false);
final int _ID = (int) System.currentTimeMillis();
PendingIntent sender = PendingIntent.getBroadcast(context , _ID, AlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, AlarmTime, sender);
}
}
Code of AlarmReceiver.class
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
boolean Vibration = bundle.getBoolean("Vibration");
boolean Sound = bundle.getBoolean("Sound");
if (message.equals(null))
NotifierHelper.sendNotification(context, MainNote.class, context.getResources().getString(R.string.NotTitle), context.getResources().getString(R.string.Nodiscr), 1, Sound, true, Vibration);
else
NotifierHelper.sendNotification(context, MainNote.class, context.getResources().getString(R.string.NotTitle), message, 1, Sound, true, Vibration);
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name=".MainNote">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FingerPaint"></activity>
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver>
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
MainNote.log can costist for example
1304094118826 text true true
After reboot I see that my process is started, but then I dont have Notifacation. Whats wrong here? And how to debug code in OnBootReciever?
I replace my code in OnBootReciever on
Intent AlarmIntent = new Intent(context, AlarmReceiver.class);
AlarmIntent.putExtra("alarm_message", "blabla");
AlarmIntent.putExtra("Vibration", true);
AlarmIntent.putExtra("Sound", true);
final int _ID = (int) System.currentTimeMillis();
PendingIntent sender = PendingIntent.getBroadcast(context , _ID, AlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+6000, sender);
And its work. So problem in part where I read information from file.
One problem was in MainNote.log. Log its static varible so I cant contact with this here. But now I have very strange problem -
java.io.FileNotFoundException: /mnt/sdcard/AlarmsFromDrawNote.alm (Permission denied)
com.notedraw.bos.app.OnBootReceiver1.onReceive(OnBootReceiver1.java:30)
30th line is -
BufferedReader in=new BufferedReader(new FileReader(log));
WTF? (see manifest)
Your AlarmReceiver needs to be a static BroadcastReceiver like your OnBootReceiver is in order for it to act on the alarm that you set. Unfortunately, I don't think you can have more than one static receiver per application (I tried before and it did not work for me). You could try putting two intent filters on your OnBootReceiver and have it deal with both broadcasts.
In your onRecieve, simply check intent.getAction() to see which broadcast it is receiving (the boot up one or the alarm), and deal with it appropriately.
You need to create a new broadcast receiver inside the class where the broadcast will be received. Put this at the top of your class outside any methods.
AlarmReceiver intentReceiver = new AlarmReceiver ();
And you need:
#Override
protected void onPause() {
// TODO Mark time user logged out
unregisterReceiver(intentReceiver);
super.onPause();
}`
And:
#Override
protected void onResume() {
IntentFilter filter = new IntentFilter(CustomAction.MY_INTENT);
filter.addAction(CustomAction.MY_INTENT);
registerReceiver(intentReceiver, filter);
super.onResume();
}