It looks like you're new here. If you want to get involved, click one of these buttons!
public static void savePicture(String xpath, String... xname) { // copy to public directory Bitmap source = loadBitmap(xpath); Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).mkdirs(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); // check if optional folder/file name parameter exists // Example xname = "myfolder/myimage_20190924_073644.png" String imageFileName = xname.length > 0 ? xname[0] : "gideros_" + timeStamp + ".png"; String destination = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES).toString() + "/" + imageFileName; savePngBitmap(destination, source); // let media scanner scan it. // NOTE: I don't think that this works with png file format } |
private static void savePngBitmap(String path, Bitmap image){ try { FileOutputStream out = new FileOutputStream(path); image.compress(Bitmap.CompressFormat.PNG, 100, out); // why not 100? out.close(); } catch (Exception e) { e.printStackTrace(); } } |
Likes: Apollo14, SinisterSoft, antix
Comments
If I modify the gmedia.java file in:
C:\Program Files (x86)\Gideros\All Plugins\gmedia\source\Android\src\com\giderosmobile\android\plugins\media
and the mediabinder.cpp in:
C:\Program Files (x86)\Gideros\All Plugins\gmedia\source\Android\jni
Will this work when building a new apk? Is this that easy or I need to build the libgmedia.so file as well?
Thank you for your help. Peace.
Likes: MoKaLux
I have modified the:
C:\Program Files (x86)\Gideros\All Plugins\gmedia\bin\Android\src\com\giderosmobile\android\plugins\media\GMedia.java
Then I compiled the apk within gideros and that worked!!!
The changes I have made:
What it does now:
- saves the picture to folder: SD/Pictures/gideros/ (or any of your liking!)
- the name of the file saved is now: "img_" + timeStamp + ".png" (or any of your liking!)
- the new format is png (100)
Next step: add the folder and file name inside gideros gmedia function. Something like this:
mediamanager:postPicture(sourcepath, destfolder, destname)
Those would be optional.
- added SHOW ANDROID BOX ALLOW APP TO ACCESS MEDIA when saving picture to SD card (tested in gideros export apk target 26, 28 & 29!)
GREAT SUCCESS!
Will commit to gideros github (God's willing)
Viva gideros!
Likes: SinisterSoft, Apollo14, hgy29, antix
I am still working on the gmedia plugin to make it fully functional again. What I have so far:
- (see post above) OK
- asking camera permission OK
- taking photos (so far I can only take thumbnail photos, the full photo involves much more android code and gideros dependencies, so I am a bit stuck here!) QUITE OK
- playing VIDEOS from inside gideros assets (tested with .mp4) OK
I am trying to override onRequestPermissionsResult so I have modified the gideros android template by adding the following:
import android.support.v4.app.ActivityCompat;
public class mediaexample04Activity extends Activity implements OnTouchListener, ActivityCompat.OnRequestPermissionsResultCallback
So far so good but the problem is that "gideros" generates this piece of code:
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
}
That is almost perfect but:
1- I don't see the @override tag which is needed.
2- GiderosApplication.getInstance() does not contain the onRequestPermissionsResult(...) function so I cannot write something like the onActivityResult(...) callback like the one below:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
GiderosApplication.getInstance().onActivityResult(requestCode, resultCode, data);
}
My questions:
1- is it a bug for the non @override?
2- how can I add GiderosApplication.getInstance().onRequestPermissionsResult(...), Is it done in c++?
Thank you for your help! The onRequestPermissionsResult(...) is needed so the app can do stuff after the permissions are granted. I can do without it but the UX is not so good then.
1- for the @override it seems to be missing in the gideros android template so I will add it OK
2- I found where the GiderosApplication is initialized, it's in: android/GiderosAndroidPlayer/app/src/main/java/com/giderosmobile/android/player/GiderosApplication.java
So now 1 question remains:
1- Is android/GiderosAndroidPlayer/app/src/main/java/com/giderosmobile/android/player/GiderosApplication.java SOMEWHERE in the gideros installation folder?
I would like to add one function to it:
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
}
I can't find it! How can I add the above function? Build gideros from source (please no, not yet!)?
Thank you for your help.
Likes: SinisterSoft
1: @Override is just a hint that the method is supposed to be overriding a base class method. It makes the compiler generate errors if not base class method with this signature exists. So it is recommanded but not required.
2: GiderosApplication.java is precompiled inside gideros.aar file in the template
But I think you don't need to change it. Basically what you want (I guess) is to have some callback in GMedia called when onRequestPermissionResult is called on GiderosActivity. If so just add a marker (GIDEROS TAG comment) in GiderosActivity inside the onRequestXXX callback and have the .gplugin file insert code here during export. You can insert code to directly call a GMedia function.
Likes: MoKaLux, SinisterSoft
Just one more question:
I want to commit this piece of code so we could overide the above mentionned method:
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
for ( Class < ? > theClass : sAvailableClasses )
{
executeMethod ( theClass, null, "onRequestPermissionsResult", new Class < ? > [] { java.lang.Integer.TYPE, java.lang.Object.TYPE, java.lang.Object.TYPE }, new Object [] { new Integer ( requestCode ), new Object ( permissions ), new Object ( grantResults ) });
}
}
but I am not sure about how to pass String[] and int[] arrays. Is the above code correct?
I would like to commit so we could override onRequestPermissions inside GMedia like we do with onActivityResult(...) that would be better imho.
The code you wrote (I trust your java skills) should be all we need to do this call in the GiderosActivity:
But now I am trying the gmedia.gplugin way. Should tell you more soon?!
Likes: MoKaLux
Small problem Error cannot access GiderosSettings.import com.giderosmobile.android.GiderosSettings;
in AndroidTemplateActivity.java.
Only part left: I can only capture a thumbnail of a photo, not the photo itself, should investigate more...
Likes: SinisterSoft
Likes: MoKaLux
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
samsung S2 android 4.4 WORKING!
samsung S5 android 6.0.1 WORKING!
samsung J6 android 9 WORKING!
all commits are done too!
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
is there such an universal path for the external sdcard as well?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Maybe try to brute force?
for me "/storage" seems to list things, one of them being the external sdcard (with a stupid arbitrary name).
but interestingly while "/storage/emulated/0" points to internal sd, i cannot list the directories in "/storage/emulated".
my plan was to give access to "/storage/" and then the user can browse wherever he wants, but this obstructs it.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Now that I see it: it would have been better to save to pictures folder directly, not pictures/gideros
PS: in the java code this is line 142 You can let the users browse wherever he wants with getPicture:
https://wiki.giderosmobile.com/index.php/Mediamanager:getPicture
But not save anywhere they want but wherever you specified (please see above).
i'm using lfs.dir(path) to get a list of directories and files contained in a folder.
now the natural thing would be to use '/' or '/storage' as the initial directory and then the user can browse to wherever he wants. the issue is that while dir('/storage') lists '/storage/emulated' correctly, yet if i try to list folders inside this, then dir ('/storage/emulated') does not list anything, e.g. it does not list'/storage/emulated/0' even though this exists and is a working path to access the internal storage.
in short, some folders seem to be invisible for lfs.dir() and i don't know why.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
still i should check out "mediamanager:getPicture() -- opens windows/android file explorer", i did not know that android has a native file explorer.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game