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.
Related
This is my first post and I am new to Android App development so please bear with me.
I have written (and use every day) a pretty good reminders App because all the others were either too complicated or too simple. It is also on the play store, although not easy to find, but thats another story.
While I am happy with the whole App the alarms which show a notification or sound an alarm do not always happen. If the alarm is soon then it will but more than say 2 hours from now it often gets missed. Using "adb shell dumpsys alarm" it looks as if they are being discarded?
I have googled for days and have tried so many things, from this forum too, but no luck so I thought I would post some code to see if anybody can please tell me were I am going wrong as it should work as far as I can see.
So here goes.
I use alarm manager to queue the pending intent to call my broadcast receiver which starts a service which starts an activity which creates a notification and optionally sounds an alarm.
I was skipping the service bit but after googling it seems I should use a service. And as mentioned, this works fine for alarms happening soon but not after a few hours or a day or more. Could be due to Doze mode or my app being stopped by Android?
I would really appreciate some help please as I am pulling my hair out!!
Thanks in advance.
Here is my manifest. Where I think the problem is?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wingwares.reminders">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<supports-screens
android:anyDensity="true"
android:normalScreens="true" />
<application
android:icon="#drawable/reminder2"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<receiver android:name=".WidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
<service
android:name=".WidgetService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />
<activity
android:name=".AppPreferences" />
<activity
android:name=".ListActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RemActivity"
android:label="#string/add_reminder"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<service
android:name=".AlarmService"
android:enabled="true"
android:exported="true" >
</service>
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="SET_ALERT" />
</intent-filter>
</receiver>
<activity
android:name=".AlarmDialog"
android:theme="#style/AlarmDialog" />
</application>
</manifest>
And my Alarm Manager from ListActivity
public void setAlert(Context context, boolean turnOn){
intent = new Intent(context, AlarmReceiver.class);
intent.putExtra("name", fullName());
intent.putExtra("notes", notes);
intent.putExtra("setalarm", setalarm);
intent.putExtra("millis", time.getMilliTime());
intent.putExtra("remId", remId);
pendingIntent = PendingIntent.getBroadcast(context, 8192 + remId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
if (turnOn) {
alertTime = time.getMilliTime() - (warning * 60000);
interval = getInterval();
//set repeating alarmManager just once
if (freq.equals(EVERY) && type.equals(FIXED) && date.equals(getOriginal()) && interval > 0) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, interval, pendingIntent);
} else {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
}
}
} else {
setalarm = false;
}
}
My broadcast receiver
public class AlarmReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent newIntent = new Intent(context, AlarmService.class);
//pass the extras on and show the dialog
newIntent.putExtras(intent);
startWakefulService(context, newIntent);
}
}
My Service
public class AlarmService extends IntentService {
public AlarmService (){
super("AlarmService");
}
#Override
protected void onHandleIntent(Intent intent) {
Intent newIntent = new Intent(this, AlarmDialog.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
//pass the extras on and show the dialog
newIntent.putExtras(intent);
startActivity(newIntent);
AlarmReceiver.completeWakefulIntent(newIntent);
}
}
My Activity (the notification part)
public class AlarmDialog extends Activity
implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
Bundle extras;
int remId;
String name, notes;
Boolean setalarm;
long alarmTime;
MediaPlayer player;
PendingIntent pendingIntent;
SharedPreferences mPrefs;
NotificationManager manager;
Notification notification;
static final int SNOOZE_BUTTON = -2;
static final int DISMISS_BUTTON = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create notification and alert box if alarmManager selected
mPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
extras = getIntent().getExtras();
alarmTime = extras.getLong("millis");
remId = extras.getInt("remId");
name = extras.getString("name");
notes = extras.getString("notes");
setalarm = extras.getBoolean("setalarm");
//notification first
notification = new RemNotification(this, name).get();
if (notification != null) {
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(remId);
manager.notify(remId, notification);
}
}
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 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);
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.
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();
}