Hi i have develop a application in android which run in every device, i use different layout for different size device's but i have use some code programmatically without xml so, it create a problem in different size device.
so i require to change the package acording to the device resolution so, it can posible in android to programmatically detect and change the package class
plz, give some suggestion.
Thanking you.
i have use android2.2 for my application
No, it is not possible to programmatically change the application package. For device-specific display sizes you can create size-specific layouts as described in the guide and use getResources().getConfiguration() to programmatically choose specific code paths to execute.
"i use different layout for different size device's " means you just use dp/dip sizes or that you have completely different layouts for each screen size?
If you only used dp/dip units, then you can add a scalefactor to your code to get the matching coordinates. If you are using different layouts, it's much more difficult. Depending on how many different layout configurations you have, you could build seperate apk files and upload them parallel. The Market will handle the distribution of the matching files then.
Another way:
Create an installer app which checks the device configuration and downloads the device-specific package afterwards from a ftp/network resource.
After installation, delete the installer and the .apk file.
Related
I have recently started creating an Android application using Appcelerator's Titanium.
Since in the application I requires to keep several images/icons with different sizes & dimensions essentially, So I need some advice on how I should organize them in the project.
And as you know like in Android project (Android studio or Eclipse with Android SDK) there is a predefined folder structure so if you want to keep any image then put them in all device sizes corresponding to the prescribed folders. So based on device sizes it will automatically detect corresponding dimension image from device preferable folder.
So does same approach can we achieve in Appcelerator's Titanium ?
Below is the default project structure for Appcelerator's Titanium project (5.1.2.GA)
As you can see there is 2 places where I can keep images. So can you suggest me where I can keep my images and how can I access them
Thanks, Any suggestion will be helpful for me. ~Chandan
Titanium supports platform, device and density specific images via folder and file conventions. I won't go into details here, but these two links walk you through:
How to use Device Specific Images
How to use Density Specific Images
The first part is used to be more specific about when these resources should be used. Images in sub-directories give us more control over when they are used.For example images that are in a folder named "res-long-land-hdpi" will be used for:
Long screens, such as WQVGA, WVGA, FWVGA
Device is in landscape orientation (horizontal)
High-density screens; approximately 240dpi.
Documentation Link
for me i deleted all folders in android/images (First) and i replaced them by folders in android/res (second)
like this
In android project there are multiple folders, I know you can simply override these with one 'Drawable' folder.
My question is: When people download my app, will it take up more room if I have manually catered to all the different Drawable folders instead of just overriding them with one?
yea, but your app will be slightly slower, cause android has to re-size the images (whereas if you have different folders it uses the respective images)
Yes, different Drawable is for different dpi based device screen and its part of APK.
When you download APK then even drawable is also part of it and it gets stored on device and it does take space.
Different Drawable folders in android directory is for supporting different screen sizes. for better UI experience you should put drawables in appropriate folders.I think you should have look into it before proceeding further Know android project directories
I'm trying to dynamically change the UI based on whether or not the device is less than 5 inches and is in landscape mode. I don't want to use XML layouts if possible to do this, but it's the only way that's working so far. Is it possible to do what I'm trying to do?
If you insist using code to determine the device dimensions an orientation you could use the resource configuration class that exposes various device configuration variables.
In your case here are the values you need:
getResources().getConfiguration().orientation
getResources().getConfiguration().screenWidthDp
getResources().getConfiguration().screenHeightDp
please note that it is highly recommended to use the provided folder naming conventions to change the app UI according to device orientation. If you incorporate fragments as well then you could achieve simpler more maintainable code.
Your best bet is to take advantage of the configuration qualifiers built into android. You can find more information about them here:
http://developer.android.com/guide/practices/screens_support.html
If you scroll down to the Using configuration qualifiers section, you will see a list of folder extensions you can use. These files in these folders overwrite sections of the matching files in folders without the extension.
IE.
A boolean could be set in dimens.xml in the values-land-small folder that will overwrite the corresponding boolean in the dimens.xml file stored in the values folder. You can then use the value of this boolean in code to target specific devices and specific configurations without having multiple xml layouts directly.
I am programming an android application and I'd like to use the system icons for mail, phone, calendar and contacts inside this application. The problem is, that these icons differ from system to system (different android versions and different smartphones) and I want to keep the application and the system consistent. Is there an easy way to achieve this?
In XML use default android drawables from #android:drawable/... and in code use android.R.drawable....
You can use the standard drawable using
#android:drawable/[icon_name] in your xml file
android.R.drawable.[icon_name] in your java code
You can see different icon in your file system in
[SDK PATH]/platforms/platforms/[ANDROID_VERSION]/data/res
Some images are standard...like contacts, calendar :)
You can't keep system consistent. For what? New versions of Android are usually prettier than older ones (well, it's my opinion).
The only way to keep system icons same for your app - copy them into your drawables instead of using direct reference to them (like #android:drawable/).
First of all if you intend to use the default images (icons) for mail , phonr etc.
This default can be used as android.R.drawable.name in code or #android:drawable/ in xml from http://docs.since2006.com/android/2.1-drawables.php
But as this will vary from OS versinos to Versions.
So , if you need to use an unique GUI for the app for all versions and devices.
Please do not use android provided images , simply use your own graphics or images supplied in drawables resources explicitly by you for your app.
If you're ok with icons from each system you can get it via PackageManager and getApplicationInfo method.
If you're not, you should copy the resources from the platform into your own application.
I have a question I cant find an answer to anywhere. Suppose I have an app which basically has some content catering to a group of users. So I have the source code checked into some sort of an SVN , and I have an apk generated which I use as required on the tablet. Now I have a different set of users. The only thing that changes are logos in the app which are images in the drawable folder, language of the app and content within the app. Now how can I dynamically pick the right logo or language based on the user. Based on what I understand I have to build the source code again using the parameters required and generate another apk. Is there no way i can communicate with the apk as to who the user is and it can show the right logo.? Is there any method kind of like String_Resources.xml in the .Net world.
Handling Screen Sizes
http://developer.android.com/guide/practices/screens_support.html
Handling Localization
http://developer.android.com/guide/topics/resources/localization.html
These 2 resources should help. I'm not sure what you mean by 'pick the right logo or language based on the user." Users Device or Users Language??
The system language settings on the users device will determine which language folder to use (if you have them set up as outlined in the second link).
If you want select a logo based on screen size, see the first link. Basically you create identical xml layouts and put them into separate folders like:
layout-normal
layout-small
layout-large
layout-xlarge
then just change the drawable in the xml file for each screen size.
No, you need to generate new apk with new app package e.g.
myapplication.company1
myapplication.company2
...
myapplication.companyN
This topic may be helpful