AlarmManager一次性报警不会触发

时间:2016-08-13 07:04:19

标签: android alarmmanager

我想用以下内容触发一次性警报,这基本上是来自https://developer.android.com/training/scheduling/alarms.html的复制(第二个ELAPSED_REALTIME_WAKEUP示例)。

这是在公共静态类里面PlaceholderFragment extends Fragment实现了View.OnClickListener:

global $product; 

// Get product attributes
$attributes = $product->get_attributes();

if ( ! $attributes ) {
    echo "No attributes";
}

foreach ( $attributes as $attribute ) {

        echo $attribute['name'] . ": ";
        $product_attributes = array();
        $product_attributes = explode('|',$attribute['value']);

        $attributes_dropdown = '<select>';

        foreach ( $product_attributes as $pa ) {
            $attributes_dropdown .= '<option value="' . $pa . '">' . $pa . '</option>';
        }

        $attributes_dropdown .= '</select>';

        echo $attributes_dropdown;
}

公共类MuteReceiver扩展BroadcastReceiver是这样的:

    @Override 
    public void onClick(View v) {
        Intent intent;
        intent = new Intent(this.getActivity(), MuteReceiver.class);
        AlarmManager alm = (AlarmManager)(this.getActivity().getSystemService(Context.ALARM_SERVICE));
        PendingIntent alarmIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
        alm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + 60*1000, 
            alarmIntent);
        Log.d("MainActivity", "alarm set");
    }

我按下片段中的按钮,看到日志消息&#34;闹钟设置&#34;,但是一分钟后(以及之后),仍然没有关于正在构建MuteReceiver或MuteReceiver启动的日志(在onReceive中)< / p>

1 个答案:

答案 0 :(得分:0)

您有一个带有注册广播的保证列表文件

相关问题