0
A
回答
0
那么你提供的信息不多,你想要做什么。所以我想你想创建后台服务来操纵其状态栏图标来显示电池状态。因此,我建议以下有关Android服务和状态栏通知的网站。
http://developer.android.com/reference/android/app/Service.html
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
如果还有问题随时问。
0
伙计,这是通知的代码
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,"Testing",System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent(this,KillerActivity.class);
PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
notification.setLatestEventInfo(getApplicationContext(), "Varaha ", "Testing", penInt);
notifi.notify(215,notification);
这里215是关联与通知栏的唯一ID
Intent i = new Intent(this,KillerActivity.class);
这里KillerActivity.class是类的名称上意图ü想要显示通知
+0
我的意思是显示电池电量,而不是一个字符串。 – 2012-02-23 16:13:25
0
使用此代码可以获得电池的使用量,电池电压和温度。
@Override
public void onCreate() {
BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
int scale = -1;
int level = -1;
int voltage = -1;
int temp = -1;
@Override
public void onReceive(Context context, Intent intent) {
level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
Log.e("BatteryManager", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage);
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryReceiver, filter);
}
//使用这个代码张贴通知,你会得到想要的结果的活动
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,"Testing",System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent(this,KillerActivity.class);
PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
notification.setLatestEventInfo(getApplicationContext(), "Varaha ", "Testing", penInt);
notifi.notify(215,notification);
合并上面的代码片断
相关问题
- 1. 关于电池级别的iOS通知
- 2. 获取没有WMI的电池信息
- 3. 电池充电通知
- 4. 电池信息服务。要监控电池状态等
- 5. Android电池电量通知&5分钟关机后关机/关机设备
- 6. 有关电话号码的信息
- 7. Spring如何通知有关实例何时销毁的信息?
- 8. 我可以获得有关通知(apn)的信息
- 9. 通过电子邮件发送有关IP更改的信息
- 10. 在我的笔记本电脑中伪造电池信息
- 11. 通知栏关闭按钮
- 12. 如何通过应用程序获取有关android电池使用情况的信息
- 13. 带电池电量的iOS通知推送
- 14. 如何禁用Android通知栏上的短信通知图标?
- 15. 检查AltBeacon信标的电池电量
- 16. 我想通过通知发送信息
- 17. 我的通知消息不会显示在通知栏中,只有标题?
- 18. Fail2ban为电子邮件通知添加更多信息
- 19. 有关RDLC的信息
- 20. 如何隐藏GXT的信息通知?
- 21. 如何获取有关Google图表中选定栏的信息?
- 22. 显示有关状态栏上连接状态的信息
- 23. 获取Windows CE 5.0设备的电池信息
- 24. codenameone中用于获取电池信息的本地接口
- 25. 如何在我的应用程序中获取电池信息?
- 26. 从命令行获取电池统计信息的问题
- 27. 如何获取索尼smartwatch 2的电池信息?
- 28. 在Android手机中更新电池信息的时间间隔
- 29. 如何刷新/通知所有短信应用程序和通知栏?
- 30. 是否有CLI方式显示有关Glassfish JDBC连接池的信息?
对不起,我的意思是这些人恰恰是出现在通知酒吧。 https://lh3.ggpht.com/ZKaSQ1xmJBV_RZVSOTS6kFIAMLV3nivGPWOqCzJ5-0WU4XBeLN9OZZXcegDE5WLwNgs – 2012-02-23 13:34:56
是的。这是您在我的第二个链接中看到的通知。但是你需要一个上下文来通知。这意味着一项服务或活动。 – Moritz 2012-02-23 16:14:07