2011-05-06 72 views
-1

嗨我已经创建了一个任务提醒应用程序。除了这个问题之外,它完美地工作。我想创建一个小部件,其中任务名称(用户以前在主应用中设置的名称)出现在小部件屏幕上(仅一行很长?),并且当用户单击小部件时,它将它们带到主应用程序。我不知道如何继续前进?我已经检查了很多小部件教程,但它们没有帮助,因为它们没有考虑到主要应用程序?如何实现一个小部件?

谢谢。

+0

你存储任务名称SQLite数据库或类似的东西? – 2011-05-06 09:59:48

回答

0

用于创建一个像小部件的快捷方式..

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); 
相关问题