How to put files into Android/Data/com.mycomp.myapp? - android-studio

I'm new to Android. Switched from .NET WPF/Windows Forms. I have some JSON files in my project. How to put them in the future /Android/data/[packagename]/
folder? In .NET WPF you just open properties for that file and select copy to application folder or so. Probably there is the same method in Android Studio, isn't it?

You put them in the assets folder if you just want them to be read accessible. If you need them to be writable, you'd put them in assets and then copy them to the filesystem on first run.

Related

Why can't I copy/paste img assets from one project into new directories in second project's drawable folder?

I downloaded a project from Github, trying to rebuild it myself for learning purposes. I'm new to Android Studio, developing on a Mac. Having trouble with what I think would be simple tasks.
The source project from Github I downloaded has several different sub directories containing image resources under the res/drawable folder. I was hoping I could just copy and paste these assets into my own project. It doesn't seem to work the way I'd expect and I don't understand what is going on.
I've tried right clicking and copy/pasting the directory I'd like to duplicate from the Github project (opened in Android Studio) into the drawable folder in my new project (Also opened in AS). Nothing seems to happen when I do this. Right clicking and selecting "reveal in finder" reveals a still unfortunately empty drawable folder.
I also tried right clicking on the specific directory I'd like to copy from the Github project and selecting "reveal in finder", thinking I'd try copying and pasting it from there into my new project. Oddly enough when I do this, the same directory isn't even the one that's opened. Instead, it opens a drawable-hdpi folder containing several assets, but it's definitely not the one I was attempting to open.
I've tried right clicking and "synchronizing" the drawable folder in my new project after copy/pasting, still no luck.
You can not copy android folders or directories directly into android studio. But you can copy individual files into there respective folders in your project.
If you want to copy folders/ directories you can open the android app folder in your MAC browser and go to Application/app/src/main and paste whatever you have in the respective folders.
The main folder conrains java and res folders and an AndroidManifest.xml file.
You can paste xml files , drawables and pngs etc in res and java classes will go into java folder.

Can't create Sample Data Directory - Android Studio

I"m trying to Create a sample data directory, using Android Studio, by clicking on app in the project view and then right mouse click to find the menu item New > Sample Data Directory.
It is not working.
Creating the directory via android studio doesn't always work. You may need to create the directory manually in your directory structure (at /app/sampledata/) without using Android Studio. Once you create it (e.g., via Windows Explorer) it should show up in Android Studio. See the the following answer for more information about sample data in general: How to put new placeholder resources into Android Studio project ("tools:sample" resources)?
"Unlike resources like images, fonts, etc. The sample data does not go in /res/ (they are not compiled with the app, hence. It is probably easier to filter them out by putting them in a totally separate directory). They go in /app/sampledata/, for example: /app/sampledata/image.png."
You can create a sample data directory in Android Studio itself by following the below steps:
Change the view of directory structure from Android to Project as follows
Right click app folder and select New->Directory
Finally, give a name to your directory, in your case, it should be sampledata
I have already created sampledata directory that's why it says "Directory already exists".
That's it. You have done it. Remember that Android Studio also supports loading sample data from a json file. All you have to give is fully qualified name of the key residing in the json file.
Ex- if your json file contains key name inside a Json Array student, then you have to specify it as "#sample/your_student_file.json/student/name" to use values present in key name.
Unless your issue happens to be different, this is a known issue that only affects Windows. As I've found, it has something to do with 'C:\' in the file path.
https://issuetracker.google.com/issues/124553391
As Shawn mentioned, you need to manually create the directory.
I've been unable to get the images to actually display in the previewer, which I suspect may also be caused by the file path bug.
Inside the app folder in file explorer, You can create a new folder (sample data) which will be reflected in your android studio.

Xamarin ios - Include Files in IPA

I want to include some images within my ipa-File, that need to be placed into the app's documents folder. A similar request was here: Preloading Documents into iOS App. But I'm not familiar with Objective-C. I think I can do it some way in Xamarion.iOS, but the problem in my opinion is the quite large number of files (around 300MB). When I include the files within the AppRessources and copy them on startup, they exist twice on the disk. So there is no real saving...
Any other ideas, how i can include files without being stored twice?
Files that you include in studio goes into your bundle. You can only read them from your application. Modifications and removing is not possible. File that you copy from bundle into your Documents folder, can be modified or removed in Document folder. So there is no way to removing files from a bundle, even if you copy them into Document folder.
You can use on demand resources to download them later intro your app:
https://developer.xamarin.com/guides/ios/tvos/application-fundamentals/resources-data-storage/#On-Demand-Resources

