Hide and encrypt video files in android - android

I am working on Android Vault (e.g Files, Audio, Video, Images). I am trying to figure out a way to hide or encrypt large file like videos that won't show up in the storage directory, even you if search for them.
If anyone can help me out from this kinda problem.
I am Using Encryption and its working fine with images, but with videos it's not working as I want.
and Thanks a lot in Advance .Truly appreciated yours efforts

To encrypt any type of file in android you can use the EasyCrypt library.
Using EasyCrypt is easy, as the name suggests.
ECSymmetric ecSymmetric = new ECSymmetric();
ecSymmetric.encrypt(file, getString(R.string.string_resource_encryption_password), new ECResultListener() {
#Override
public void onProgress(int i, long l, long l1) {
// can show a progress bar here
}
#Override
public <T> void onSuccess(T t) {
Log.d(TAG, "onSuccess: file encrypted");
Log.d(TAG, "result: " + t.toString());
}
#Override
public void onFailure(#NotNull String s, #NotNull Exception e) {
Log.d(TAG, "onFailure: " + s);
}
});
Here file is the Java File class Object for any type of file you want.
To hide the encrypted file you can just add a '.' before the name of the file.
for example:
File file = new File(Environment.getExternalStorageDirectory() + File.separator + ".file.mp4");

Related

How to Specify Storing Path in AWS Amplify in Android.?

I'm able to store files with the AWS Amplify Storage category. However, they all are being stored in the top of the public folder in my bucket. How do I specify a path inside the public folder?
I referenced both the JavaScript and Android documentation for Amplify storage.
Here's my code.
Amplify.Storage.uploadFile(
"filenmae.txt",
filename.getAbsolutePath(),
new ResultListener<StorageUploadFileResult>() {
#Override
public void onResult(StorageUploadFileResult result) {
Log.i("StorageQuickStart", "Successfully uploaded: " + result.getKey());
}
#Override
public void onError(Throwable error) {
Log.e("StorageQuickstart", "Upload error.", error);
}
}
);
If you want to upload A file to a specific folder, then all you have to do is add the folder name path prefix to your 1st key parameter of the method Amplify.Storage.uploadFile().
For Example
let's say you want to upload your files in a folder that have name "game".
// Name of your folder with '/' in the end to make it like path prefix
String folderGame = "game/";
// here we just adding it before the name of your file
String key = folderGame +"filenmae.txt";
/*
* Now the value in key will look like "game/filenmae.txt" and
* pass it in method as first parameter where you were passing
* the name previously.
*/
Amplify.Storage.uploadFile(
key,
filename.getAbsolutePath(),
new ResultListener<StorageUploadFileResult>() {
#Override
public void onResult(StorageUploadFileResult result) {
Log.i("StorageQuickStart", "Successfully uploaded: " + result.getKey());
}
#Override
public void onError(Throwable error) {
Log.e("StorageQuickstart", "Upload error.", error);
}
}
);
Extra
For the other methods like download, remove etc., you have to do the same thing to access these files. Just add the prefix.

Firebase Storage getDownloadUrl() always return last result I select

I'm trying to play the mp3 files which are stored on Firebase storage by getting downloadUrl.
I use two spinners to decide the music types and music name which matches the folder name and file name on storage.
But after the first time choosing, the Uri I get is Null.
When I choose the second one the Uri I get is the first one I just choose.
I choose the third one, I get the second one and so on.
Here is the code I get the Url.
private void prepareMusic() {
btnPlay.setText(getString(R.string.btnplay));
btnPlay.setEnabled(false);
btnStop.setEnabled(false);
mStorageRef.child("music/"+musicType+"/"+musicName).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
uriTest = uri.toString();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
//uriTest =" ";
}
});
//the toast here is the correct type and name I choose
Toast.makeText(this,"Now musicType is: " + musicType + " musicName is:" + musicName, Toast.LENGTH_SHORT).show();
//the Uri here is always last one I choose and null at beginning
Toast.makeText(this,"uri is: " + uriTest, Toast.LENGTH_LONG).show();
try{
mper.reset();
mper.setDataSource(uriTest);
mper.prepareAsync();
}catch (Exception e){
tos.setText(getString(R.string.setTrackError) + e.toString());
tos.show();
}
}
I have searched lots of question here, but there is not a good answer to deal with my problem.
getDownloadUrl() is asynchronous and returns immediately after it's called with a Task object that represents the work in progress. Your code will then display two toasts before the download url is available.
You should only be using the download URL from the moment that the success callback is invoked, so move your code in there, or call a method in there that uses the URL.
To learn more about why Firebase APIs are asynchronous, read this blog.

Unable to upload a media file on S3 servers from Android using Retrofit

