如何使用用户首选项和复选框显示onGoing通知?我想要消除我的MainActiviy中的电池电量:
private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
. . .
String[] statusbatt = {
"Battery level: " +level+"%",
. . .};
ListView lvStatus = (ListView) findViewById(R.id.lv_status);
lvStatus.setAdapter(new ArrayAdapter<String>(MainActivity.this, R.layout.list, statusbatt));
info.getListViewSize(lvStatus);
}
};
设置首选项:
public class Settings extends SettingsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager()
.findPreference("Checkbox");
////// here the check box code for notfication
}
}
你可以看到我不知道怎么做。有帮助吗? settings.xml中的复选框:
<CheckBoxPreference
android:defaultValue="true"
android:key="first"
android:summary="@string/summary_show"
android:title="@string/Show_notifications" />