How to Load the KMZ file? - android

"I have to load a kmz file in to the android application that i am developing and that kmz file will be loaded from sdcard in to the application. So what i should do for that whether there is direct uri intent or i have to parse it by xml parsing if so then how to load coordinates in to the map to show that kmz file.

To use the native v3 KmlLayer, which supports kmz files, subject to the documented size and complexity restrictions, the kmz file must be publicly available on the web (so google's servers can get to it).
To use a local file (which it sounds like you do), your only option is to use a third party parser like geoxml3 or geoxml-v3.

to open in android studio use below code :
try {
KmlLayer layer = new KmlLayer(mGoogleMap,R.raw.filename,
getApplicationContext());
// creating the kml layer, put the file in res/raw
layer.addLayerToMap();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Related

Create folder in drive with rest v2 in android app

I am trying to create a folder in Drive and using below
String folderName = UrlConstants.APP_NAME + "_dont_delete";
File fileMetadata = new File();
fileMetadata.setTitle(folderName);
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = null;
try {
file = driveService.files().insert(fileMetadata)
.setFields("id")
.execute();
} catch (IOException e) {
e.printStackTrace();
}
However it is not creating folder in drive , instead it is creating a document named 'Untitled'.
Thanks in advance.
In Drive API for Android, note that working with folders has slight differences when compared to Google Drive API. Folders in the Drive API for Android are specialized resources within metadata and a DriveId and to create a folder, call DriveFolder.createFolder for the root folder. Then, pass the metadata containing the title and other attributes to set the values for the folder.
For a full working example, see the CreateFolderActivity sample in the Google Drive Android API Demos app.
The CloudRail SDK allows you to do that in a pretty simple way:
GoogleDrive service = new GoogleDrive(
this,
"[Google Drive Client Identifier]",
"[Google Drive Client Secret]",
"http://localhost:12345/auth",
"someState"
);
service.createFolder(
"/myFolder"
);

where can I upload json file?

I have wrote a json file with data I will get it to recycleview in android but I don't know where can I upload this file to access it into android project
There are 2 ways you can do that:
Local Storage: You can save a JSON file in your project locally. (already answered by others)
Upload your JSON: You can upload your JSON at jsonbin.io and it will generate an API that you can use in your project.
You can store JSON file in your assets folder......
void saveStringToFile(String path, String content) {
try {
File newFile = new File(path);
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
fos.write(content.getBytes());
fos.flush();
fos.close();
Constant.logD("File "+ newFile.getName()+ " is saved successfully at "+ newFile.getAbsolutePath());
} catch (Exception e) {
Constant.logE("Unable to save file", e);
}
}
Mention a path in a mobile sdcard like Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + System.currentTimeMillis()+".jpg" as path
Based on your requirement:
Best option is to host it on a (web server if you have one)
If you don't, share the file on GDrive or Dropbox (or similar hosting services which provide free storage). Share it with read-only access for your app to read from.
You can put your json file in the assets folder and best option is host the json file on the server and use the data (API) in your project.

How to create File from Image Url without download Image

How to create File from Imageurl?
I know How to
Download Image from Url using AsyncTask
I want to know about how can I create File object without download Image from url.
I tried like below.
File file = new File("http://www.planwallpaper.com/static/images/Winter-Tiger-Wild-Cat-Images.jpg");
I want to use this file in status.setMedia(file)
StatusUpdate status = new StatusUpdate(twitterMessage);
status.setMedia(file );
try {
twitter4j.Status response = twitter.updateStatus(status);
return response.toString();
} catch (TwitterException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
But no success.
Please help me about create File direct from imageurl without download Image.
How to create File from Imageurl?
You don't. File is for local files. A URL is for something that is stored on a server, and particularly in this case, that server is not the device itself, and so the URL does not point to a local file... unless you download a copy of that content to a local file.
I want to use this file in status.setMedia(file)
See if that API offers other parameter types than File, like Uri, that the library would use to support network-based sources of the media. If not, you have no choice but to download the data and provide a File pointing to your local copy.
you means show the image with a default image,but not really download.
then,when click on it,download it.right?
you can request JSON info from server then store the ImagerUrls into a list.when the user click the imageView ,then you can take out the ImagerUrl and download the image with volley or AsyncTask.

Android: Unable to create PDFRenderer

I am currently having problem create PDFRenderer object. I have a pdf file inside the assets folder and using getAssets().openfd to get the file descriptor.
My code creating the object is:
try {
_fileDescriptor = activity.getAssets().openFd(assetFile).getParcelFileDescriptor();
_pdfRender = new PdfRenderer(_fileDescriptor);
} catch (IOException ex) {
ex.printStackTrace();
}
The error saying : java.io.IOException: not create document. The fileDescriptor isn't null and the assetFile has a correct file path.
I am using the correct android api 21. I tried using lower version android but force close so I think not the phone problem

Patching an Android app

I have an Android app with an expansion file already attached. This is all working fine.
The file is: main.2.com.mydomain.myapp.obb
I want to update some assets in my app so I planned on adding a patch expansion file. Going by the next version iteration this file was: patch.10.com.mydomain.myapp.obb
I've uploaded an alpha build and I can see the files are downloading successfully. The assets in question are videos so I have the following code to access them:
ZipResourceFile expansionFile= null;
AssetFileDescriptor fd= null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),2,10);
fd = expansionFile.getAssetFileDescriptor("myvideo.mp4");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
My understanding is that the getAPKExpansionZipFile call will merge the two expansion files but my questions are:
If my patch file contains a file of the same name as the original main expansion, will the patch file version take precedent or should I have new filenames in my patch file (e.g. patch_myvideo.mp4)
How do I know the video will be correctly loaded from the patch file? I tried checking the AssetFileDescriptor offsets (start, length etc..) but it was the same with and without the patch file call.
Would love to know if I'm on the right track here!
Thanks for any help.

Categories

Resources