How do I add images to an Xamarin iOS project and make them available in Interface Builder?

I am working in Xamarin to build an iOS iPad app.
I have created a folder called Resources in the project root e.g. ProjectName/Resources. Within here is a subfolder ProjectName/Resources/Images. I have added 2 images into the Images folder.
Then, in Interface Builder (in Xcode), I have added a UIImageView to my xib file and gone to the Image drop down in the attributes inspector. There are no images available to select.
Maybe I have to add them via Xcode instead? If so what are the correct steps and file structures to use?
What is the correct way to work with images and make them available for selection in Interface Builder?
Xamarin Studio only exports images that would live in the top-level app bundle directory when the app gets compiled. This is because Xcode's .xib files only seem to be able to refer to images in the top-level app bundle.
There are multiple ways of achieving your goal:
The first option is to specify a LogicalName to be whatever you want the name to be inside of the compiled app bundle. In Xamarin Studio, this property is called the Resource ID (may or may not be available depending on which version of Xamarin Studio you are using - it was only recently added). You can also set the LogicalName by editing the *.csproj file like so:
<BundleResource Include="Icons\icon.png">
<LogicalName>icon.png</LogicalName>
</BundleResource>
Normally, that Icons\icon.png file would be copied into the iOS app bundle as Icons/icon.png, however, the LogicalName property overrides the relative install path/name. In this case it would be copied over as simply icon.png.
As another example, you can also do this:
<BundleResource Include="Icons\iOS\icon.png">
<LogicalName>AppIcon.png</LogicalName>
</BundleResource>
This will copy the Icons\iOS\icon.png file into the root of the iOS app bundle and also rename it to AppIcon.png.
A second option is to simply move your image file(s) into the Resources folder. The Resources folder is a special directory that gets stripped out of the default path names when copied over to the iOS app bundle. In other words, Resources\icon.png would be copied over into the root of the iOS app bundle as icon.png rather than Resources\icon.png as is the case with normal project directories.
A third option is to simply register other "Resource" directories of your own (and they can exist within other directories, including the default Resources directory).
For example, you could have the structure in your project:
Resources/
Icons/
icon.png
icon#2x.png
And in your *.csproj file, edit the following tag:
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
and replace it with:
<IPhoneResourcePrefix>Resources;Resources\Icons</IPhoneResourcePrefix>
This will ensure that the icon.png and icon#2x.png files are installed in the root of the iOS app bundle.

MonoDevelop's Images directory does not seen on XCode(IB)

In my project files marshalling shown below ,Mono Develop doesn't show Images directory(group) in XCode and they are not seen on xib interfaces,also crashes on runtime. But when I put images under Project's root directory works fine!
Fine! But seeing dozens of images on root directory make things confusing.
Here goes details;
My images built actions are content.
I have tried adding them to Xcode by creating a group named Images then this time all images copied to Mono Develop's root again.
Am I missing something?
Project
--Images
---- FaceOff.Png
---- icons
---------CandyButton32x.png
I think you are experiencing a limitation of the XCode integration with MonoDevelop.
Images only show up in XCode if they are in the root directory of your project. To combat this, there are two ways you can setup your image folders for MonoTouch projects:
Use build action Content, put your images anywhere, but they will only show up in XCode if they are in the root of the project
Use the build action BundleResource and put all your images in the Resources folder, this is the same as putting your images in the root of the project, but you get to package them nicely in a subfolder
I have not experimented with BundleResource and XCode to see if subfolders work via that method or not.
This is from my experience, someone from Xamarin, feel free to chime in.
Further to Jonathan's great answer, I have a nice organised setup for my images using BundleResource and the Resources Folder.
On the filesystem I have all my images in a nice directory structure, for example: img/common/title.png.
I then add all the image files (not directories) into the iOS project Resources folder, using the 'Add Files' option and selecting BundleResource for the files I select.
When given the copy, move or link option, because my files are outside the target directory, I select the 'Add a link to the file' option.
This procedure allows me to:
Happily keep all my images in an organised directory structure on the file system
Have access to them in XCode Interface Builder
Access them as root when in code, such as Image.FromFile("title.png")
Easily update them in the filesystem and have them automatically change in Xamarin Studio

Resources