小编Fai*_*yed的帖子

Android - 从通知操作按钮调用方法

我知道您可以使用PendingIntents从操作按钮启动活动.如何在用户单击通知操作按钮时调用方法?

public static void createNotif(Context context){
    ...
    drivingNotifBldr = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.steeringwheel)
            .setContentTitle("NoTextZone")
            .setContentText("Driving mode it ON!")
            //Using this action button I would like to call logTest
            .addAction(R.drawable.smallmanwalking, "Turn OFF driving mode", null)
            .setOngoing(true);
    ...
}

public static void logTest(){
    Log.d("Action Button", "Action Button Worked!");
}
Run Code Online (Sandbox Code Playgroud)

android android-layout android-notifications action-button

14
推荐指数
1
解决办法
2万
查看次数