TF card plug-in monitor

By registering the monitoring interface, we can know the status of the TF card; here we first need to implement our own monitoring class:

#include "os/MountMonitor.h"

class MyMountListener : public MountMonitor::IMountListener {
    virtual void notify(int what, int status, const char *msg) {
        switch (status) {
        case MountMonitor::E_MOUNT_STATUS_MOUNTED:    // Insert
            // msg is the mount path
            LOGD("mount path: %s\n", msg);
            mMountTextviewPtr->setText("TF card has been inserted");

        case MountMonitor::E_MOUNT_STATUS_REMOVE:     // Remove
            // msg is the uninstall path
            LOGD("remove path: %s\n", msg);
            mMountTextviewPtr->setText("TF card has been removed");

Define the listening object:

static MyMountListener sMyMountListener;

Register to listen:


When we no longer need to monitor, we need to remove the monitor:


For specific operations, please refer to the MountDemo project in Sample Code

powered by Gitbooklast modified: 2021-05-28 12:00:31

results matching ""

    No results matching ""