Programmatically Disabling Screenshot in App

Disable screenshot in Android application

I'm going to say that it is not possible to completely prevent screen/video capture of any android app through supported means. But if you only want to block it for normal android devices, the SECURE FLAG is substantial.

  1. The secure flag does block both normal screenshot and video capture.
  1. Also documentation at this link says that

    Window flag: treat the content of the window as secure, preventing
    it from appearing in screenshots or from being viewed on non-secure
    displays.

    Above solution will surely prevent applications from capturing Video
    of your app

See the answer here.


  1. There are alternative means of capturing screen content.

It may be possible to capture the screen of another app on a rooted device or through using the SDK,

which both offer little to no chance of you either blocking it or receiving notification of it.

For example: there exists software to mirror your phone screen to your computer via the SDK and so screen capture software could be used there, undiscoverable by your app.

See the answer here.

getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);

How do I disable screenshot from an android application?

Use Flag Secure as a layout parameter flag.

How to disable the screenshot in native iOS using objective c/Swift?

A)
First of all iOS does not allows you to disable the screenshot so you must clearly convey to the Client or Any business person that it is not a feasible thing as it is OS related.

B)
Next thing the solution provided you is not an apt solution as it just detects when the screenshot is taken and after that user has to manually delete the screenshot with his permission . It cannot be done automatically(without user permission) as APPLE PHOTOS API does not allows you to do that because of strict user privacy policy. So this solution is the last implementation if any case client is adamant or anyhow wants to implement it, but according to my experience it is not a 100 percent solution and must not be implemented

I can understand the trouble of converting back from Swift to Objective c . Since i have the same experience i can share snapshot of Objective C codes which you can assemble together to achieve the desired result . The code is:

For getting last object:

PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
PHAsset *lastAsset = [fetchResult lastObject];

For deleting perhaps:

PHFetchResult *asset = [PHAsset fetchAssetsWithALAssetURLs:@“Your asset url” options:nil];
[asset enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"%@",[obj class]);
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
BOOL req = [obj canPerformEditOperation:PHAssetEditOperationDelete];
if (req) {
NSLog(@"true");
[PHAssetChangeRequest deleteAssets:@[obj]];
}
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Finished Delete asset. %@", (success ? @"Success." : error));
if (success) {
NSLog(@“delete successfully”);
}
}];
}];

Follow link1 link2 and yes write to me back in comment in any case.

How to prevent Screen Capture in Android

I'm going to say that it is not possible to completely prevent screen/video capture of any android app through supported means. But if you only want to block it for normal android devices, the SECURE FLAG is substantial.

1) The secure flag does block both normal screenshot and video capture.

Also documentation at this link says that

Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.


Above solution will surely prevent applications from capturing Video of your app

See the answer here.

2) There are alternative means of capturing screen content.

It may be possible to capture the screen of another app on a rooted device or through using the SDK,

which both offer little to no chance of you either blocking it or receiving notification of it.

For example: there exists software to mirror your phone screen to your computer via the SDK and so screen capture software could be used there, undiscoverable by your app.

See the answer here.

getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);


Related Topics



Leave a reply



Submit