【问题标题】:How to implement a widget?如何实现一个小部件?
【发布时间】:2011-05-06 09:40:01
【问题描述】:

您好,我创建了一个任务提醒应用程序。除了这一问题外,它还可以完美运行。我想创建一个小部件,其中任务名称(用户先前在主应用程序上设置)出现在小部件屏幕上(只有一行长?),当用户点击小部件时,它会将它们带到主应用程序。我不知道该怎么做?我查看了许多小部件教程,但它们没有考虑到主应用程序,因此没有任何帮助?

谢谢。

【问题讨论】:

  • 您是否将任务名称存储在 SQLite 数据库或类似的数据库中?

标签: android android-widget


【解决方案1】:

用于创建快捷方式,如小部件..

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多