Setting a reminder in Wear OS

Is it possible to set a reminder that will alert a user from both a watch and a connected phone, programmatically, in Android, using Wear OS (that is, via an Android smart watch)? I can use the reminder app on my watch to set a reminder, but I cannot do this from an app that I’m developing that is executing on the watch.

I am told that the way to programmatically set a reminder (on a phone) is to use two steps, and the first step is to Send Data from Wear OS to Phone. Specifically, on the Wear OS device, use the Data Layer API to send event details to the phone.

import com.google.android.gms.tasks.Task; import com.google.android.gms.wearable.DataClient; import com.google.android.gms.wearable.DataMap; 
import com.google.android.gms.wearable.PutDataMapRequest; 
import com.google.android.gms.wearable.PutDataRequest; 
import com.google.android.gms.wearable.Wearable;
public void sendEventToPhone(String title, long startTime, long endTime, String location) {
    PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/calendar_event");
    putDataMapReq.getDataMap().putString("title", title);
    putDataMapReq.getDataMap().putLong("startTime", startTime);
    putDataMapReq.getDataMap().putLong("endTime", endTime);
    putDataMapReq.getDataMap().putString("location", location);
    PutDataRequest putDataReq = putDataMapReq.asPutDataRequest();
    Task<DataItem> putDataTask = Wearable.getDataClient(this).putDataItem(putDataReq);
}

The Next step is to receive data on the phone and insert an event by implementing a WearableListenerService to receive the data and insert the event into the calendar.

import android.content.ContentValues;
import android.net.Uri;
import android.provider.CalendarContract;
import com.google.android.gms.wearable.DataEvent;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.WearableListenerService;


public class CalendarEventService extends WearableListenerService {
    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        for (DataEvent event : dataEvents) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                DataMap dataMap = 
                    DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                if (event.getDataItem().getUri().getPath().equals("/calendar_event")) {
                    String title = dataMap.getString("title");
                    long startTime = dataMap.getLong("startTime");
                    long endTime = dataMap.getLong("endTime");
                    String location = dataMap.getString("location");
                    insertEvent(title, startTime, endTime, location);
                }
            }
        }
    }


    private void insertEvent(String title, long startTime, long endTime, String location) {
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Events.DTSTART, startTime);
        values.put(CalendarContract.Events.DTEND, endTime);
        values.put(CalendarContract.Events.TITLE, title);
        values.put(CalendarContract.Events.EVENT_LOCATION, location);
        values.put(CalendarContract.Events.CALENDAR_ID, 1); // Use the default calendar
        values.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC");


        Uri uri = getContentResolver().insert(CalendarContract.Events.CONTENT_URI, values);
        if (uri != null) {
            long eventId = Long.parseLong(uri.getLastPathSegment());
            // Optionally, add a reminder
            ContentValues reminderValues = new ContentValues();
            reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventId);
            reminderValues.put(CalendarContract.Reminders.MINUTES, 15);
            reminderValues.put(CalendarContract.Reminders.METHOD,
                CalendarContract.Reminders.METHOD_ALERT);
            getContentResolver().insert(CalendarContract.Reminders.CONTENT_URI, 
                reminderValues);
        }
    }
}

However, this will not work for my application, as I need the reminder to be set without the phone being powered on. The reason for this is that if the user needs to access the phone, there is no point in using the watch.

Here are some things I’ve tried that don’t work:

First, I tried the following code using WearableCalendarContract, and the code threw an exception indicating that inserts with WearableCalendarContract are not allowed.

   public long createInstance(ContentResolver contentResolver, long i_eventId, long 
            beginTime, long endTime) {
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Instances.EVENT_ID, i_eventId);
        values.put(CalendarContract.Instances.BEGIN, beginTime);
        values.put(CalendarContract.Instances.END, endTime);

        Uri uri = null;
        try {
            uri = contentResolver.insert(WearableCalendarContract.Instances.CONTENT_URI,
                values);
        }
        catch (Exception e){
            int x = 1;
        }
    Cursor cursor = contentResolver.query(WearableCalendarContract.Instances.CONTENT_URI,
            new String[]{CalendarContract.Reminders.EVENT_ID }, null, null, null);
    int wNumInstances = cursor.getCount();

    if (uri == null) {
        return Long.parseLong(uri.getLastPathSegment());
    }

    // Prepare reminder values
    values = new ContentValues();
    // eventId is the ID of the event
    values.put(CalendarContract.Reminders.EVENT_ID, i_eventId); 
    // or METHOD_EMAIL
    values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); 
    values.put(CalendarContract.Reminders.MINUTES, 1); // Reminder 30 minutes before event
    // Insert reminder
    android.net.Uri uri2 = 
        contentResolver.insert(WearableCalendarContract.Reminders.CONTENT_URI, values);
    Cursor cursor2 = contentResolver.query(WearableCalendarContract.Reminders.CONTENT_URI,
            new String[]{CalendarContract.Reminders.EVENT_ID }, null, null, null);
    int wNumReminder = cursor2.getCount();
    return Long.parseLong(uri2.getLastPathSegment());
}

Next: I tried modifying the code to use CalendarContract. This involved changing CalendarContract.Instances.EVENT_ID to CalendarContract.Events.EVENT_ID and related changes for BEGIN & END. The code no longer threw an exception when the insert was executed, yet the insert did not work. This was confirmed by examining the instance count in the wNumInstances = cursor.getCount() line of code indicating that wNumInstances= 0, meaning that no items have been inserted. Is there any way to resolve these issues and add a reminder?

Finally, I tried to find an API that can be used with the Reminder app on the phone (the Reminder app, somehow, can add reminders). My search did not find any API that would allow my app to set reminders through the Reminder app, nor did it show any other API.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật