How can I put widgets and shortcuts on the watch page?

I applied ViewPager in my Launcher home application and I added 5 pages to ViewPager .

Now I want to add home screen widgets and application shortcuts on separate pages in my ViewPager . What would be the best way to achieve this?

+4
source share
2 answers

Application Shortcuts:

You can specify installed applications using:

 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 additional information, for example, an application icon, follow these steps: How to get a list of installed applications for Android and choose one to launch

You can then add the layout with the ListView to the Fragment / Activity page.

Add the applications you want and onClick events to the ListView adapter to create the intention to open them.

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

Widgets: I have never seen widgets inside an application, but according to the below fooobar.com/questions/1380762 / ... , there is a way.

If you are interested in something completely different ... instead, you can create your own screen and use it instead of the usual one. This will not be an application.

0
source

Here's a similar question (partly about widgets): Any AppWidgetHost tutorials?

And here is the AppWidgetHost tutorial with a mostly working example. At least this is a good starting point.

Note: there is a typo on line 176 of the example:

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

should be replaced by

 int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); 
+1
source

Source: https://habr.com/ru/post/1380762/


All Articles