android activity - Save Level screenshot and upload to Google+ in LIBGDX -


when in finished-level mode, i'm print-screening game screen in png , save file (savescreenshotnamepath). want upload level picture google+ using sharegoogleimage. tested share function text , works i'm having problems image sharing part.

the print screen seen in google upload dialog appears, i see title text; apparently image not attached. issue here?

here's code:

this saves print-screen file:

public static string savescreenshotnamepath(string name){     try{         filehandle fh;         do{             fh = new filehandle(name + ".png");         }while (fh.exists());         pixmap pixmap = getscreenshot(0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight(), false);         pixmapio.writepng(fh, pixmap);         pixmap.dispose();         return fh.file().getabsolutepath();     }catch (exception e){         return "";     }         } 

this starts intent:

@override public void sharegoogleimage(int no_level, string path) {     try { thread.sleep(2000); } catch (interruptedexception e) { e.printstacktrace(); }     intent share = new plusshare.builder(this)         .settext("see latest game level " + integer.tostring(no_level) + " score")         .settype("image/png")         .setstream(uri.parse(path)).getintent();     startactivityforresult(share, 0); } 

i tried mediastore variant have same result:

@override public void sharegoogleimage(int no_level, string path) {     file tmpfile = new file(path);     string photouri = "";     try {         photouri = mediastore.images.media.insertimage(getcontentresolver(), tmpfile.getabsolutepath(), null, null);      } catch (filenotfoundexception e1) { e1.printstacktrace(); }      try { thread.sleep(2000); } catch (interruptedexception e) { e.printstacktrace(); }     intent share = new plusshare.builder(this)         .settext("see latest game level " + integer.tostring(no_level) + " score")         .settype("image/png")         .setstream(uri.parse(photouri))         .getintent();     startactivityforresult(share, 0); } 

this in-game (core files) trigger (scene2d imagebutton press) in game screen sharegoogleimage function located inside androidlauncher.java (activity file):

sharegooglebutton.addlistener( new clicklistener() { @override public void clicked(inputevent event, float x, float y){     if(!share_pressed){          share_pressed = true;         sharegooglebutton.clearactions();         sharegooglebutton.addaction(sequence(moveby(0f, 12f, 0.1f), moveby(0f, -12f, 0.2f), run(new runnable(){             public void run(){                   string pathto_screencap = screenshotfactory.savescreenshotnamepath("google_share_image");                 game.google_facebook_services.sharegoogleimage(level_no, pathto_screencap);                 share_pressed = false;             }         })));                            }     } }); 

there @ least 2 problems here: infinite loop , absolute file path. since wrapped in catch-all catch block no useful logging, aren't getting log messages debug it.

this infinite loop after first time method called because file exist (assuming written). not sure why have this.

do{     fh = new filehandle(name + ".png"); }while (fh.exists()); 

anyway, need save external directory (not absolute one) if want shared other apps g+, replace this:

fh = gdx.files.external(name + ".png"); 

you need write-external-storage permission in manifest:

<manifest ...>     <uses-permission android:name="android.permission.write_external_storage" />     ... </manifest> 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -