diff options
author | Marco Nelissen <marcone@google.com> | 2014-09-22 14:57:14 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-09-22 14:57:14 +0000 |
commit | dfc44eab3e19eef7d02787b157a16516122e69d0 (patch) | |
tree | 03107686ed70ebdaddc7bec50ae433a75abc08ef /cmds | |
parent | 1716e116c83d0fe1c8bcfda83511102edbb3517e (diff) | |
parent | c840e31d0ee772373b1be7469b7bfbe28715d52e (diff) | |
download | frameworks_base-dfc44eab3e19eef7d02787b157a16516122e69d0.zip frameworks_base-dfc44eab3e19eef7d02787b157a16516122e69d0.tar.gz frameworks_base-dfc44eab3e19eef7d02787b157a16516122e69d0.tar.bz2 |
am c840e31d: am fa436298: Merge "Broadcast an intent to mediascanner after executing screencap"
* commit 'c840e31d0ee772373b1be7469b7bfbe28715d52e':
Broadcast an intent to mediascanner after executing screencap
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/screencap/screencap.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp index 6b2a0e2..1ddbecb 100644 --- a/cmds/screencap/screencap.cpp +++ b/cmds/screencap/screencap.cpp @@ -18,6 +18,8 @@ #include <unistd.h> #include <stdio.h> #include <fcntl.h> +#include <stdlib.h> +#include <string.h> #include <linux/fb.h> #include <sys/ioctl.h> @@ -86,6 +88,21 @@ static status_t vinfoToPixelFormat(const fb_var_screeninfo& vinfo, return NO_ERROR; } +static status_t notifyMediaScanner(const char* fileName) { + String8 cmd("am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://"); + String8 fileUrl("\""); + fileUrl.append(fileName); + fileUrl.append("\""); + cmd.append(fileName); + cmd.append(" > /dev/null"); + int result = system(cmd.string()); + if (result < 0) { + fprintf(stderr, "Unable to broadcast intent for media scanner.\n"); + return UNKNOWN_ERROR; + } + return NO_ERROR; +} + int main(int argc, char** argv) { ProcessState::self()->startThreadPool(); @@ -112,10 +129,11 @@ int main(int argc, char** argv) argv += optind; int fd = -1; + const char* fn; if (argc == 0) { fd = dup(STDOUT_FILENO); } else if (argc == 1) { - const char* fn = argv[0]; + fn = argv[0]; fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0664); if (fd == -1) { fprintf(stderr, "Error opening file: %s (%s)\n", fn, strerror(errno)); @@ -184,6 +202,7 @@ int main(int argc, char** argv) SkData* streamData = stream.copyToData(); write(fd, streamData->data(), streamData->size()); streamData->unref(); + notifyMediaScanner(fn); } else { write(fd, &w, 4); write(fd, &h, 4); |