Running Processing Sketches on Android

edited March 2018 in Android Mode

I have added "processing-android-core.jar" file to my Android Studio project. In order to run my Processing sketches on Android Studio I also need classes like "PFragment" and for my project "JSONObject". They are not included in the added "jar-file". It is quite hard to locate those files.

Can anyone point me to the right files?

Kind regards,

Niels

Answers

  • Answer ✓

    Try exporting your application (or an/any application) from the Processing PDE. Then go to the generated folder and check what jars are being bundle together as part of the export.

    Kf

  • edited March 2018

    Great, this indeed works for most of the code..

    I follow the procedure explained on the website: http://android.processing.org/tutorials/android_studio/index.html

    My code to load the code "Sketch.class" is the following:

    public class MainActivity extends AppCompatActivity {
    
    private PApplet sketch;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FrameLayout frame = new FrameLayout(this);
        frame.setId(CompatUtils.getUniqueViewId());
        setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    
        //PFragment is not included in the core library
        sketch = new Sketch();
        PFragment fragment = new PFragment(sketch);
        fragment.setView(frame,this);
    }
    
    
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (sketch != null){
            sketch.onRequestPermissionsResult(requestCode,permissions,grantResults);
        }
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        if (sketch != null){
            sketch.onNewIntent(intent);
        }
    }
    

    }

    Two errors here: - The "onRequestPermissionsResult" call requires API level 23, this would allow me to target only 40% of devices. Is there a way to circumvent this call and include more devices?

    • The "onNewIntent" call gives an error message "has protected access in Activity"

    Any ideas, suggestions?

    Thank you very much for your help..

  • edited March 2018 Answer ✓

    @nvwingh===

    • as for testing p5 code with AS you have only to export it (with P5) as android project; then go to AS and on launch select "import from existing code" and choose your android folder created when you exported as the src code.

    • the call for permissions does not requires API level 23 (or more); the main activity extends appCompatActivity and (with P5) the minSDK is 15 (or 16, i dont remember)

    • put the code you are using in the fragment. Are you using "dangerous permissions"??? - and what version of the android mode are you using?

    • have a look (with AS) to your buil.gradle and your dependencies

  • I have exported it with Processing, then imported it as an Android Project. Seems to work, they use a few additional libraries, now the code seems to work. Only question is how to do this properly with an existing Android Project.

    Will try to add all the libraries and the code and then launch again.. Step in the good direction, thank you!

Sign In or Register to comment.