android use the camera app and private storage - security

I am trying to use the sample code at
https://developer.android.com/training/camera/photobasics.html
to take pictures that WILL NOT show up in gallery or get shared. Google's example missed this part of the demo.
I followed the example: My code is at:
https://github.com/tomha2014/SecureCameraIntent/tree/master
Failed to ensure directory: /storage/sdcard1/Android/data/thackbarth.com.securecameraintent/files/Pictures
I have all the read/write external permissions in the manifest.

Make sure folders in this path exist.
thackbarth.com.securecameraintent/files/Pictures

YEA! I found it
In the google sample code found at
https://developer.android.com/training/camera/photobasics.html
There is a line of of code that looks like:
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
That create a file uri, the bitmap decode:
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
Wants a path to the file Take off the "file:" and it it works.....
That was a lot of hours wasted, if Google would have just provided that code in the sample linked to that page.
In any case, I am working on a sample that uses that code for Android 6
can be found at:
https://github.com/tomha2014/SecureCameraIntent

Related

Autodesk Forge: Industrial Construction Demo bucket not working

I have cloned the Industrial Construction Demo code https://github.com/petrbroz/forge-industrial-construction but I am having issues with the 'bucket-name'.
In the launch file you need to specify "FORGE_BUCKET": "" instead of the usual URN.
I have written the name of the bucket that contains my file but it does not work. I have tried debugging it but still no luck.
There is no exemplary bucket or files, so I would really like to know:
-What do I need to put in as the bucket name?
-What files need to be in the bucket?
-What file types?
-Any extra information to help me figure out why it isnt working.
Many thanks,
Poppy
My apologies, I haven't explained this in the code sample very well. The demo requires files in Forge to be named in a specific way. I have just updated the README with more details: https://github.com/petrbroz/forge-industrial-construction.

how to check if a file path in cloud storage is valid or not using cloud function?

so I am trying to download an image from firebase storage like this using cloud function
const bucket = storage.bucket("myApp.appspot.com")
const filePath = `eventPoster/${creatorID}/${eventID}.png`
await bucket.file(filePath).download({
destination: tmpFilePath
})
but the problem is, I can't ensure the image is always in the png format, it can also be jpeg or jpg
I will get error like this if I hard code it like that
Error: No such object: myApp.appspot.com/eventPoster/user1/ev123.png
so how to check if a path is valid or not or how to make a code that can work dynamically with other image extension ?
Posting as Community Wiki, because I based part of it in a comment and so other members of the Community can feel free to edit it.
As mentioned in the comments, you can use the method exists(), to check if a specific file exists in your bucket. This way, you will not an issue, in case the file doesn't exist when you are trying to return it. This would be the best way for you to check only for files existing, with the name based in the ids as you are basing your name structure.
Besides that, as clarified in this other post from the Community here, you can restrict the file types in your bucket in case you are using the POST method to upload files, otherwise, you won't be able - which can also, be an alternative. In case you are not using POST, as mentioned as well in this other post, you can try to construct a Cloud Function that will check for the file type before it uploads the file to the bucket, which would make your application only upload specific files.
In case you would like to check on how to upload files to Cloud Storage using Cloud Functions, you can check this tutorial here: How to upload using firebase cloud functions
Unfortunately, these seem to be the only available options right now, but I think they are a good start for you.
Let me know if the information helped you!
You can use the exists method on a file to check if your PNG is present or not. You can also change your code and use the getFiles() method. As you can see, you can put options, and one named "prefix". In your case you can have this
bucket.getFiles({
prefix: "eventPoster/${creatorID}/${eventID}"
}, <callback>);
Here you will list all the file with the prefix: PNG, JPEG and others. make your code smarter to leverage this dynamic answer

Deploy and load a picture to use as a texture in a holographic app

