I have my class that extends FlutterPlugin and MethodCallHandler. I would like to add this to the GeneratedPluginRegistrant. If i add it manually, fultter run is going to overwrite the list. What is the solution here? (Its not a flutter package, just a Class in the native android project)
I've tried to hide app from launcher by adding and changing codes form the app source but failed every time.
Is it possible to hide a specific app from the launcher by editing Launcher3 source code? btw I'm working with AOSP build and want to integrate a 3rd party Open Source app into Settings, so that it can only be opened from Settings.
Looking through the original Launcher3 source code, you will find AppFilter file under /src/com/android/launcher3. From the file name itself, we know it’s a class to filter applications. There is a method called shouldShowApp, as its name suggest, is to consider if an application is needed to show.
Following this, AllAppsList.java uses this method in the add method. Clearly, when mAppFilter.shouldShowApp return false, it will return directly, making the applications to exclude from the application list, which will not be displayed.
Thus,
The easiest way is by simply change Line the line in AppFilter.java to be return !"com.google.android.gm".equals(app.getPackageName());, where this snippet of code will make sure that the package “com.google.android.gm” (Gmail) to be excluded from showing up in Launcher.
package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
public class AppFilter {
public static AppFilter newInstance(Context context) {
return Utilities.getOverrideObject(AppFilter.class, context,
R.string.app_filter_class);
}
public boolean shouldShowApp(ComponentName app) {
return !"com.google.android.gm".equals(app.getPackageName());
}
}
Hope this help.
I know that public classes have to be in a separate file. Otherwise, they can 't be public. I try to understand and implement swipe view with titles/tabs in an android app, so I downloaded this example, which is from The Android Open Source Project. The example works and runs like a charm, but I can 't understand why, and I also can 't understand why eclipse doesn 't show me any errors for this.
If the above method is allowed in some special cases, which are these cases?
The documentation gives the impression that all classes are top level, but they are not. Check the source code on the zip file and you will see DemoCollectionPagerAdapter and DemoObjectFragment are nested inside CollectionDemoActivity.
This is the layout of the classes.
public class CollectionDemoActivity extends FragmentActivity {
...
public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter {
...
}
public static class DemoObjectFragment extends Fragment {
...
}
}
I'm trying to set up a tabbed interface for my application. I opened up the Support13Demos project distributed with the ADT. I am able to compile and run it. In order to work from it, I created a new project with a com.example.android.supportv13.app package and copied the appropriate files into it.
Then I copied over the referenced layouts and strings. All of my compilation errors are gone, but the application starts and immediately crashes with the error: Could not find class 'com.example.android.supportv13.app.ActionBarTabsPager$TabsAdapter', referenced from method com.example.android.supportv13.app.ActionBarTabsPager.onCreate.
The class ActionBarTabsPager does include a class TabsAdapter.
public class ActionBarTabsPager extends Activity {
…
public static class TabsAdapter extends FragmentPagerAdapter
implements ActionBar.TabListener, ViewPager.OnPageChangeListener { … }
}
I have tried cleaning the project and it didn't help. Private Libraries are also enabled.
i cant speak english well ,hope i can help u.
first right-click on your project--BuildPath--ConfigureBuildPath.
and then choose Order And ExPort
maybe some jar you need but you have not choose.
here's two picture(before modified and after modified)
before:http://img.my.csdn.net/uploads/201212/04/1354602396_3168.jpg;
after:http://img.my.csdn.net/uploads/201212/04/1354602436_2486.jpg
I added the android-support-v13.jar to the exports and removed Android Private Libraries.
We're using an Android Library Project to share core classes and resources across different builds (targets) of our Android application. The Android projects for each specific target reference the Core library project (behind the scenes, Eclipse creates and references a jar from the referenced library project).
Overriding resources such as images and XML layouts is easy. Resource files placed in the target project, such as the app icon or an XML layout, automatically override the core library's resources with the same name when the app is built. However, sometimes a class needs to be overridden to enable target-specific behavior. For example, the Amazon target preferences screen cannot contain a link to the Google Play app page, requiring a change in the Amazon project's preferences.xml and preferences Activity class.
The goal is to reduce the amount of duplicate code among target projects while removing as much target-specific code from the Core library as possible. We've come up with a couple of approaches to implement logic specific to different targets:
Write the target-specific functions within Core library classes and use if/switch blocks to select behavior based on product SKU. This approach is not very modular and bloats the Core library codebase.
Extend the particular Core class in a target project and override the base (Core) class functions as needed. Then keep a reference to the base-class object in the Core library and instantiate it with an extended class object (from How to override a class within an Android library project?)
Are there other strategies to override or extend an Android library project class? What are some of the best practices for sharing and extending common classes among Android app targets?
Library project is referenced as a raw project dependency (source-based mechanism), not as a compiled jar dependency (compiled-code based library mechanism).
#yorkw this is not true for the latest versions of ADT Plugin for Eclipse
http://developer.android.com/sdk/eclipse-adt.html
From version 17 Change log
New build features
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
More info http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
Before that, update overwriting of the Activity from Library project was easy, just exclude the class. Now the library is included as jar file, and there is no way to exclude class file from jar dependency.
EDIT:
My solution to overwrete/extend Activity from library jar:
I created a simple util class:
public class ActivityUtil {
private static Class getActivityClass(Class clazz) {
// Check for extended activity
String extClassName = clazz.getName() + "Extended";
try {
Class extClass = Class.forName(extClassName);
return extClass;
} catch (ClassNotFoundException e) {
e.printStackTrace();
// Extended class is not found return base
return clazz;
}
}
public static Intent createIntent(Context context, Class clazz) {
Class activityClass = getActivityClass(clazz);
return new Intent(context, activityClass);
}
}
In order to overwrite a library's "SampleActivity" class it a the project which depends on that library, create a new class with the name SampleActivityExtended in the project in the same package and add the new activity to your AndroidManifest.xml.
IMPORTANT: all intents referencing overwritten activities should be created through the util class in the following manner:
Intent intent = ActivityUtil.createIntent(MainActivity.this, SampleActivity.class);
...
startActivity(intent);
behind the scenes, Eclipse creates and references a jar from the referenced library project.
This is not quite accurate. Library project is referenced as a raw project dependency (source-based mechanism), not as a compiled jar dependency (compiled-code based library mechanism). Currently Android SDK does not support exporting a library project to a self-contained JAR file. The library project must always be compiled/built indirectly, by referencing the library in the dependent application and building that application. When build dependent project, the compiled source and raw resources that need to be filtered/merged from Library project are copied and properly included in the final apk file. Note that Android team had started revamping the whole Library Project design (move it from ource-based mechanism to compiled-code based library mechanism) since r14, as mentioned in this earlier blog post.
What are some of the best practices for sharing and extending common classes among Android app targets?
The solution given by Android is Library Project.
The solution given by Java is Inheritance and Polymorphism.
Come together, the best practice IMO is the second option you mentioned in the question:
2.Extend the particular Core class in a target project and override the base (Core) class functions as needed. Then keep a reference to the base-class object in the Core library and instantiate it with an extended class object (from Android library project - How to overwrite a class?)
From my personal experience, I always use Android Library Project (Sometimes with Regular Java Project, for implementing/building common-lib.jar that contains only POJO) manage common code, for instance SuperActivity or SuperService, and extends/implements proper classes/interfaces in the dependent project for Polymorphism.
Solution based on PoisoneR's solution and Turbo's solution.
public static Class<?> getExtendedClass(Context context, String clsName) {
// Check for extended activity
String pkgName = context.getPackageName();
Logger.log("pkgName", pkgName);
String extClassName = pkgName + "." + clsName + "Extended";
Logger.log("extClassName", extClassName);
try {
Class<?> extClass = Class.forName(extClassName);
return extClass;
} catch (ClassNotFoundException e) {
e.printStackTrace();
// Extended class is not found return base
return null;
}
}
The benefits of this is that
The extended class can be in the project's package, not the library's package. Thanks to Turbo for this part.
By taking a String as an argument instead of a Class object, this method is able to be used even with ProGuard. getName() is where the problem is with ProGuard, as that will return something like "a" instead of the name of the original class. So in the original solution instead of looking for ClassExtended it will look for aExtended instead, something which does not exist.
What about using a callback approach here? (Okay, callback is a little bit misleading but I currently have no other word for it:
You could declare an interface in every Activity which should/may be expanded by the user. This interface will have methods like List<Preference> getPreferences(Activity activity) (pass whatever parameters you need here, I would use an Activity or at least a Context to be futureproof).
This approach could give you what you want when I have understood it correctly. While I haven't done this before and don't know how other people handle this I would give it a try and see if it works.
Could you, please, clarify what is different in Kindle and regular Android?
I think - they are the same.
What you need is different resources for Kindle and other devices. Then use appropriate resource.
For example I use 2 links to store:
<string name="appStore"><a href=http://market.android.com/details?id=com.puzzle.jigsaw>Android Market</a> or <a href=http://www.amazon.com/gp/mas/dl/android?p=com.puzzle.jigsaw>Amazon Appstore</a> <br>http://market.android.com/details?id=com.puzzle.jigsaw <br>href=http://www.amazon.com/gp/mas/dl/android?p=com.puzzle.jigsaw</string>
<string name="appStore_amazon"><a href=http://www.amazon.com/gp/mas/dl/android?p=com.puzzle.jigsaw>Amazon Appstore</a> <br>href=http://www.amazon.com/gp/mas/dl/android?p=com.puzzle.jigsaw</string>
and use appStore for all none Amazone product and appStore_amazon for Kindle.
How to determine where are you on run time - that would be another question which was answered here many times.
I was inspired by PoinsoneR's answer to create a Utility class to do the same thing for Fragments - override a fragment in an android Library. The steps are similar to his answer so I won't go into great detail, but here is the class:
package com.mysweetapp.utilities;
import android.support.v4.app.Fragment;
public class FragmentUtilities
{
private static Class getFragmentClass(Class clazz)
{
// Check for extended fragment
String extClassName = clazz.getName() + "Extended";
try
{
Class extClass = Class.forName(extClassName);
return extClass;
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
// Extended class is not found return base
return clazz;
}
}
public static Fragment getFragment(Class clazz)
{
Class fragmentClass = getFragmentClass(clazz);
Fragment toRet = null;
try
{
toRet = (Fragment)fragmentClass.newInstance();
return toRet;
}
catch (InstantiationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return toRet;
}
}
Usage:
FragmentUtilities.getFragment(MySpecialFragment.class)
You can also use an Activity factory if you need to provide extended activitys for differnt build variants and have your library deal with the abstract factory alone. This can be set in your build variants Application file.