symbian 设置左右软健

最近因为工作需要,开始研究如何将自己的应用程序通过code添加到快捷方式中。下面给大家介绍一下。

  由于SDK版本不同,因此设置方式也不同

  MR 和 FP1

  // if the shortcut is in the primary container then we should move it to the secondary container

  _LIT(KContainer_Secondary, "Container_Secondary");

  RDbTable table2;

  err = table2.Open(db, KContainer_Secondary);

  User::LeaveIfError(err);

  CleanupClosePushL(table2);

  TInt rcount = table.CountL();

  TInt found=EFalse;

  for(table2.FirstL(); table2.AtRow(); table2.NextL())

  {

  table2.GetL();

  if(table2.ColUint32(1)==KShortcut1)

  {

  found = ETrue;

  break;

  }

  }

  if(found)

  {

  // if the shortcut also exists in the secondary container then we update it

  table2.UpdateL();

  }

  else

  {

  // else we create a new record

  table2.InsertL();

  }

  // update/copy to the secondary container

  TUint32 action = table.ColUint32(1);

  table2.SetColL(1, action);

  table2.SetColL(2, table.ColUint32(2));

  TInt len = table.ColLength(3);

  HBufC8* buf = HBufC8::NewLC(len);

  TPtr8 ptr(buf->Des());

  RDbColReadStream rs;

  rs.OpenLC(table, 3);

  rs.ReadL(ptr, len);

  CleanupStack::PopAndDestroy(); // rs

  RDbColWriteStream ws;

  ws.OpenLC(table2, 3);

  ws.WriteL(ptr, len);

  ws.CommitL();

  CleanupStack::PopAndDestroy(); // ws

  CleanupStack::PopAndDestroy(buf);

  table2.PutL();

  CleanupStack::PopAndDestroy(&table2);

  table.UpdateL();

  }

  else

  {

  // else we create a new record

 table.InsertL();

  }

  // we don't really understand the format of ScData, so we simply copy a ready made bytes array to it

  const TUint32 KRTType = 0x1020722a;

  const TUint8 KScData[]={0x2a,0x72,0x20,0x10,0x7c,0x50,0x27,0x10,0x01,0x00,0x00,0x00,0x00,0x00,0x00,

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb9,0xcd,0x00,0x20};

  table.SetColL(1, KShortcut1);

  table.SetColL(2, KRTType);

  RDbColWriteStream ws;

  ws.OpenLC(table, 3);

  TInt len = sizeof(KScData)/sizeof(TUint8);

  TPtr8 ptr((TUint8*)KScData, len, len);

  ws.WriteL(ptr, len);

  ws.CommitL();

  CleanupStack::PopAndDestroy(); // ws

  table.PutL();

  CleanupStack::PopAndDestroy(&table);

  err = db.Compact();

  User::LeaveIfError(err);

  CleanupStack::PopAndDestroy(&db);

  CleanupStack::PopAndDestroy(&dbs);

  const TUid KUid = {0x101f877c};

  const TUint32 KKey = 0x06;

  CRepository* cenrep = CRepository::NewLC(KUid);

  TInt value = 0;

  err = cenrep->Get(KKey, value);

  User::LeaveIfError(err);

  if(value==1)

  {

  value = (value==0)?1:0;

  err = cenrep->Set(KKey, value);

  User::LeaveIfError(err);

  User::After(100000); // wait till Standby finish the update

  value = (value==0)?1:0;

  err = cenrep->Set(KKey, value);

  User::LeaveIfError(err);

  }

  CleanupStack::PopAndDestroy(cenrep);

  在这里我们最需要关注的就是在哪个位置和设置哪个因公到此位置上。在哪个位置设置快捷方式我们应该关注的是KShortcut1的值,在这个例子中是0x1027507c,这是快捷方式栏中的第五个位置,第一个位置是0x10275078,第二个位置是0x10275079,以此类推,大家明白了吧。找到了要设置的位置,我们接下来就要关系将哪个应用设置到这个位置上了。看变量KScData,这是一个数组。里面的格式我们可能看不懂,不要紧,我们只要按照这个格式去改就可以了。

0x2a,0x72,0x20,0x10,0x7c,0x50,0x27,0x10,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb9,0xcd,0x00,0x20

  看数组的第五个值是0x7c,7c是不是就是我们要设置的位置的id的最后两位,大家再往数组的第六七八个数看,倒过来是不是就是我们要设置的位置的id,既然是这样,那么我们就将这个地方改成我们要设置的位置的id。大家再看整个数组的最后的四个数,倒过来连在一起就是我们的应用程序的Uid,把你需要设置的应用程序的UId替换上去就可以了,记住是倒着的。

  在MR和FP1中可以这样设置,那么在FP2以及以后的版本中用这个方法就不行了,可能是诺基亚做了改进,有了更好的办法,比这个简单多了。

  CRepository* cenrep = CRepository::NewLC(TUid::Uid(0x10275104));

  _LIT(KShortcut, "localapp:0x10005a22");

  TInt err = cenrep->Set(0x5, KShortcut); // WriteDeviceData

  User::LeaveIfError(err);

  CleanupStack::PopAndDestroy(cenrep);

  是不是很简单,就这么几句话。KShortcut这个是你要设置的应用的Uid,TInt err = cenrep->Set(0x5, KShortcut)里的0x5是要设置的快捷方式的位置,0x5代表的是第五个位置,同理,0x1就是第一个位置了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值