I created a sample holographic application in Visual Studio 2015 with C++/CX (or whatever they call that fancy C++ with hats and ref new). It builds, deploys and runs fine, rendering a rotating colored cube, just as it's supposed to. Now I am trying to add a jpeg image and use it as a texture on the cube. The question is, where shall I put the image, how do I add it to the project, how do I make VS to deploy it along with the rest of the project, and how do I load it in my application?
I have literally zero experience with both DirectX and UWP. I've done this tutorial on textures on my desktop Windows 10 (a regular C++ app, not managed, not UWP), although the way they load a file into a texture in the tutorial didn't work for me. After some googling I downloaded this library, built it for desktop Windows 10 (DirectXTex_Desktop_2015_Win10.sln) and used in my project as follows:
DirectX::ScratchImage image;
LoadFromWICFile(L"myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
CreateShaderResourceView(d3d11Device, image.GetImages(), image.GetImageCount(), image.GetMetadata(), &CubesTexture);
It worked. Now, for Hololens I built their DirectXTex_Windows10.sln solution (assuming that if the other one was for desktop, this one must be for non-desktop) and tried (unsuccessfully) using it like this:
DirectX::ScratchImage image;
HRESULT hr = LoadFromWICFile(L"ms-appx:///myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
CreateShaderResourceView(m_deviceResources->GetD3DDevice(), image.GetImages(), image.GetImageCount(), image.GetMetadata(), &m_cubesTexture);
I also tried ms-appdata instead of ms-appx. In both cases LoadFromWICFile does not return S_OK. It gives ERROR_INVALID_NAME: The filename, directory name or volume label syntax is incorrect. As for myimage.jpg, I put it into the Assets subfolder and added to the solution through Add->Existing Item. Is that enough to get it deployed to Hololens? How do I check if it gets deployed? Where on the device is it going to be located, if deployed?
It seems I over-complicated things.
To add a file like that into a project, simply use right click (on the Assets sub-folder in the solution explorer) -> Add -> Existing Item. To get it deployed on the device or emulator, right click on the file -> Properties, set Content to Yes and Item Type to Image or Does not participate in build (for something that doesn't get recognized correctly, for example, Wavefront .OBJ file, which VS would otherwise try and fail to link).
To check if (and where) the file is going to be on the device or emulator, you can build an actual package: right click on the project, choose Store->Create App Packages... It creates an .appx file, which is actually a zip-archive. You can explore it with an archiver like 7zip, or rename it from .appx to .zip and open with Windows File Explorer. In my case the image file was there, in the Assets subfolder. I was able to read it by its simple relative path, like this (no ms-appx:/// or other such prefixes):
HRESULT hr = LoadFromWICFile(L"Assets/myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
For some other functions (std::fopen, std::ifstream etc.) this relative path didn't work, I had to use the full path as follows:
Platform::String^ appInstallFolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
std::wstring folderNameW(appInstallFolder->Begin());
std::string folderNameA(folderNameW.begin(), folderNameW.end());
std::string fname = folderNameA + std::string("/Assets/model.obj");
std::FILE *f = std::fopen(fname.c_str(), "r");
This textured cube project might give you some insight. I think is based on the C# VS2015 Holographic template.
https://github.com/dngoins/HololensDXTutorials

Gifs on Sailfish-os

I came here with a little problem, i can't use any local .gif in my code.
I work on Linux with QtCreator and the Sailfish VM to make a Sailfish-os application.
I tried first this example, without any success.
Rectangle {
width: animation.width
height: animation.height
AnimatedImage { id: animation; source: "../images/animatedimageitem.gif"}
}
The execution return :
QML AnimatedImage: Error Reading Animated Image File file:///bla/bla/.....
Same problem with other permissions on the gif and with an other gif.
After some researches I found this page where someone indicate to download a plugin, but Qt declare (I wish i could put a link but i'm new -_-', see comments) that gifs are already support by default.
The plugin was finally unobtainable and I found this Sailfish/bin/plugins/imageformats/libqgif.so in my directories.
So what can i do to show a gif on this damn thing ?
The error you are seeing is probably related to filepaths. Gifs are supported, AFAIK.
Instead of coding the path that way, consider the usage of a resource file to improve portability and platform independence.
Create a new resource file (File -> New File or project -> Qt -> Qt Resource File)
The property editor opens, click Add in the bottom then Add prefix and set a prefix such as / (or whatever you like!)
Click again to select Add files and insert your image
Right-click the newly added image entry and copy resource path to Clipboard
Build -> Run qmake (fundamental to ensure correct compilation)
The path you copied in the clipboard should be of the form:
://PATH_TO_IMAGE.gif
Now, given your QML code, I can guess the image folder is inside source code at the same level as the QML folder. Hence, if you added the .gif file from that folder you would have the following path in the clipboard:
://images/name.gif
This can be prepended with the prefix to obtain the final path. If your prefix is set to /, as we did above, the final string to be set in the source property of your AnimatedImage would be:
"qrc:///images/name.gif"
Obviously, a different prefix or a different path would result in a different final path.
Well..... I just put it on my phone (Jolla) and the gif works well. So this is the VM who doesn't seems to like gifs ...
Thanks for help though,
Psycho.

Getting the full path of a DirectoryEntry

Does anyone know how to get the full path of a DirectoryEntry object in a Chrome Packaged App, without any tildes or other shortcuts?
I am writing a Google Chrome Packaged App. My app has a button where a user can choose a directory using chrome.fileSystem API. When the directory choice comes back to my app, it is represented by a DirectoryEntry object, which is defined in the File API. The object looks like this in the console:
DirectoryEntry {
filesystem: DOMFileSystem
fullPath: "/to_read"
isDirectory: true
isFile: false
name: "to_read"
__proto__: DirectoryEntry
}
I am using Windows and the full path of the directory is
C:\Users\David\Desktop\to_read
I would like a function that can return that path or something close. Unfortunately, the closest thing I found is chrome.fileSystem.getDisplayPath, but that returns the following:
~\Desktop\to_read
The return value from getDisplayPath is not useful to me, because I want to get the full name of the directory (including the drive) so I can compare it to some other full directory paths I have.
I tried calling toURL() on the DirectoryEntry and it returned an empty string.
A bit about my project: I want to write an iTunes library synchronizer as a Chrome Packaged App. The iTunes library XML file contains full paths like file://localhost/D:/David/Music/Bob/Bob%20Album/01%20Bob.mp3. The user will give my app access to his music folders, and I want to be able to tell if he gave me access to the right folders.
The only full paths available are those returned by getDisplayPath.
The mediaGalleries API may be a better fit for your project: http://developer.chrome.com/apps/mediaGalleries.html#iTunes.
If you have a full path path/to/the/file.mp3 and you want to load the file directly with tis you can do it but the solution is not perfect. Use the chrome.mediaGalleries API to ask where the user saves his music (in your case), then you can write a loop who check if one of the path repository is equal to a gallery.
For example if you got a file path/to/the/file.mp3 from the xml file and your galleries list looks like ["D", "to", "Videos"], write a function to check if each component of the file's path is a gallery. In this case your code will find "to", so you can launch a second function who use "the/file.mp3".
The second function has to use the given path and find if the gallery contains the right folders and finally the right file (use this example by Google). In the case you're trying to find "the/file.mp3" with the gallery to your loop has to find a directory named "the" then "file.mp3" (write a recursive function), if you find the file open it, otherwise come back to the first function if you haven't check all the galleries or all the path's component.
This is currently (2014-01-10) not a feature of Chrome, but I have suggested it and they are working on it:
https://code.google.com/p/chromium/issues/detail?id=322952

Resources