Calling other application within sketch (Android code share)

My initial goal was to call call different sketches one after another, but there is still a white screen visible for a fraction of a second, so I have to use an boolean if in draw() to do it smoothless.
Nevertheless it can be handy to call other app’s within sketch programmatically, so I decided to share it.
The code below will print a list with the the package names of all installed app’s so that you copy them to the launcher activity.

import android.content.Intent;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo; 
import android.content.pm.PackageInfo;
import java.util.List;

Activity act;
PackageManager pm;
ApplicationInfo packageInfo;
int i;

void setup() {
  act = this.getActivity();
  pm = act.getPackageManager();
  List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
  for (ApplicationInfo  packageInfo : packages) {
    if (pm.getLaunchIntentForPackage(packageInfo.packageName)!= null
      && !pm.getLaunchIntentForPackage(packageInfo.packageName).equals("")) {
      println("Package Name :" + packageInfo.packageName);
      println("Launch Intent For Package :"   + pm.getLaunchIntentForPackage(packageInfo.packageName));
      println("Application Label :"   + pm.getApplicationLabel(packageInfo));
      println("i : "+i);
      /*
      if (i==85) {
       startActivity(pm.getLaunchIntentForPackage(packageInfo.packageName));
       break;
       }
       */
      i++;
    }
  }
}

void draw() {
}

void mousePressed() {
  // Be sure to have no spaces in packageName string
  startActivity(pm.getLaunchIntentForPackage("com.android.chrome"));
}
3 Likes

do u now how to return to the mainactivity ? Or how to close the processing sketch without closing the entire app

I don’t understand quite well what you want.
If you run the code above the browser will open. If you then hit the back button the latest activity will return, meaning the processing sketch. If you tap on links in the browser, every time you use the back button it will return to the latest number of the activity stack until you reach processing’s activity again. The only way to return right to the sketch activity is by tapping the “recent apps” button (sometimes long tapping the home button), and choose it there.
If you want to close/end the sketch activity at the moment you call the other app you just add:
act.finish();
in mousePressed.

Muchas gracias por tu codigo , no soy para nada experto en programar android , pero este sketch me ayudo a aprender unas dudas que tenia , muy amable !