shortcut+livefolder
Livefolder 組件 因爲不是android剛開始支持的 導致先期開發的ContentProvider 並沒有預先給予支持 而Livefolder對列名有一定限制 導致Livefolder顯得有點雞肋
所以 今天打算以shortcut形式 來使用livefolder
整個代碼也比較簡單 貼代碼 如果有不懂得地方 諸位跟帖 再細說
源代碼:
public class LivefolderTest extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
CursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,c,
new String[] {People.NAME,People.NUMBER},
new int[] {android.R.id.text1,android.R.id.text2});
setListAdapter(adapter);
if (getIntent().getAction()
.equals(Intent.ACTION_CREATE_SHORTCUT)) {
createShortcut("ContactLivefolder");
}
}
public void createShortcut(String name){
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addShortcut = new Intent();
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
Parcelable icon = Intent.ShortcutIconResource.fromContext(
this,R.drawable.icon);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
this.setResult(RESULT_OK, addShortcut);
finish();
}
emulator 運行截圖:
* 系統聯繫人:
* shortcut 運行:
done!!!