我是 Android 编程新手。我创建了一个警报管理器和广播管理器程序。广播管理器类被定义为主要活动中的内部类。但是内部类不起作用。我也在这里给出代码。请帮我。
public class Alarmactivity extends Activity {
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button) findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startAlert(null);
}
});
}
public void startAlert(View view) {
AlarmManager am=(AlarmManager)this.getSystemService(this.ALARM_SERVICE);
Intent i = new Intent(this, Broadcas.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0,i,0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 15, pi);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class Broadcas extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("**********************hello***********************************");
}
}
}