We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi.
a simple code to check the battery state worked in processing 2.
it doesn't work anymore in processing 3
(my issue is I can't reinstall android mode in processing 2, the android mode doesn't appear in mode manager).
is this a known bug ?
here's the code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
int level=0;
int charging;
int voltage;
import android.os.BatteryManager;
int temp;
String tech;
void setup()
{
battery_checking();
}
void draw()
{
}
void battery_checking()
{
println("======================");
println("Niveau Batterie :"+level+"% ");
// println("Technologie : "+tech);
// println("Voltage : "+voltage);
// println("Temperature : "+temp);
// println("plugged : "+charging);
println("======================");
}
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@ Override
public void onReceive(Context c, Intent i) {
level = i.getIntExtra("level", 0);
voltage = i.getIntExtra("voltage", 0);
charging = i.getIntExtra("plugged", 0);
tech = i.getStringExtra("technology");
temp = i.getIntExtra("temperature", 0);
}
};
@ Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerReceiver(mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
thanks in advance !
Answers
In what way doesn't it work? Does it print errors? Does it just not return a value?
Android version?
I try with android 7.1 and 6. processing gives me: "the function registerReceiver(BroadcastReceiver, IntentFilter)" doesn't exist...
Here are some previous posts.
https://forum.processing.org/two/search?Search=BroadcastReceiver
Kf
@pauline909=== 2== you are in an Activity; 3== you are in a fragment; i think this is your problem (not tested!!!, guessed!!!) i verify Asap
I made some changes to your code. Check them out,
Kf
cool !!!! it does work, thanks !!!
@pauline909=== what kfrager added (lines 70_72) is the way to write code in a fragment...