I have a Huawei P8 with Android 5.0 that I'm using for testing an app. The app needs to be running in the background, as it tracks BLE regions.
I've discovered that Huawei has built in a "feature" called Protected Apps, that can be accessed from the phone settings (Battery Manager > Protected Apps). This allows elected apps to keep running after the screen is turned off.
Sensibly for Huawei, but unfortunately for me, it looks like it's opt-in, i.e. apps are out by default, and you have to manually put them in. This isn't a showstopper, as I can advise users in an FAQ or printed documentation about the fix, but I recently installed Tinder (for research purposes!), and noticed that it was put in the protected list automatically.
Does anyone know how I can do this for my app? Is it a setting in the manifest? Is it something Huawei has enabled for Tinder because it's a popular app?
if("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER) && !sp.getBoolean("protected",false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.huawei_headline).setMessage(R.string.huawei_text)
.setPositiveButton(R.string.go_to_protected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
sp.edit().putBoolean("protected",true).commit();
}
}).create().show();
}