4

I'm trying to deal with the new Android Lollipop MediaProjection API.

I have found that (at least on my stock Samsung Galaxy S4 jfltexx) when I start the intent to get permission to capture the screen (ProjectionManager.createScreenCaptureIntent()), I won't have a result in onActivityResult unless I have checked "Don't ask again" on the preceding try ...

private static final int ALLOW_SCREENSHOT_REQ = 102;

{
 ...
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            System.out.println("request permission");
            startActivityForResult(mProjectionManager.createScreenCaptureIntent(), ALLOW_SCREENSHOT_REQ);
        }
 ...
}

And the result handling:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.println("RebootActivity.onActivityResult(" + requestCode + "," + resultCode + ", data)");
}

The permission dialog is showing well, but my activity gets hidden and it never goes to onActivityResult.

Any idea of what's going wrong?

Floern
  • 33,559
  • 24
  • 104
  • 119
gRRosminet
  • 137
  • 1
  • 8

1 Answers1

0

Have you tried like this: See Full Example android-ScreenCapture

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_MEDIA_PROJECTION) {
        if (resultCode != Activity.RESULT_OK) {
            Log.i(TAG, "User cancelled");
            Toast.makeText(getActivity(), R.string.user_cancelled, Toast.LENGTH_SHORT).show();
            return;
        }
        Activity activity = getActivity();
        if (activity == null) {
            return;
        }
        Log.i(TAG, "Starting screen capture");
        mResultCode = resultCode;
        mResultData = data;
        setUpMediaProjection();
        setUpVirtualDisplay();
    }
}

Hope it will helps you.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437