Android - take picture - onActivityResult returns immediately -
in app take picture. current fragment within tabhost.
within fragment start camera action with:
intent takepicture = new intent( mediastore.action_image_capture); getactivity().startactivityforresult( takepicture, 1);
in mainactivity have onactivityresult:
@override public void onactivityresult( int requestcode, int resultcode, intent imagereturnedintent) { super.onactivityresult( requestcode, resultcode, imagereturnedintent); if( imagereturnedintent == null) { // coming here when own app singletop or singletask
when app contains activity launchmode singletask or singletop, onactivityresult immediately returns imagereturnedintent null. when remove launchmode in app, works again.
how can fix this?
what read on internet activity launched (so, in case camera app) should not have launchmode singletop or singletask.
question: how can own activity (having launchmode singletop or singletask) onactivityresult camera app?
notice: in android 5.0+ works fine. in android 4.x not.
i hope gives better answer brute-force answer starting camera app activity launched 'singleinstance' or 'singletop'. so, remove answer if has better solution.
you can start seperate activity - interfacing camera app. yeah - feel bit ashamed devising solution. in end works.
ok, in manifest file add:
<activity android:name = "startmedia" android:label = "startermedia" android:theme = "@android:style/theme.nodisplay" />
the class contains code --- , don't forget finish():
public class startmedia extends activity { @override public void oncreate( bundle savedinstancestate) { super.oncreate(savedinstancestate); intent takepciture= new intent( mediastore.action_image_capture); startactivityforresult( takepciture, 2); } @override public void onactivityresult( int requestcode, int resultcode, intent imagereturnedintent) { if( imagereturnedintent == null) { logger.v( "intent null - action ... "); return ; } switch( requestcode) { case 1: case 2: uri selectedimage = imagereturnedintent.getdata(); string[] filepathcolumn = { mediastore.images.media.data}; cursor cursor = getcontentresolver().query( selectedimage, filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); string filename = cursor.getstring( columnindex); logger.v( "your path:" + filename); // result cursor.close(); break; } finish(); // important - otherwise hangs app } }
bottom line: there must better solution this. if not, may escape.
Comments
Post a Comment