메인페이지에서 버튼클릭할시
RealService 클래스 안에 public void sendNotification(Double Lat, Double Long) 를 호출시켜
푸쉬를 전송하려고하는데 계속 오류가나네요..
Process: dpm.location.tracker, PID: 20887
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.app.PendingIntent.getActivity(PendingIntent.java:345)
at android.app.PendingIntent.getActivity(PendingIntent.java:312)
at dpm.location.tracker.RealService.sendNotification(RealService.java:152)
at dpm.location.tracker.JobServiceDemoActivity$1.onClick(JobServiceDemoActivity.java:91)
메인페이지
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RealService realService = new RealService();
Double aa = 123.123;
Double bb = 123.123;
//realService.new update_gps2(aa, bb).execute();
realService.sendNotification(aa,bb);
}
});
이구 RealService페이지는
public void sendNotification(Double Lat, Double Long) {
Intent intent = new Intent(RealService.this, JobServiceDemoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(RealService.this.context, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); // 오류난부분입니다.
String channelId = "fcm_default_channel";//getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)//drawable.splash)
.setContentTitle("Service test")
.setContentText(Lat+"-"+Long)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(Notification.PRIORITY_HIGH)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,"Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
new update_gps2(Lat, Long).execute();
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
//notificationManager.cancelAll();
}
입니다,
도움좀 부탁드립니다.