I am using Retrofit library to upload media files (multipart) from my Android application. The servers are on Amazon using S3.
I am getting this following error :
05-15 20:17:38.515: W/System.err(649): Caused by: javax.net.ssl.SSLException: Write error: ssl=0x5eed7ca0: I/O error during system call, Broken pipe
Few points :
1. I have tested the API using POSTMAN and it is working perfectly. (no issues with max upload size as well.)
2. Weirdly this is running(uploading) successfully in one of my phones ie Moto E. The phone it is not working includes Moto G2 and Xperia SP as of now.
3. I am able to make normal requests through Retrofit successfully. Its uploading media files that is an issue.
Here is the code to upload :
#Multipart
#POST("/journeys/{journey_id}/videos")
public void uploadVideo(
#Path("journey_id") String journeyId,
#Part("api_key") TypedString apiKey,
#Part("video[user_id]") TypedString userId,
#Part("video[video_file]") TypedFile video,
Callback<String> callback);
public static void uploadVideo(final Context context, final Video video) {
RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new StringConverter())
.setEndpoint(Constants.TRAVELJAR_API_BASE_URL).build();
TravelJarServices myService = restAdapter.create(TravelJarServices.class);
myService.uploadVideo(TJPreferences.getActiveJourneyId(context), new TypedString(
TJPreferences.getApiKey(context)),
new TypedString(TJPreferences.getUserId(context)), new TypedFile("video/*",
new File(video.getDataLocalURL())), new Callback<String>() {
#Override
public void success(String str, retrofit.client.Response response) {
try {
Log.d(TAG, "video uploaded successfully " + str);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void failure(RetrofitError retrofitError) {
Log.d(TAG, "error in uploading video" + retrofitError);
retrofitError.printStackTrace();
}
});
}
I have been researching on this issue for a while now and cannot come to a solution. I don't want to switch to another library as this should work for me as well. Any help will be highly appreciated. TIA

Create or Open native Google documents using GoogleDriveApi

I have been closely following the documentation for the Google Drive Android API and, all works great. I can create new text documents and read them back in using the mime type of text/plain.
What I cannot do is create a native Google "Document" or "Spreadsheet." Actually, I can create them by using the mime type to application/vnd.google-apps.document or application/vnd.google-apps.spreadsheet as per Supported MIME Types documentation.
If, however, I try to write content to these documents, the documents never get uploaded.
If I try to read documents that have content (content I created via a web browser) my openContents call fails.
Again, I can create text/plain documents and write to them, but they are not native Google Documents. I have scowered the documentation and sample files, but nothing describes what I'm looking for.
This seems so basic. Does the new GoogleApiClient not support doing this? What am I missing or doing wrong?
Here is the core code for creating. I have a similar issue when trying to read a application/vnd.google-apps.document but I'm sure the two issues are related. I'll spare the verbosity of "read" code.
private void exportToGDriveFile() {
Drive.DriveApi.newContents(getGoogleApiClient()).setResultCallback(createNewFileCallback);
}
final private ResultCallback<ContentsResult> createNewFileCallback = new ResultCallback<ContentsResult>() {
#Override
public void onResult(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
writeLog("Error while trying to create new file contents");
return;
}
String fileName = getIncrementedFileName();
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(fileName)
.setMimeType("text/plain") // <-- This works! I can write and read back :)
//.setMimeType("application/vnd.google-apps.document") <-- can create if no contents are included.
//.setMimeType("application/vnd.google-apps.spreadsheet")
.setStarred(true)
.build();
writeLog("creating file: " + fileName);
// create a file on root folder
Drive.DriveApi.getRootFolder(getGoogleApiClient())
.createFile(getGoogleApiClient(), changeSet, result.getContents())
.setResultCallback(afterCreateFileCallback);
}
};
private ResultCallback<DriveFileResult> afterCreateFileCallback = new ResultCallback<DriveFileResult>() {
#Override
public void onResult(DriveFileResult result) {
if (!result.getStatus().isSuccess()) {
writeLog("Error while trying to create the file");
return;
}
DriveFile driveFile = result.getDriveFile();
writeLog("Created file " + driveFile.getDriveId());
new WriteFileAsyncTask().execute(driveFile);
}
};
private class WriteFileAsyncTask extends AsyncTask<DriveFile, Void, Boolean> {
#Override
protected Boolean doInBackground(DriveFile... args) {
DriveFile file = args[0];
try {
ContentsResult contentsResult = file.openContents(getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
if (!contentsResult.getStatus().isSuccess()) {
return false;
}
/************************
If I try to write content here, `application/vnd.google-apps.document` files will not upload.
*************************/
String contents = "Hello World";
OutputStream outputStream = contentsResult.getContents().getOutputStream();
outputStream.write(contents.getBytes());
com.google.android.gms.common.api.Status status = file.commitAndCloseContents(
getGoogleApiClient(), contentsResult.getContents()).await();
return status.getStatus().isSuccess();
} catch (IOException e) {
// toast("IOException while appending to the output stream");
}
return false;
}
#Override
protected void onPostExecute(Boolean result) {
if (!result) {
// toast("Error while editing contents");
return;
}
// toast("Successfully uploaded Quizifications!");
}
}
It's not currently possible to read or edit the contents of Google Documents, Spreadsheets or Presentation files. They files are of a special type that don't have standard binary content, so you can't read and write from them in the same way you can from other files.
You can, however, interact with the metadata of existing files.
Sorry for the confusion, we should update the behavior so that its clear that its not possible.
Updating Google Docs with HTML is simple. Just make an api request with html-formatted text in the body (html tag is required) and content-type to be google docs, then your created/updated file will be available to the user as a Google Doc with all the formatting options.
request({
uri: 'https://www.googleapis.com/upload/drive/v2/files/'+fileId,
method: 'PUT',
qs: {
uploadType: 'media'
},
form: '<html> Hello <b>World!</b> </html>',
headers: {
'Content-Type': 'application/vnd.google-apps.document',
'Authorization': 'Bearer ' + access_token
}}, function (error, response, body){
})

How to split up Epub Html into pages according to screen size

I'm developing an Android application that reads ebooks (in epub format) and as for now I'm using Paul Siegeman's epublib library that is really a very good epub reader but it has some limitations, for example and the one I need, you can't move through pages horizontally (as you do reading a real book) so I need my own implementation of it, but I'm stuck.
The method that actually reads the epub and then puts it inside a webview is the next:
private void openEpub(String bookFilename){
WebView webView = (WebView) findViewById(R.id.webView);
nl.siegmann.epublib.domain.Book book=null;
try {
book = (new EpubReader()).readEpub(new FileInputStream(Environment.getExternalStorageDirectory().getPath() + "/" + bookFilename));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String baseUrl = Environment.getExternalStorageDirectory().getPath() + "/";
String data=null;
try {
data = new String(book.getContents().get(1).getData());
} catch (IOException e) {
e.printStackTrace();
}
webView.loadDataWithBaseURL(baseUrl, data, "text/html", "UTF-8", null);
}
So as you see I display the ebook in a webview so as far as I know the only scrolling possibility webview gives is up/down.
I was thinking on splitting the html string that getData() returns and webview loads into pages and displaying them one by one with a viewpager, but how to split the html correctly according to screen size?
Do you think with this idea I'm on the right way? Any other solutions to display epub from left to right / right to left (paginate) or any other "free or cheap" library to do so? (I tried PageTurner, it's really good, but the commercial version is too expensive for me)
I have done pagination effect in android like this..
-> create a custom webview class.
-> set below clients and load url then you will get horizontal scrolling with page count.
-> Lock the webview default scroll.
-> For smooth pagination effect instead of moving scroll of webview ,move the entire webview so for one page there would be one webview.
-> Use your own viewflippers to buffer previous and next pages.
I have done all these implementations and I made a product for an organisation.Just I am sharing my idea how to approach towards the best solution.Instead of using third parities and stucking in the middle due to limitation of that sdk ,make every thing your own.
private class MyWebClient extends WebViewClient
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
final MyWebView myWebView = (MyWebView) view;
String varMySheet = "var mySheet = document.styleSheets[0];";
String addCSSRule = "function addCSSRule(selector, newRule) {"
+ "ruleIndex = mySheet.cssRules.length;"
+ "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"
+ "}";
String insertRule1 = "addCSSRule('html', 'padding: 0px; height: "
+ (myWebView.getMeasuredHeight()/getContext().getResources().getDisplayMetrics().density )
+ "px; -webkit-column-gap: 0px; -webkit-column-width: "
+ myWebView.getMeasuredWidth() + "px;')";
myWebView.loadUrl("javascript:" + varMySheet);
myWebView.loadUrl("javascript:" + addCSSRule);
myWebView.loadUrl("javascript:" + insertRule1);
}
}
private class MyWebChromeClient extends WebChromeClient
{
#Override
public void onProgressChanged(WebView view, int newProgress)
{
super.onProgressChanged(view, newProgress);
if(newProgress == 100)
{
postDelayed(new Runnable()
{
#Override
public void run()
{
calculateNoOfPages();
}
},200);
}
}
}
private void calculateNoOfPages()
{
if(GlobalSettings.EPUB_LAYOUT_TYPE == GlobalConstants.FIXED)
{
}
else
{
if(getMeasuredWidth() != 0)
{
int newPageCount = computeHorizontalScrollRange()/getMeasuredWidth();
getData().getChapterVO().setPageCount(newPageCount);
}
}
}
#Override
public int computeHorizontalScrollRange() {
// TODO Auto-generated method stub
return super.computeHorizontalScrollRange();
}
one you load url to
Follow this github account.
FbReader provide some great libraries for epub and pdf reader. Try this....
or
You can Make your own custom WebView by extending WebView. Here you can place and modify all the functionalities you want from your WebView.
My colleague made a reader using this FbReader and It was fabulous.
Hey I think this will help you. The answer by Nacho L worked for me. Here HTML book-like pagination?

Categories

Resources