4

I have implemented aViewPagerin my customize home Launcher application and I added 5 pages in theViewPager.

Now I want to add home screen widgets and application shortcuts on individual pages in myViewPager. What would be the best way to accomplish this?

HandlerExploit
  • 7,831
  • 4
  • 28
  • 49
sam_k
  • 5,757
  • 13
  • 70
  • 106

2 Answers2

1

Here is a similar question (in part about Widgets): Any AppWidgetHost-tutorials out there?

And here is an AppWidgetHost tutorial with a mostly working example. At least it's a good starting point.

Note: there is a misprint in line 176 of the example:

int appWidgetId = WidgetScreen.this.mAppWidgetHost.allocateAppWidgetId();

should be replaced by

int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
Community
  • 1
  • 1
praetorian droid
  • 2,921
  • 1
  • 15
  • 18
0

Application shortcuts:

You can list installed applications with:

final PackageManager pm = getPackageManager();
//get a list of installed apps.
        List<ApplicationInfo> packages = pm
                .getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo packageInfo : packages) {

            Log.d(TAG, "Installed package :" + packageInfo.packageName);
            Log.d(TAG,
                    "Launch Activity :"
                            + pm.getLaunchIntentForPackage(packageInfo.packageName)); 

        }// the getLaunchIntentForPackage returns an intent that you can use with startActivity() 
    }

If you need more info like app icon check this: How to get a list of installed android applications and pick one to run

Then you can add a Layout with a ListView to the page Fragment/Activity.

Add within the adapter for the ListView the applications you want, and onClick events to create an intent to open them.

I think this is the best way to show a list of applications, with icons etc.

Widgets: I never seen widgets inside an app, but according to the answer below https://stackoverflow.com/a/8218587/327011 apparently there is a way.

If you are interested in something a little different... you can instead create a custom Home Screen, and use it instead of custom. This will not be a app.

Community
  • 1
  • 1
neteinstein
  • 16,975
  • 11
  • 87
  • 117
  • @NeTelnStEiN He wants to add widgets, live folder, shortcuts etc... just like at default HomeScreen we do. – Pawan Nov 18 '11 at 17:56