How to create Android AppWidget that can go into home screen folders and home row (dock)? -
i have found several examples of android apps have simple widgets droppable home screen folders , bottom, persistent row on home screen. instance, gmail label widget, or dropbox folder widget. in attempts make similar widget - single cell icon , text view underneath - widget can on home screen.
how can make simple widget can dropped home screen folder or home row normal app icon?
is possible i'm looking not widget, app icon somehow included in widget list (but without adding second app icon in app list)?
edit:
huge kuffs getting me in right direction.
the key in kuffs points in manifest:
... <intent-filter> <action android:name="android.intent.action.create_shortcut" /> <category android:name="android.intent.category.default" /> </intent-filter> ...
as kuffs mentions, alone gets app entry in widget list. work team.
widgets can placed on home screen. cannot added dock on home screen. icons go here.
you need add shortcut.
add relevant permission manifest.
<uses-permission android:name="com.android.launcher.permission.install_shortcut" />
create activity create shortcut , add manifest example below.
e.g
<activity android:name=".shortcutactivity" android:label="@string/app_name" android:exported="true"> <intent-filter> <action android:name="android.intent.action.create_shortcut" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity>
if run app now, offered opportunity add shortcut gmail/dropbox apps (the widget screen list new shortcut creating activity). of course, activity should add shortcut useful.
the activity started os startactivityforresult()
, therefore expecting intent inside returned intent (to used os in onactivityresult
call). info found here: https://stackoverflow.com/a/11449443/1399483
so, create activity creates shortcut such this:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); intent i= new intent(); intent shortcutactivity = new intent(this, activitytolaunch.class); i.putextra(intent.extra_shortcut_intent, shortcutactivity); i.putextra(intent.extra_shortcut_name, "shortcut title"); i.putextra(intent.extra_shortcut_icon_resource,intent.shortcuticonresource.fromcontext(this, r.drawable.shortcut_icon)); setresult(result_ok, i); finish(); }
to use custom icon rather drawable resource, replace extra_shortcut_icon_resource
following:
bitmap bm; // set image want use i.putextra(intent.extra_shortcut_icon, bm);
Comments
Post a Comment