title: Android get method of BroadcastReceiver
body: <p>How can I get the method in my BroadcastReceiver into my Fragment?
  Or is it even possible?
  receiver:</p>
  
  <pre><code>public class Receiver extends BroadcastReceiver {
  
  
      public void test(Context c) {
       ....
      }
  
  }
  </code></pre>
  
  <p>Fragment:</p>
  
  <pre><code>public class Test extends Fragment {
  ...
  }
  </code></pre>
  
  <p>So a error appeared:</p>
  
  <blockquote>
    <p>Attempt to invoke virtual method 'android.content.Context
    android.content.Context.getApplicationContext()' on a null object
    reference
                at </p>
  
  <pre><code>com.test.tab.MyReceiver.sendNotificationIfTimeEnd01(MyReceiver.java:47)
  
          at com.test.tab.Juli.broadcastIntent(Juli.java:54)
  
          at com.test.tab.Juli.onCreateView(Juli.java:188)
  </code></pre>
  </blockquote>
  
  <p>The code for those lines are:
  in Receiver:</p>
  
  <pre><code>    public void sendNotificationIfTimeEnd01(Context c) {
          Context context = c.getApplicationContext();
          Intent intent01 = new Intent(context, MainActivity.class);
  ....
  }
  </code></pre>
  
  <p>and in Fragment:</p>
  
  <blockquote>
  <pre><code>    receiver.sendNotificationIfTimeEnd01(context);
      broadcastIntent();
  </code></pre>
  </blockquote>
  
  <p>EDIT UPGRADED CODE:
  Fragment:</p>
  
  <pre><code>public class FragmentTest extends Fragment {
  
      private Context context;
  
  
      IntentFilter filter = new IntentFilter("com.example.Broadcast");
  MyReceiver receiver = new MyReceiver();
  
  // Call this method when the condition is met.
  public void broadcastIntent() {
      Intent intent = new Intent();
      intent.setAction("com.example.Broadcast");
      getActivity().sendBroadcast(intent);
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    if (diffDays &lt;= 0 &amp;&amp; diffHours &lt;= 0 &amp;&amp; diffMinutes &lt;= 0) {
          ((TextView) android.findViewById(R.id.test)).setText("test works");
          if (!notification043 &amp;&amp; !buttonColor01.equals("red01")) {
              broadcastIntent();
              editor.putBoolean("notification43", true);
              editor.apply();
          }
      } 
  </code></pre>
  
  <p>}</p>
  
  <p>MyReceiver:</p>
  
  <pre><code>public class MyReceiver extends BroadcastReceiver {
      public static final int NOTIFICATION_ID_01 = 1;
  
      @Override
      public void onReceive(Context context, Intent intent) {
          sendNotificationIfTimeEnd01(context);
      }
  
      public void sendNotificationIfTimeEnd01(Context c) {
          Context context = c.getApplicationContext();
          Intent intent01 = new Intent(context, MainActivity.class);
          PendingIntent pendingIntent01 = PendingIntent.getActivity(context, 1, intent01, 0);
          NotificationCompat.Builder builder =
                  new NotificationCompat.Builder(context)
                          .setSmallIcon(R.drawable.ic_stat_notification)
                          .setContentIntent(pendingIntent01)
                          .setAutoCancel(true)
                          .setLargeIcon(BitmapFactory.decodeResource(c.getResources(), R.drawable.ic_launcher))
                          .setContentTitle(testArray[0])
                          .setContentText("testready")
                          .setSubText("click here");
          NotificationManager notificationManager =
                  (NotificationManager) c.getSystemService(c.NOTIFICATION_SERVICE);
          notificationManager.notify(NOTIFICATION_ID_01, builder.build());
          try {
              Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
              Ringtone r = RingtoneManager.getRingtone(c.getApplicationContext(), notification);
              r.play();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>