I was creating a simple notification app, but which is not showing any notification. I have used BroadcastReceiver and service for showing it up. It doesn't showing any errors but still not working.
MainActivity.java
package com.example.myapplication;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
int NOTIFICATION_REMINDER_NIGHT = 1;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setBroadcast(this);
}
void setBroadcast(Context context)
{
Intent notifyIntent = new Intent(this, MyReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast
(context, NOTIFICATION_REMINDER_NIGHT, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
1000 * 60 * 15, pendingIntent);
}
}
MyNewIntentService.java
package com.example.myapplication;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentSender;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationManagerCompat;
public class MyNewIntentService extends IntentService
{
private static final int NOTIFICATION_ID = 1;
#Override
public void onCreate() {
super.onCreate();
startForeground(NOTIFICATION_ID, new Notification());
}
/**
* #param name
* #deprecated
*/
public MyNewIntentService(String name) {
super(name);
}
public MyNewIntentService(){
super("service");
}
#Override
protected void onHandleIntent(#Nullable Intent intent)
{
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("My title");
builder.setContentText("This is the body");
builder.setSmallIcon(R.drawable.ic_launcher_background);
Intent notifyIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,2, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification notificationCompat = builder.build();
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(NOTIFICATION_ID, notificationCompat);
}
}
MyReceiver.java
package com.example.myapplication;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
public class MyReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Intent intent1 = new Intent(context, MyNewIntentService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, MyNewIntentService.class));
} else {
context.startService(new Intent(context, MyNewIntentService.class));
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyApplication"
tools:targetApi="31">
<service
android:name=".MyNewIntentService"
android:enabled="true"
android:exported="true"></service>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<receiver android:name=".MyReceiver"
android:enabled="true"
android:exported="false"/>
</application>
</manifest>
log
android.app.RemoteServiceException:
Bad notification for startForeground
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2275)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:257)
at android.app.ActivityThread.main(ActivityThread.java:8246)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1016)
what's the problem? is there any os validations.
Thanks.
This error is likely because you're just using an empty notification. Take your logic from onHandleIntent, and use it to construct the notification when calling context.startForeground(...)
Also, AlarmManager::setRepeating is not reliable in modern versions of Android. I would recommend you use setAlarmClock or setExactAndAllowWhileIdle instead.
I have a complete example of an alarm app on my GitHub here, which may be useful for you.
Related
i create an android notification with a compiled sdk version of 28 with min sdk version of 26, i actually developing android that need a notification so 1st i create an android notification separated from my FirstApplication, it works fine but when i add this notification in my FirstApplication the notification doesn't appear.
App.java
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
public class App extends Application {
public static final String CHANNEL_1_ID = "channel1";
public static final String CHANNEL_2_ID = "channel2";
#Override
public void onCreate() {
super.onCreate();
createNotificationChannels();
}
private void createNotificationChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel1 = new NotificationChannel(
CHANNEL_1_ID,
"Channel 1",
NotificationManager.IMPORTANCE_HIGH
);
channel1.setDescription("This is Channel 1");
NotificationChannel channel2 = new NotificationChannel(
CHANNEL_2_ID,
"Channel 2",
NotificationManager.IMPORTANCE_LOW
);
channel2.setDescription("This is Channel 2");
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel1);
manager.createNotificationChannel(channel2);
}
}
}
MainActivity.java
import android.app.Notification;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import static com.project.cms.App.CHANNEL_1_ID;
import static com.project.cms.App.CHANNEL_2_ID;
public class MainActivity extends AppCompatActivity {
private NotificationManagerCompat notificationManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
notificationManager = NotificationManagerCompat.from(this);
sendchannel()
sendchannel2()
}
public void sendchannel(){
Notification notification = new NotificationCompat.Builder(this, CHANNEL_1_ID)
.setSmallIcon(R.drawable.ic_one)
.setContentTitle("Appointment Request")
.setContentText("ACCEPTED")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.build();
notificationManager.notify(1, notification);
}
public void sendchannel2(){
Notification notification = new NotificationCompat.Builder(this, CHANNEL_2_ID)
.setSmallIcon(R.drawable.ic_one)
.setContentTitle("Appointment Request")
.setContentText("DECLINED")
.setPriority(NotificationCompat.PRIORITY_LOW)
.build();
notificationManager.notify(2, notification);
}
}
when i open the app, the notification should appear but it doesn't work. So im asking you guys to help me and check my code if im missing something or what.
look at this what i am trying to say:-
In your application tag add
name="App" which is your class name of creating channels and also extends the Application class
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<application
android:name=".notification"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
<activity android:name=".Main2Activity" />
<activity android:name=".Main3Activity"/>
<service android:name=".MyService"
android:enabled="true"/>
<service android:name=".Service"
android:enabled="true"/>
<provider
android:authorities="${applicationId}.provider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
</application>
I have an App where a background service running . When a phone call is detected I want that app to open and show me a particular Intent. How should I do this.
My code is
MainActivity.java
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.lang.reflect.Method;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startService(View view){
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener phoneStateListener = new PhoneStateListener(){
#Override
public void onCallStateChanged(int state, String incomingNumber) {
String number = incomingNumber;
Log.d("gaandu", number);
if(state == TelephonyManager.CALL_STATE_RINGING){
Toast.makeText(MainActivity.this, "incoming call from" + incomingNumber, Toast.LENGTH_SHORT).show();
}
if(state == TelephonyManager.CALL_STATE_OFFHOOK){
Toast.makeText(MainActivity.this, "Phone is currently in a call", Toast.LENGTH_SHORT).show();
}
if(state == TelephonyManager.CALL_STATE_IDLE){
Toast.makeText(MainActivity.this, "Phone is neither Ringing nor in a Call", Toast.LENGTH_SHORT).show();
}
}
};
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
public void stopService(View view){
Intent i = new Intent(MainActivity.this, MyService.class);
stopService(i);
}
}
MyService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
#Override
public void onCreate() {
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_SHORT).show();
return START_STICKY;
}
#Override
public void onDestroy() {
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_SHORT).show();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.abab">
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
<service android:name=".MyService"
android:exported="false"
/>
</application>
</manifest>
In MainActivity.java, after a phone call has been detected, I want to launch my app running in background to open to its first Activity.
You might want to look into the Android cookbook:
You want to act on an incoming phone call and do something with the incoming number.
Solution:
This can be achieved by implementing a Broadcast receiver and listening for a TelephonyManager.ACTION_PHONE_STATE_CHANGED action.
You probably need to do some more research; depending the version of Android you are targeting!
Try this link. hope this will help you. Transparent your activity will help you some what.
Go through this link also
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
I've searched the archives and still can't resolve my issue.
I'm trying to take an user input in seconds that will call the broadcast receiver to create a toast message and vibrate the phone. However, the broadcast receiver is never called and I can't figure it out. My code is below.
Thanks!
package com.example.cs984x.alrm;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText inputSeconds = (EditText) findViewById(R.id.editText1);
int inputTime = Integer.parseInt(inputSeconds.getText().toString());
Toast.makeText(MainActivity.this, "The alarm will go off in " + inputTime + " seconds.", Toast.LENGTH_LONG).show();
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
myIntent.setAction("com.example.cs984x.alrm.vibrate");
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(inputTime*1000), pendingIntent);
}
});
}
}
Broadcast Receiver Class:
package com.example.cs984x.alrm;
import android.app.AlarmManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.widget.EditText;
import android.widget.Toast;
import static android.content.Context.ALARM_SERVICE;
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Your time is up", Toast.LENGTH_LONG).show();
Vibrator v;
v= (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(2000);
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cs984x.alrm">
<uses-permission android:name="android.permission.VIBRATE" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
</application>
<receiver
android:name=".MyReceiver" android:process=":remote"
android:enabled="true">
<intent-filter>
<action android:name="com.example.cs984x.alrm.vibrate" />
</intent-filter>
</receiver>
</manifest>
Add action to intent:
Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
myIntent.setAction("YourPackageName.YourAction");
PendingIntent pendingIntent =PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
in AndroidManifest:
<intent-filter>
<action android:name="YourPackageName.YourAction" />
</intent-filter>
I am trying to create a notification when an alarm triggers.But alarm is not triggering and also no notification is displaying. Here is Here is the MainActivity.java file -
package com.kaushal28.kaushal1
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scheduleAlarm();
}
public void scheduleAlarm()
{
Long time = new GregorianCalendar().getTimeInMillis()+10000;
Intent intentAlarm = new Intent(this, AlarmReciever.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(this,1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
Toast.makeText(this, "Alarm Scheduled", Toast.LENGTH_LONG).show();
}
}
And here is the AlarmReciever Class -
package com.kaushal28.kaushal1;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
public class AlarmReciever extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent1)
{
System.out.println("Notification setup");
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intent=new Intent(context,MainActivity.class);
PendingIntent pendingIntent=PendingIntent.getActivity(context,1,intent,0);
Notification notification=new Notification.Builder(context)
.setContentText("TESTING NOTIFIACTION")
.setContentTitle("Notification")
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setSound(sound)
.build();
NotificationManager notificationManager= (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE) ;
notificationManager.notify(1,notification);
}
}
And here is my menifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kaushal28.kaushal1">
<uses-permission android:name="android.permission.WAKE_LOCK"></uses- permission>
<receiver android:process=":remote" android:name=".Alarm"></receiver>
<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>
</application>
</manifest>
What I'm missing here? Any help will be appreciated.
The receiver is missing from the manifest file you need to add it according to the docs.
For brevity, I paraphrase the relevant bits:
Add the receiver to your app's manifest file:
<receiver android:name=".AlarmReciever"
android:enabled="false">
</receiver>
On my Android app I am trying to run a task every 3 minutes, and if the CPU is asleep then it should wake up and run my task; my task is called CheckTask and is a Runnable. I know AlarmManager is what I need and I have been trying to get it working but the OnReceive() method is never executed. Here is the relevant code below, please tell me what is wrong so I can fix it and get it working.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.charles.sitechecker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.charles.sitechecker.MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".LocalService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.charles.sitechecker.LocalService" />
</intent-filter>
</service>
<receiver
android:name="com.charles.sitechecker.Alarm"
android:enabled="true"/>
</application>
Alarm.java
package com.charles.sitechecker;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Alarm extends BroadcastReceiver
{
private MainActivity mainActivity;
private AlarmManager aManager;
public Alarm()
{
}
Alarm(MainActivity mainActivity)
{
this.mainActivity = mainActivity;
aManager = (AlarmManager)mainActivity.getSystemService(Context.ALARM_SERVICE);
}
void scheduleAlarm()
{
Intent intent = new Intent(mainActivity, Alarm.class);
PendingIntent pIntent = PendingIntent.getBroadcast(mainActivity, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
aManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(), 180000, pIntent);
}
public void onReceive(Context context, Intent intent)
{
Runnable task = new CheckTask(mainActivity);
task.run();
}
}
LocalService.java
package com.charles.sitechecker;
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.IBinder;
public class LocalService extends Service
{
public void onCreate()
{
Notification n = MainActivity.checkTask.mainActivity.notifier.sendOngoingNotification("SiteChecker", "Sleeping", -1);
startForeground(-1, n);
Alarm alarm = new Alarm(MainActivity.checkTask.mainActivity);
alarm.scheduleAlarm();
}
public void onDestroy()
{
super.onDestroy();
}
public IBinder onBind(Intent intent)
{
return null;
}
public int onStartCommand(Intent intent, int flags, int startId)
{
return START_STICKY;
}
}
an example class to set alarm in mainactivity:
public void setRepeatingAlarm()
{
Intent intent = new Intent(this, ReceiveAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(*time_in_milis to repeat*), pendingIntent);
}
Broadcast Receiver:
public class ReceiveAlarm extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, InService.class));
}
}
Intent service class example:
public class InService extends IntentService
{
public InService() {
super("InService");
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
//do your thing here
}
}
Declare your broadcast receiver / service class in manifest inside tags
<receiver android:name="ReceiveAlarm" />
<service android:name="InService"></service>
Try this.
I think you may need to implement a WakeLock. This requires a specific permission, and allows your app to "wake-up" the device to do work.
I used the example referenced in this SO question when I implemented my alarm (many moons ago), and it works well for me.
AlarmManager and WakeLock example
the specific example link is: (from CommonsGuy)
https://github.com/commonsguy/cw-omnibus/tree/master/AlarmManager/Wakeful