免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1248 | 回复: 0
打印 上一主题 下一主题

notification apk [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-09 16:21 |只看该作者 |倒序浏览
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 
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.test">

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name">
        <activity
            android:name="notification"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="point_notify" android:label="@string/app_name">
        </activity>
    </application>
</manifest>

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 
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright (C) 2008 The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <TextView
        android:id="@+id/myTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:text="@string/desc" 
        />
    <Button android:id="@+id/myButton1"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="40dip"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:text="@string/button_text"
        android:gravity="center" />
</LinearLayout>

chechunli@chechunli-PC:notification $ cat res/values/strings.xml 
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="desc">"test my_notification"</string>
    <string name="button_text">start</string>
    <string name="app_name">my_notify</string>
</resources>

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 随便找图片即可
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP