Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓警报震动不工作_Android_Vibration - Fatal编程技术网

Android 安卓警报震动不工作

Android 安卓警报震动不工作,android,vibration,Android,Vibration,我创建了AlarmReceiver类,并在接收报警时添加了振动功能。在我的代码中,一定有一些错误,因为收到警报时振动不会启动。这是代码的一部分: Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds } private Vibrator getSystemService(String vibrat

我创建了AlarmReceiver类,并在接收报警时添加了振动功能。在我的代码中,一定有一些错误,因为收到警报时振动不会启动。这是代码的一部分:

        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // Vibrate for 500 milliseconds


    }


    private Vibrator getSystemService(String vibratorService) {
        // TODO Auto-generated method stub
        return null;

    }
}

当然,我在清单中添加了p
ermission
。我是否需要实现此代码的
getSystemService
,如果我没有实现此方法,则
eclipse
会抛出一个我需要实现此方法的错误。

您不需要实现getSystemService。您需要对其进行caal以访问可控震源对象,然后在其上调用振动方法。 但是,您需要将getSystemService返回的对象强制转换为可控震源

Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500});