Forum Replies Created
-
AuthorPosts
-
Version 3.3.0 beta of Calculus available. https://play.google.com/store/apps/details?id=com.poly.calculus
Now the graphs can be zoomed in. Also some small bug fixes and improvements.


I opened an issue on Github on the permissions. I attached the permissions.monkey2 as such I altered it.
I made some changes to \modules\std\permissions.monkey2 and now asking permission at run-time works like a charm…
I found this old thread: http://monkeycoder.co.nz/forums/topic/android-permissions/
The permissions can be asked simply in nice Monkey2 code.
Though, I had at first problem with the following line:
RequestPermissions(permissions,Lambda( results:Int[] )
Error : Can’t find overload for ‘RequestPermissions’ with argument types (monkey.types.String[],Void(monkey.types.Int[]))
If it is changed to: RequestPermissions( permissions,Lambda( results:ResultType[] ) it can be compiled.
I made a new code, this little code (needs some improvement) seems to work.
It prompts the user (system feature) if the app may write to external storage, after permission, when the permission is granted, the picture is saved to Pictures folder!
Java123456789101112131415161718192021222324252627282930313233343536373839if( name.equals( "internal" ) ){f=Monkey2Activity.instance().getFilesDir();}else if( name.equals( "external" ) ){f=Monkey2Activity.instance().getExternalFilesDir( null );}else if( name.equals( "pictures" ) ){String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};com.monkey2.lib.Monkey2Permissions.requestPermissions(permissions, WRITE_REQUEST_CODE);f= Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES );}if( f!=null ) return f.getAbsolutePath()+"/";return "";}public static String onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {switch (requestCode) {case WRITE_REQUEST_CODE: {// If request is cancelled, the result arrays are empty.if (grantResults.length > 0&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {// permission was granted, yay! Do the// read external storage-related task you need to do.return Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES ).getAbsolutePath()+"/";} else {// permission denied, boo! Disable the// functionality that depends on this permission.return "NO_PERMISSION";}}// other 'case' lines to check for other// permissions this app might request.}return null;}We should add proper code to Monkey2 modules to get more Android features like Camera.
From Android version 6 (API >= 23) one must ask at run-time permission for example to Pictures folder.
This was my first try to do Android coding inside the Android Studio and I came up with this not working skeleton, that is based on Google’s example code:
Java123456789101112131415161718192021222324252627else if( name.equals( "pictures" ) ){if (ContextCompat.checkSelfPermission(Monkey2Activity.instance(),Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {// Permission is not granted// Should we show an explanation?if (ActivityCompat.shouldShowRequestPermissionRationale(Monkey2Activity.instance(),Manifest.permission.READ_EXTERNAL_STORAGE)) {// Show an explanation to the user *asynchronously* -- don't block// this thread waiting for the user's response! After the user// sees the explanation, try again to request the permission.} else {// No explanation needed; request the permissionActivityCompat.requestPermissions(Monkey2Activity.instance(),new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an// app-defined int constant. The callback method gets the// result of the request.}} else {// Permission has already been grantedf = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);}Edit: Also this in addition:
Java1234567891011121314151617181920public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {switch (requestCode) {case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {// If request is cancelled, the result arrays are empty.if (grantResults.length > 0&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {// permission was granted, yay! Do the// READ_EXTERNAL_STORAGE-related task you need to do.} else {// permission denied, boo! Disable the// functionality that depends on this permission.}return;}// other 'case' lines to check for other// permissions this app might request.}}Has anyone a working solution?
Working solution should ask the user, if the user agrees to app’s writing to external storage.
edit: Link to original code: https://developer.android.com/training/permissions/requesting#java
As default there is in the Android Manifest this permission: WRITE_EXTERNAL_STORAGE
I also thought, that could it be permissions issue, because ..Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES ) is the correct way to get the Pictures folder.
With my new Samsung Galaxy A6+ saving to Pictures folder doesn’t work. I checked SavePixmap state from the debugger, it was false and nothing was saved. Has anyone else tried this?
With version 16.0.0 the ads are working perfectly. I thought that 17.0.0 was oldest available after 17.1.1. Anyway 15.0.1 that I’ve used earlier isn’t available anymore. Thanks!
We should get ready for the time, when ads library that’s available is 17.0.0 or later.
But your reply saved my day! Thanks again.
Nice to see that Monkey 2 community is alive.
I have added RelativeLayout to my Android project (layout.xml) just like the instructions say in Google’s Admob page:
Monkey123456789101112131415161718192021222324<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_height="match_parent"android:layout_width="match_parent"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".Monkey2Game"><com.google.android.gms.ads.AdViewxmlns:ads="http://schemas.android.com/apk/res-auto"android:id="@+id/adView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_alignParentBottom="true"ads:adSize="BANNER"ads:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView></RelativeLayout>Also metadata to Android manifest file:
Monkey123<meta-dataandroid:name="com.google.android.gms.ads.ca-app-pub-3940256099942544~3347511713"android:value="ca-app-pub-3940256099942544~3347511713"/>Still not working. Though I’m not sure about that RelativeLayout in Monkey 2 projects…
Is there anyone here who has working ad code with “com.google.android.gms:play-services-ads:17.1.1”?
Anyone? No-one?
Calculus is now at version 2.9.9.
Now the original graph view gives same output, if scale factor = 1. Also possibility to save black and white graphs added.

In order to access the graphs with computer, one must copy or move the graph files seen in the Pictures folder. For example one could create Graphs folder to Pictures folder and move the graphs there.
Thanks!
Calculus is now at version 2.9.7. Two graph views. The original has been a little improved, the second tries to fit any curve(s) to the screen. The calculation precision is the limit.
I try to implement that to the next version — very good idea, the user sees better what’s he/she is doing.
-
AuthorPosts