android:-警报管理器不工作
在我的代码中,警报管理器不起作用。我的应用程序的其余部分运行良好。请参阅我的代码。
Intent myIntent = new Intent(getApplicationContext(), AndroidAlarmService.class);
myIntent.putExtra("class", "home");
PendingIntent pendingIntent = PendingIntent.getService(this, 0,myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),6000,pendingIntent);
和我的 android AlarmService 类:-
public class AndroidAlarmService extends BroadcastReceiver implements URLs{
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("BroadCast\n");
String name=intent.getStringExtra("class");
if(name.equals("home")){
Intent homeIn=new Intent(context,Home.class);
context.startActivity(homeIn);
}
}
}
在清单中我已经这样做了;
<receiver android:name=".AndroidAlarmService" android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
为什么它不工作?
In my code alarm manger is not working.Rest of my application is working well.Please see my code.
Intent myIntent = new Intent(getApplicationContext(), AndroidAlarmService.class);
myIntent.putExtra("class", "home");
PendingIntent pendingIntent = PendingIntent.getService(this, 0,myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),6000,pendingIntent);
and my android AlarmService class:-
public class AndroidAlarmService extends BroadcastReceiver implements URLs{
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("BroadCast\n");
String name=intent.getStringExtra("class");
if(name.equals("home")){
Intent homeIn=new Intent(context,Home.class);
context.startActivity(homeIn);
}
}
}
in manifest I have done this;
<receiver android:name=".AndroidAlarmService" android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
Why its not working??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我得到了答案。我做了以下更改:
在我的 AndroidAlarmService 类中:
I got the answer.I made following changes:
In my AndroidAlarmService class:
我遇到了同样的问题,直到我发现我将广播接收器放在了不同的包上,而不是通用的包上。
简单地改变:
为:
I had the same problem until I found that I had put my Broadcast Receiver on a different package, not the general.
Simply changed:
for:
您是否尝试过
将 6000 更改为其他内容?看来您其他一切都正确。
编辑:
确保您的清单中具有 Read_phone_state 权限。
Have you tried changing the
Have you tried changing the 6000 to something else? It seems like you have everything else correct.
EDIT:
Make sure you have the Read_phone_state permission in your manifest.