Android - Fragment API for API level < 11 - android

I have came across a problem for dynamic forms in my app, which is suited for Android 2.1 and above. I know there is new Fragment API since API level 11 (Android 3.0 Honeycomb), but also I have read an article - http://android-developers.blogspot.com/2011/03/fragments-for-all.html stating Fragment Api is available also for API level lower then 11 in, so called, Compatiblity package. I have installed it via SDK, but I am not able to use is in my App, e.g. I cannot import android.app.FragmentManager, application doesn't know it.
Do you know, how to solve it? Is Fragment API truely available for older API levels? If so, how to make them going? Or is there any other solution like Fragments API? I will need for dynamic generated forms if possible
Thanks
Hmyzak

Android Studio:
Add a dependency for support compatibility package v4:
dependencies {
...
compile 'com.android.support:support-v4:21.0.+'
...
}
and then use import android.support.v4.app.Fragment; instead of import android.app.Fragment; in imports.

You need to add the package to the build path.

Use ActionBarSherlock. It comes with a lot of working examples.

Related

PopupMenu in older android API

can I use PopupMenu in older API without using support library v7 ?
I am already using support library v4, but it's not enough for this
and what is the alternative, if I don't use it ?
PopupMenu is only available in API 11 or higher. As far as I can tell from the documentation it is not included in any support library and thus cannot be used on a lower api version. You should probably use an alternative like a Dialog or ContextMenu in those situations. It's not the same thing but kind of close.
You must import support v7 in your application same as follow:
Adding libraries with resources
and in your project import android.support.v7.widget.PopupMenu and then compile your code with that your popup menu is compatible for android 2.2 and above.

android.app.ActionBar class not being recognized

The problem i'm facing right now is Android Studio doesn't recognize import classes api level 11 and above. And in manifest the minsdk version i'm using is 14, this is fustrating. I'm trying to import android.app.ActionBar but i can't, i was going to use support library but there's no sense if i'm using api level 14.
Thanks.
I resolved it modyfing the build.gradle in the section {android,defaultConfig} :-)

Regarding Minimum Required SDK , Target SDK , Compile with options in Android

Can anyone explain regarding the Minimum Required SDK, Target SDK , Compile with options while creating an application.
If i set the minimum required SDK as API 8, Target SDK as API 16 and Compile with API 17,
will it work on Froyo devices in adroid?
If i want to use the methods introduced in API 16 or Library uses API 16, and want my app
to work on Froyo or ICS devices, how can i achieve this?
Thanks in advance.
You can use API-Level 16 methods only on devices that are Level 16 and higher. But you can check in your app and only call them when this is the case. Look into my small test-app which uses API-11-methods and runs from API-3 and up.
http://code.google.com/p/android-change-log/source/browse/trunk/src/sheetrock/panda/changelog/ChangeLog.java
Look at lines 40-41, 144-145 and 324-341. You don't need any third party libraries for this, but you need to put your higher API code in a separate class (lines 324-341).
Yes. But be careful not to include API higher than Froyo in your application
From my understanding, you can't, unless you use third party libraries. There are useful libraries out there which help you realise that:ViewPager and ActionBarSherlock.
Yes ofcourse for first question. If you use like this.
android:minSdkVersion="8"
android:targetSdkVersion="16"
For second. you can go for third party library if you import it, surely will work.For eg:
special features introduced in android 4.0 with tabs and swipe.But to overcome that
actionbar sherlock library been introduced which support in all version and in github.
Hope it helps you.

Is it Possible? app developed in 2.x device with compatibility lib V4 to use native library if device is android 3.x or greater device?

Before posting my question. i looked this one stack overflow.and wann know, is it really impossible? i have app developed in android 2.2 with the use of compatibility library v4. which is also compatible with android 3.0 device. and i want my app to use android compatibility library v4 if device is android 2.x and native library if device is android 3.x. any suggestion??
thanks in advance
I haven't tried what I'm recommending, but it could work:
Set your build target to Honeycomb
Use an if-else statement and Build info to determine which version of Android you're on
If you're below 3.0, use the compatibility library in your code
If you're on 3.0 or above, use the native library.
For this to work, you'll need to use fully qualified names in your code, instead of having import statements on the top. So for Fragments on 3.0 and above, you'd use:
android.app.Fragment fragment;
instead of:
Fragment fragment;
and an import statement on top. And finally for pre 3.0, you'd need statements like:
android.support.v4.app.Fragment fragment;
You need to use these names as you cannot import both version and use only one.

Imports just on API level > 15

I have a App created on API 8. Now I want to make it work with ICS and for that I need additional imports which are not available in API 8.
I want to add following imports:
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
So do I have to make a diffenent app just for API > 15? The name of the App should not change.
Or maybe it is possible to place 2 App versions and make the minSdkVersion and maxSdkVersion according to the API level into Google Play?
How do you handle that?
I have a App created on API 8.
Great!
Now I want to make it work with ICS and for that I need additional imports which are not available in API 8.
No problem! Since import statements are applied at compile time, so long as you set your project's build target (e.g., Project > Properties > Android) to API Level 14 or higher, your code will compile fine.
So do I have to make a diffenent app just for API > 15?
No. Just use version guard blocks to ensure that you do not try using the newer code on older devices:
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// do stuff with CalendarContract
}
Or maybe it is possible to place 2 App versions and make the minSdkVersion and maxSdkVersion according to the API level into Google Play?
That should not be necessary.
You want to add a compatibility shim to your existing app so that it works on lower API levels and is still able to access API's from higher levels.
In general, the way to do this is to isolate the code that uses the higher-level API's in classes that are loaded at run-time via reflection, only if the API level supports them.

Categories

Resources