我想只播放一次音乐,但每分钟播放的代码我怎么能这样做?
public class MainActivity extends AppCompatActivity {
Button BT;
PendingIntent pendingIntent;
public void func()
{
AlarmManager alarmManager=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),1*60*1000,pendingIntent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent=new Intent(MainActivity.this,sv.class);
pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
BT=(Button) findViewById(R.id.button);
BT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
func();
}
});
}
答案 0 :(得分:0)
你有警报类型' setInexactRepeating' - 正如它所暗示的......重复。尝试使用'设置'代替。这里有更多信息:http://developer.android.com/reference/android/app/AlarmManager.html