mattprecious / telescope

A simple tool to allow easy bug report capturing within your app.
Apache License 2.0
1.18k stars 116 forks source link

Native Screenshot Capture #13

Closed JakeWharton closed 8 years ago

JakeWharton commented 9 years ago

http://developer.android.com/about/versions/android-5.0.html#ScreenCapture

tasomaniac commented 9 years ago

The library should have a reference to the Activity in order to accomplish this. We need to call startActivityForResult once to get a permission.

startActivityForResult(
                mMediaProjectionManager.createScreenCaptureIntent(),
                REQUEST_MEDIA_PROJECTION);

How do you think it should be done? The first thing I thought was to have a method like initialize(Activity this) and make the caller Activity override onActivityResult and call our helper method again like telescopeLayout.handleActivityResult(...)

Views don't have direct access to Activity's. If we don't want to do this, we may re-structure the library to do it.

mattprecious commented 9 years ago

Yeah, TelescopeLayout will need a reference to an activity and will need to expose a method for handling the activity result. I started working on this a while back but couldn't figure out the media projection part of it. Not sure how to turn any of that into a screenshot.

My WIP API was this:

public void setNativeScreenshotEnabled(Activity activity) { }

public void setNativeScreenshotDisabled() { }

public void onActivityResult(int requestCode, int resultCode, Intent data) { }
mattprecious commented 9 years ago

Should probably change the last one to return a boolean of whether or not the result was handled.

NightlyNexus commented 8 years ago

@mattprecious What about just setNativeScreenshotEnabled(MediaProjection projection) and leave it as the Activity's responsibility to get a projection?

mattprecious commented 8 years ago

That works, but it means the app would need to front-load the request for the permission instead of at the time of the screenshot request.

JakeWharton commented 8 years ago

This library is an aar, right? You could embed an activity with a completely transparent theme which would be started and could handle the whole intent interaction dance if native capture was enabled.

mattprecious commented 8 years ago

Oooooh.... I'll look into that.

NightlyNexus commented 8 years ago

@mattprecious My thinking is that it isn't a big deal because it is a (hopefully) one-time user-facing prompt and only for debug builds (UX isn't crucial).

@jakewharton Cool idea; I'll give that a try as well. :-)

On Fri, Oct 23, 2015, 12:07 PM Matthew Precious notifications@github.com wrote:

Oooooh.... I'll look into that.

— Reply to this email directly or view it on GitHub https://github.com/mattprecious/telescope/issues/13#issuecomment-150665475 .

mattprecious commented 8 years ago

My hesitation with doing it up front is that we use this for our company-wide internal builds, which includes many people who aren't Android developers. Without any context they aren't going to know why they're being asked for such a thing and will likely deny it.