开发者

How to implement a widget?

Hi I have created a task reminder application. It works perfect apart from this one issue. I would like to create a small widget where a task name (that the user previously set on the main app) appears on the widget screen(only a line long?) and when the user clicks on the widget, it takes them to the main app. I am not sure how to go forward with this? I have checked many widget tutorials but they are of no help as they don't take the ma开发者_如何学运维in application into consideration?

Thanks.


for create shortcut like widget..

Intent shortcutIntent; 
shortcutIntent = new Intent(); 
shortcutIntent.setComponent(new ComponentName( 
this.getPackageName(), ".classname")); 

shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

final Intent putShortCutIntent = new Intent(); 
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, 
shortcutIntent); 

// Sets the custom shortcut's title 
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
"Title"); 
putShortCutIntent.putExtra( 
Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 
Intent.ShortcutIconResource.fromContext( 
this, R.drawable.icon)); 
putShortCutIntent 
.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
sendBroadcast(putShortCutIntent);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