Chinaunix首页 | 论坛 | 博客
  • 博客访问: 565513
  • 博文数量: 213
  • 博客积分: 6789
  • 博客等级: 准将
  • 技术积分: 1947
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-01 17:11
文章分类

全部博文(213)

文章存档

2012年(9)

2011年(62)

2010年(99)

2009年(43)

分类: 嵌入式

2011-02-09 16:21:42

chechunli@chechunli-PC:notification $ tree
.
|-- AndroidManifest.xml
|-- Android.mk
|-- README
|-- res
|   |-- drawable
|   |   |-- icon.png
|   |   `-- offine.png
|   |-- layout
|   |   `-- main.xml
|   `-- values
|       `-- strings.xml
`-- src
    `-- com
        `-- android
            `-- test
                |-- notification.java
                `-- point_notify.java

8 directories, 9 files

chechunli@chechunli-PC:notification $ cat AndroidManifest.xml 

    package="com.android.test">

    
        android:icon="@drawable/icon"
        android:label="@string/app_name">
        
            android:name="notification"
            android:label="@string/app_name">
            
                
                
            
        
        
        
    

chechunli@chechunli-PC:notification $ cat Android.mk 
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := notification
LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

chechunli@chechunli-PC:notification $ cat res/layout/main.xml 

        xmlns:android=""
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    
        android:id="@+id/myTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:text="@string/desc" 
        />
    

chechunli@chechunli-PC:notification $ cat res/values/strings.xml 
    "test my_notification"
    start
    app_name">my_notify

chechunli@chechunli-PC:notification $ cat src/com/android/test/notification.java 
package com.android.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;

import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;

public class notification extends Activity
{
    private Button mButton1;
    private TextView mTextView1;
    /* init ptr */
    private NotificationManager myNotiManager;

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

        myNotiManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);


        mButton1 = (Button) findViewById(R.id.myButton1);
        mTextView1 = (TextView) findViewById(R.id.myTextView1);

        mButton1.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
                setNotiType(R.drawable.offine,"ok");
            }
        });
    }

    /* send Notification method */
    private void setNotiType(int iconId, String text)
    {
        /* set a intent to go to the Activity when point the notification */ 
        Intent notifyIntent=new Intent(this,point_notify.class);  
        notifyIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
        /* set PendingIntent delay Activity */ 
        PendingIntent appIntent=PendingIntent.getActivity(notification.this,0,
                notifyIntent,0);

        /* start a Notication, set ptr */ 
        Notification myNoti=new Notification();
        /* set statusbar icon */
        myNoti.icon=iconId;
        /* set statusbar text */
        myNoti.tickerText=text;
        /* set notification sound when action */
        myNoti.defaults=Notification.DEFAULT_SOUND;
        /* set Notification leaving message ptr */
        myNoti.setLatestEventInfo(notification.this,"status",text,appIntent);
        /* send Notification */
        myNotiManager.notify(0,myNoti);
    } 

}

chechunli@chechunli-PC:notification $ cat src/com/android/test/point_notify.java 
package com.android.test; 
import android.app.Activity;
import android.os.Bundle; 
import android.widget.Toast; 
public class point_notify extends Activity 
{
  @Override 
  protected void onCreate(Bundle savedInstanceState) 
  { 
    super.onCreate(savedInstanceState);
    Toast.makeText(point_notify.this, "point Activity", Toast.LENGTH_SHORT ).show(); 
    finish();
    }
  }

/res/drawalbe/*.png 随便找图片即可
阅读(1451) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~