1

I tried making an app that sends a custom notification to android wear, that part worked but then I wanted to implement a service so that the app will send the notification every minute. But I am missing something,can you guys help me please? Thanks a lot! The error points to "this", I am new to android programming, I really don't know how to solve this.

public class MainActivity extends Activity {

public class notifService extends Service {
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

    public IBinder onBind(Intent arg0) {
        return null;
    }


    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        final Intent intent1 = new Intent(this, notifService.class);

        scheduler.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                setContentView(R.layout.activity_main);
                //Create PendingIntent
                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
                //Create Notification Action
                NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                        R.mipmap.app_icon, getString(R.string.wearTitle), pendingIntent).build();
                //Create Notification
                Notification notification = new NotificationCompat.Builder(this)
                        .setContentText(getString(R.string.content))
                        .setContentTitle(getString(R.string.title))
                        .setSmallIcon((R.mipmap.app_icon))
                        .extend(new NotificationCompat.WearableExtender().addAction(action))
                        .build();
                //Create Notification Manager
                NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
                notificationManagerCompat.notify(001, notification);
            }
        }, 60, 60, TimeUnit.SECONDS);
Alex Acea
  • 11
  • 2

0 Answers0