Showing posts with label HTC. Show all posts
Showing posts with label HTC. Show all posts

Thursday, February 16, 2012

Android: How to start vendor specific Alarm Clock on any Android device?

Alarm clock is a nice to have feature for many applications and because of Intents you dont need to code this functionality in every app where you want it. For Android, adding an Alarm Clock to your application is as simple as launching an Intent for the built-in Alarm Clock of the device. The only issue here is that different manufacturers i.e HTC, Google, Samsung, Sony Ericson have their own implementation of Alarm Clock and there is no single intent that will automatically launch which ever Alarm Clock is present on the device. So to start Alarm Clock, you will first need to check which Alarm Clock is present on the device that the app is running on and then launch that Alarm clock.

The code below is what I used in one of my recent apps:
private void startAlarmActivity()
{
 PackageManager packageManager = getPackageManager();
 Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN)
                                     .addCategory(Intent.CATEGORY_LAUNCHER);

 // Verify clock implementation
 String clockImpls[][] = {
    { "HTC", "com.htc.android.worldclock",
    "com.htc.android.worldclock.WorldClockTabControl" },
    { "Standard", "com.android.deskclock", 
    "com.android.deskclock.AlarmClock" },
    { "Froyo", "com.google.android.deskclock", 
    "com.android.deskclock.DeskClock" },
    { "Motorola", "com.motorola.blur.alarmclock",
    "com.motorola.blur.alarmclock.AlarmClock" },
    { "Sony Ericsson", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" },
    { "Samsung", "com.sec.android.app.clockpackage", 
    "com.sec.android.app.clockpackage.ClockPackage" } };

 boolean foundClockImpl = false;

 for (int i = 0; i < clockImpls.length; i++)
 {
  String packageName = clockImpls[i][1];
  String className = clockImpls[i][2];
  try
  {
   ComponentName cn = new ComponentName(packageName, className);
   packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
   alarmClockIntent.setComponent(cn);
   foundClockImpl = true;
   break;
  }
  catch (NameNotFoundException e)
  {
   Log.d("ADNAN", "Alarm clock "+clockImpls[i][0]+" not found");
  }
 }
 if (foundClockImpl)
 {
  alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(alarmClockIntent);
 }
}

Saturday, December 17, 2011

Android: Debugging your application on real hardware (phone/tablet) on Ubuntu 10.10

If you own an Android smartphone and want to debug your application on your smartphone instead of emulator, you need to declare your application debuggable and setup your device.

To declare your application debuggable, add android:debuggable="true" to  element in your application's AndroidManifest.xml

To setup your device, connect it to your computer with a usb cable and run following command:
adnan@adnan-laptop:~$ adb devices
List of devices attached
emulator-5554 device
???????????? no permissions
if the output contains a line with many question marks (?), as in the above example, then Ubuntu was not able to identify your device. In this case create the file /etc/udev/rules.d/51-android.rules and add following line to it:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
Here the 0bb4 is the vendor id for HTC (Check the list of vendor ids at the end of this post for vendor id of your device) Now unplug and replug the usb cable connecting your device and again  run "adb device":
adnan@adnan-laptop:rules.d$ adb devices
List of devices attached
emulator-5554 device
SH1A6TR23522 device
Your device is ready now and can be used for debugging an application but before trying to install and debug your application on this device, make sure that you have selected the following options on your device:
Settings->Applications->Unknown sources
Settings->Applications->Development->USB debugging
Now when your run your app from Eclipse, you will be presented with a dialog of available emulators and devices. To run your app on device instead of emulator select the device from this dialog and your app will be installed and run on the device.



Vendor IDs:

CompanyUSB Vendor ID
Acer0502
ASUS0B05
Dell413C
Foxconn0489
Garmin-Asus091E
Google18D1
Hisense109B
HTC0BB4
Huawei12D1
K-Touch24E3
KT Tech2116
Kyocera0482
Lenevo17EF
LG1004
Motorola22B8
NEC0409
Nook2080
Nvidia0955
OTGV2257
Pantech10A9
Pegatron1D4D
Philips0471
PMC-Sierra04DA
Qualcomm05C6
SK Telesys1F53
Samsung04E8
Sharp04DD
Sony Ericsson0FCE
Toshiba0930
ZTE19D2