1. 直接调用clock的程序界面,
        Intent intent = new Intent();
        intent.setClassName("com.android.deskclock", "com.android.deskclock.deskclock");
        startActivity(intent);2. 如果只是想要获取当前clock显示的时间,可以通过下面的代码来获得
        Calendar mCalendar;
        String mFormat;        mCalendar = Calendar.getInstance();
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        mFormat = Alarms.get24HourMode(mContext) ? M24 : M12;
        CharSequence newTime = DateFormat.format(mFormat, mCalendar);

解决方案 »

  1.   


    To yyy025025025:
      
      这两种方法我都试了,都出现了问题?
       第1种方法:
      public class TestApp extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            Intent intent = new Intent();
            intent.setClassName("com.android.deskclock", "com.android.deskclock.deskclock");
            startActivity(intent);        
        }
    }ERROR/AndroidRuntime(729): Caused by: android.content.ActivityNotFoundException:    Unable to find explicit activity class           {com.android.deskclock/com.android.deskclock.deskclock}; 
    出现上面的错误!
    我用的是sdk2.1,换成sdk1.5出现同样的错误!第2种方法:Calendar mCalendar;
      String mFormat;  mCalendar = Calendar.getInstance();
      mCalendar.setTimeInMillis(System.currentTimeMillis());
      mFormat = Alarms.get24HourMode(mContext) ? M24 : M12;
      CharSequence newTime = DateFormat.format(mFormat, mCalendar);出错:
        M24 : M12;是什么无法被解析!!
         Alarms;是什么无法被解析!!请问yyy025025025是什么原因?
      

  2.   

    第2种方法改成  Calendar mCalendar;
      String mFormat;
      private final static String M12 = "hh:mm";
      private final static String M24 = "kk:mm";  mCalendar = Calendar.getInstance();
      mCalendar.setTimeInMillis(System.currentTimeMillis());
      mFormat = M24;
      CharSequence newTime = DateFormat.format(mFormat, mCalendar);
      

  3.   

    方法一:
    1. 直接调用clock的程序界面,
    Intent intent = new Intent();
    intent.setClassName("com.android.deskclock", "com.android.deskclock.deskclock");
    startActivity(intent);
    其中deskclock在模拟器中没有,所以运行不了。
      

  4.   


    To yyy025025025:方法1)在真机下运行出现错误:05-15 17:00:42.345: ERROR/AndroidRuntime(489): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.deskclock/com.android.deskclock.deskclock};不清楚是什么原因呢?我用的真机是Htc Tatto!方法2):
    运行通过!
      

  5.   

    把你tatto接到ddms里面,把clock打开,你看看进程是不是deskclock了,我估计都不是这个。
    另一种情况即使有deskclock,HTC也可能将入口activity换掉,那么一样会造成无法启动了。还是不要用了吧,能获得时间就好。
      

  6.   


    现在运行还是出现Activity找不到问题!
    05-15 17:00:42.345: ERROR/AndroidRuntime(489): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.deskclock/com.android.deskclock.deskclock};
    功能要求是点击图标后,调用系统自带时钟!所以要实现功能!