Hello everyone!
I noticed that the services of my app get killed if the app is running in backgroud.
Problem happens on huawei phones but after searching online i found that the problem can happen also on other manufacturers.
So i found this thread: https://stackoverflow.com/questions...setting-on-huawei-phones-and-how-to-handle-it
my problem is that i am not skilled in Java and i need some help to port to B4A with In-Line Java. (I copied it to B4A but i get some errors during compilation:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
So my question is: is there someone that can make following code working in B4A? Thank you in advance!
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			I noticed that the services of my app get killed if the app is running in backgroud.
Problem happens on huawei phones but after searching online i found that the problem can happen also on other manufacturers.
So i found this thread: https://stackoverflow.com/questions...setting-on-huawei-phones-and-how-to-handle-it
my problem is that i am not skilled in Java and i need some help to port to B4A with In-Line Java. (I copied it to B4A but i get some errors during compilation:
			
				B4X:
			
		
		
		error: package android.support.v7.widget does not exist
import android.support.v7.widget.AppCompatCheckBox;
                                ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 errorSo my question is: is there someone that can make following code working in B4A? Thank you in advance!
			
				B4X:
			
		
		
		import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.support.v7.widget.AppCompatCheckBox;
import android.widget.CompoundButton;
import java.util.List;
public class Utils {
public static void startPowerSaverIntent(Context context) {
   SharedPreferences settings = context.getSharedPreferences("ProtectedApps", Context.MODE_PRIVATE);
   boolean skipMessage = settings.getBoolean("skipProtectedAppCheck", false);
   if (!skipMessage) {
       final SharedPreferences.Editor editor = settings.edit();
       boolean foundCorrectIntent = false;
       for (Intent intent : Constants.POWERMANAGER_INTENTS) {
           if (isCallable(context, intent)) {
               foundCorrectIntent = true;
               final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(context);
               dontShowAgain.setText("Do not show again");
               dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                   @Override
                   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                       editor.putBoolean("skipProtectedAppCheck", isChecked);
                       editor.apply();
                   }
               });
               new AlertDialog.Builder(context)
                       .setTitle(Build.MANUFACTURER + " Protected Apps")
                       .setMessage(String.format("%s requires to be enabled in 'Protected Apps' to function properly.%n", context.getString(R.string.app_name)))
                       .setView(dontShowAgain)
                       .setPositiveButton("Go to settings", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int which) {
                               context.startActivity(intent);
                           }
                       })
                       .setNegativeButton(android.R.string.cancel, null)
                       .show();
               break;
           }
       }
       if (!foundCorrectIntent) {
           editor.putBoolean("skipProtectedAppCheck", true);
           editor.apply();
       }
   }
}
private static boolean isCallable(Context context, Intent intent) {
   List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
           PackageManager.MATCH_DEFAULT_ONLY);
   return list.size() > 0;
}
}
import android.content.ComponentName;
import android.content.Intent;
import java.util.Arrays;
import java.util.List;
public class Constants {
public static List<Intent> POWERMANAGER_INTENTS = Arrays.asList(
       new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
       new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
       new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
       new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
       new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
       new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
       new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
       new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
       new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
       new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).setData(android.net.Uri.parse("mobilemanager://function/entry/AutoStart"))
);
}