现在的位置: 首页 > 综合 > 正文

S60桌面快捷设置_很霸道的说

2012年10月24日 ⁄ 综合 ⁄ 共 3580字 ⁄ 字号 评论关闭

 

 最近因为工作需要,开始研究如何将自己的应用程序通过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就是第一个位置了。

 

这部分代码测试需要注意,和可能导致手机不能开机,本人已通过测试。qq:9804727

 

源文档 <http://veronica870225.blog.sohu.com/148326186.html>

抱歉!评论已关闭.