title: BroadcastReceiver onReceive not called from custom Unity android plugin
body: <p>I'm writing my own Unity plugin for firing timed local notifications on Android. I've managed to make the necessary JNI calls through Unity but for some reason the onReceive method of my BroadcastReceiver is not called. Below is the code for classes included in my plugin. The scheduleNotification method is called from a C# script but there is no notification after the time specified by 'interval' has passed.</p>
  
  <p>The plugin is added as a jar file in Unity (placed at Assets/Plugins/Android/). I also have a res folder at this path which gives me the icons to be used with the notification. What am I doing wrong here? Why is my BroadcastReceiver not called?   </p>
  
  <p><strong>PushPlugin.java</strong></p>
  
  <pre><code>public class PushPlugin extends UnityPlayerActivity
  {
      private static final String TAG = "PushPlugin_Unity";
      private static PushPlugin instance = null;
  
      @Override
      protected void onCreate(Bundle myBundle) {
          instance = this;
          super.onCreate(myBundle);
      }
  
      public static void scheduleNotification(String notificationID,
                                          String message, String objectId, int interval) {
  
          // get a Calendar object with current time
          Calendar cal = Calendar.getInstance();
          cal.add(Calendar.SECOND, interval);
  
          Intent intent = new Intent(UnityPlayer.currentActivity.getApplicationContext(), PluginBroadcastReceiver.class);
          intent.putExtra("notificationID", notificationID);
          intent.putExtra("message", message);
          intent.putExtra("objectId", objectId);
  
          PendingIntent sender = PendingIntent.getBroadcast(UnityPlayer.currentActivity.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          // Get the AlarmManager service
          AlarmManager am = (AlarmManager) UnityPlayer.currentActivity.getApplicationContext().getSystemService(UnityPlayer.currentActivity.getApplicationContext().ALARM_SERVICE);
          am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
  
      }
  }
  </code></pre>
  
  <p><strong>PluginBroadcastReceiver.java</strong></p>
  
  <pre><code>public class PluginBroadcastReceiver extends BroadcastReceiver {
  public static Bundle extras = new Bundle();
  static final String TAG = "PushPlugin-BR";
  public static final int NOTIFICATION_ID = 1;
  private NotificationManager mNotificationManager;
  NotificationCompat.Builder builder;
  Context ctx;
  
  @Override
  public void onReceive(Context context, Intent intent) {
      ctx = context;
  
      // Local notification.
      Bundle bundle = intent.getExtras();
      String notificationID = bundle.getString("notificationID");
      String message = bundle.getString("message");
      String objectId = bundle.getString("objectId");
  
      Log.v(TAG, "Received local notification of type: " + notificationID
              + " and message: " + message + " and objectId " + objectId);
  
      sendNotification(message, notificationID, objectId);
  }
  
  // Put the GCM message into a notification and post it.
  private void sendNotification(String msg, String notifID, String objectID) {
      mNotificationManager = (NotificationManager) ctx
              .getSystemService(Context.NOTIFICATION_SERVICE);
  
      Intent intent = new Intent(ctx, PushPlugin.class);
  
      PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
              intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
      extras.putString("notificationID", notifID);
      extras.putString("message", msg);
      extras.putString("objectId", objectID);
  
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
              ctx);
  
      Resources res = ctx.getResources();
      int icon = res.getIdentifier("app_icon", "drawable", UnityPlayer.currentActivity.getPackageName());
  
      mBuilder.setSmallIcon(icon);
      mBuilder.setContentTitle("Plugin Test");
      Log.v(TAG, "-------- notification received: " + msg);
      mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
      mBuilder.setContentText(msg);
      mBuilder.setContentIntent(contentIntent);
      mBuilder.setAutoCancel(true);
  
      mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.test.app"
  android:versionCode="1"
  android:versionName="1.0"&gt;
  &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
  &lt;!-- gcm --&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
  &lt;permission android:name="com.test.app.permission.C2D_MESSAGE"
  android:protectionLevel="signature" /&gt;
  &lt;uses-permission android:name="com.test.app.permission.C2D_MESSAGE" /&gt;
  
  &lt;application android:label="@string/app_name"&gt;
      &lt;activity android:name=".PushPlugin"
          android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver
          android:name=".PluginBroadcastReceiver"
          android:permission="com.google.android.c2dm.permission.SEND" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;category android:name="com.test.app" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;service android:name=".PluginIntentService" /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>