Code Monkey home page Code Monkey logo

Comments (3)

marchbold avatar marchbold commented on August 18, 2024

Start app, can be done with the Share ANE:

https://docs.airnativeextensions.com/docs/share/launch-applications

Restarting an app and stopping an app however aren't implemented anywhere.

Do you have the code you have used previously? I believe this will be even more restricted with Android 30, they have limited a lot of package control outside your own app now.

from ane-packagemanager.

AlexanderMaydorf avatar AlexanderMaydorf commented on August 18, 2024

Hi Michael,

we did all a maybe very dirty way - but it worked and it's still working so far...

The reason for this was, that we was doing some development with MOVERIO glasses from EPSON. We created some "helper apps" outside our main app. To control these helpers - we used our ANE.

to stop:

we pass the argument "updateFilee"

public class UpdaterStopApp implements FREFunction {
	
	public static final String NAME = "UpdaterStopApp";

    
	@Override
	public FREObject call(FREContext context, FREObject[] passedArgs) {

		FREObject result = null;
		UpdaterCtx updater = (UpdaterCtx) context;

		try {

			FREObject fro = passedArgs[0];
			String updateFile= fro.getAsString();
               	
			ActivityManager manager =  (ActivityManager) updater.getActivity().getSystemService(Context.ACTIVITY_SERVICE);
		    List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses();

		    for (int i = 0; i < activityes.size(); i++){
		        if (!activityes.get(i).processName.equals(updateFile)){
		            android.os.Process.killProcess(activityes.get(i).pid);
		        }

		    }
         	
             return FREObject.newObject(true);
		}
		catch (Exception e) {
	        // done
		}
		return result;
	}

}

to start we used this:

public class UpdaterCallApp implements FREFunction {
	
	public static final String NAME = "UpdaterCallApp";
    
	@Override
	public FREObject call(FREContext context, FREObject[] passedArgs)
	{

		FREObject result = null;
		UpdaterCtx updater = (UpdaterCtx) context;

		try
		{

			FREObject fro = passedArgs[0];
			String updateFile= fro.getAsString();
	  
		      Intent intent = new Intent("android.intent.action.MAIN");
		        intent.addCategory("android.intent.category.LAUNCHER");

		        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
		        List<ResolveInfo> resolveInfoList = updater.getActivity().getPackageManager().queryIntentActivities(intent, 0);

		        for(ResolveInfo info : resolveInfoList){
		            if(info.activityInfo.packageName.equalsIgnoreCase(updateFile))
		            {
		                launchComponent(info.activityInfo.packageName, info.activityInfo.name,updater);
		    	        result = FREObject.newObject(true);
		            }
		        }
	        result = FREObject.newObject(false);
		}	catch (Exception e) {
	        // done
		}
		return result;
	}

and for restart - just a combination:

public class UpdaterRestart implements FREFunction {
	
	public static final String NAME = "UpdaterRestart";
    
	@Override
	public FREObject call(FREContext context, FREObject[] passedArgs) {

		FREObject result = null;
		UpdaterCtx updater = (UpdaterCtx) context;

		try {

			FREObject fro = passedArgs[0];
			String updateFile= fro.getAsString();

			ActivityManager manager =  (ActivityManager) updater.getActivity().getSystemService(Context.ACTIVITY_SERVICE);
		    List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses();

		    for (int i = 0; i < activityes.size(); i++){
		        if (!activityes.get(i).processName.equals(updateFile)){
		            android.os.Process.killProcess(activityes.get(i).pid);
		            
		        }

		    }
		    Intent intent = new Intent("android.intent.action.MAIN");
	        intent.addCategory("android.intent.category.LAUNCHER");

	        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
	        List<ResolveInfo> resolveInfoList = updater.getActivity().getPackageManager().queryIntentActivities(intent, 0);

	        for(ResolveInfo info : resolveInfoList){
	            if(info.activityInfo.packageName.equalsIgnoreCase(updateFile))
	            {
	                launchComponent(info.activityInfo.packageName, info.activityInfo.name,updater);
	    	        result = FREObject.newObject(true);
	            }
	        }
						
	        result = FREObject.newObject(true);
		}
		catch (Exception e) {
	        // done
		}
		return result;
	}








private void launchComponent(String packageName, String name,UpdaterCtx updater)
	{
	    Intent intent = new Intent("android.intent.action.MAIN");
	    intent.addCategory("android.intent.category.LAUNCHER");
	    intent.setComponent(new ComponentName(packageName, name));
	    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	    updater.getActivity().startActivity(intent);
	}

from ane-packagemanager.

marchbold avatar marchbold commented on August 18, 2024

Okay, thanks will investigate. Definitely have a feeling some of this won't work in Android 30, but will see what we can do.

from ane-packagemanager.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.