Amazon Gift Cards

Saturday, March 28, 2009

Notification in Android

Notification in android is handy way to notify your user. Here is a very simple example of it. We would combine it with WebView with ZoomControls in Android.

First of all rename the Main class on the WebView tutorial to WebActivity making it
public class WebActivity extends Activity {
private WebView myWebView;


Then import the following to your manifest file
<application android:icon="@drawable/icon" android:label="@string/app_name">
  .....
  <activity android:name=".WebActivity"/>
</application>
<uses-permission android:name="android.permission.INTERNET">


public class Main extends Activity implements View.OnClickListener {
  private Button Button01;
  private NotificationManager mManager;
  private static final int APP_ID = 0; 

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    this.Button01 = (Button) this.findViewById( R.id.Button01);
    this.Button01.setOnClickListener(this);

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  }

  @Override
  public void onClick(View v) {
    Intent intent = new Intent(this,WebActivity.class);

    Notification notification = new Notification(R.drawable.icon,
"Notify", System.currentTimeMillis());
    notification.setLatestEventInfo(Main.this,
"App Name","Description of the notification",
PendingIntent.getActivity(this.getBaseContext(), 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT));
    mManager.notify(APP_ID, notification);
  }
}



Quick Explanation:
(Most of it is explained on the android dev site)

mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Call the notification service

Notification notification = new Notification(R.drawable.icon,"Notify", System.currentTimeMillis());
*** Create a new notification with an icon and label and do the notification now. See Notification Class

notification.setLatestEventInfo(Main.this,"App Name","Description of the notification",PendingIntent.getActivity(this.getBaseContext(), 0, intent,PendingIntent.FLAG_CANCEL_CURRENT));
*** Set the info of the notification, see Notification Class

mManager.notify(APP_ID, notification);
Notify the notification manager about our new notification and pass an id for it

Output:


Reference:
PhotoStream Source

Update History
   Jan 17, 2012 - Visual Update

Monday, March 23, 2009

Connecting and debugging your application with your phone on Ubuntu 9.04

After a long time, i'm back with an android post. This time is how to connect your g1 to Ubuntu 9.04 (im using 64bit). I won't explain that detailed coz i found an article that could help you with the detailed explanation. Anyway here's how i made it.

* Alt + F2, gnome-terminal then enter

* type: lsusb
look for and memorize the words after ID and before the colon(:) :
Bus 001 Device 004: ID 0bb4:0c02 High Tech Computer Corp.

* sudo gedit /etc/udev/rules.d/50-android.rules

paste the following to the file (the {idVendor} is the one you memorized previously)
* SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"

* sudo chmod a+rx /etc/udev/rules.d/50-android.rules

* sudo /etc/init.d/udev restart


Done with the ubuntu's part, now on android's part
* go to tools folder of your sdk

* sudo ./adb kill-server

* sudo ./adb devices

If it still doesn't work, try connecting it to your computer's back usb post or change the usb cord (coz some usb has lower power then the others)

If you want a detailed explanation on the Ubuntu's part
http://www.johandekoning.nl/index.php/2009/02/07/android-dev-phone-ubuntu-and-vmware-server/
Other resources: http://androidforums.com/support/3534-problems-mounting-communicating-g1-ubuntu.html