Android当中Notification实例

点击通知栏当中的条目跳到一个新的页面,这里我们先写一个other_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
   <TextView android:id="@+id/textView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="文本框"/>

</LinearLayout>

OtherActivity.java

package com.example.notificationtest;

import android.os.Bundle;
import android.app.Activity;
public class OtherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other_activity);
}
}

在AndroidManifest.xml当中加入activity,并且加入权限

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.notificationtest"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />


    <!-- 添加操作闪光灯的权限 -->
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <!-- 添加操作震动的权限 -->
   <uses-permission android:name="android.permission.VIBRATE"/>
    

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.notificationtest.MainActivity"
            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="com.example.notificationtest.OtherActivity"
            android:label="@string/other_activity">
        </activity>

    </application>

</manifest>


main_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" 
    android:orientation="vertical">

<Button android:id="@+id/show"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="显示通知栏"/>

<Button android:id="@+id/cancle"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="取消通知栏"/>
</LinearLayout>

MainActivity.java

package com.example.notificationtest;

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity {


final int NOTIFICATION_ID=0X123;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button show=(Button) super.findViewById(R.id.show);
Button cancle=(Button) super.findViewById(R.id.cancle);

show.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

//安卓组件之间的通讯,主要是由Intent完成的
Intent intent=new Intent(MainActivity.this,OtherActivity.class);

/*
* pendingIntent是一种特殊的Intent。主要的区别在于Intent的执行立刻的,而pendingIntent的执行不是立刻的。
*/
//当点击消息的时候进行跳转
PendingIntent pi=PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

//创建一个Notification
Notification notify=new Notification();

//设置图标
notify.icon=R.drawable.ic_launcher;

//设置弹出时候的文本内容
notify.tickerText="您有一条新消息";

//为Notification设置发送时间
notify.when=System.currentTimeMillis();

//为Notification设置声音
notify.defaults=Notification.DEFAULT_SOUND;

//设置默认震动
//notify.defaults=Notification.DEFAULT_VIBRATE;

//以重复的方式1秒震动、1秒停止,共4秒动
long[] vibrate={1000,1000,1000,1000};
notify.vibrate=vibrate;

notify.defaults=Notification.DEFAULT_ALL;

//设置闪光灯的颜色为红色
//notify.ledARGB=Color.RED;

/*
* ledOffMS 0让闪光灯一直亮着
* ledOnMS ledOffMS都设为0表示的是关闭此功能
*/

//开始闪光灯的时间
//notify.ledOnMS=1;

//关闭闪光灯的时间
//notify.ledOffMS=0;

//notify.flags=Notification.FLAG_SHOW_LIGHTS;

//设置事件信息
/*
*普通通知,显示在通知栏的标题
*点击查看是副标题
*/
notify.setLatestEventInfo(MainActivity.this, "普通通知","点击查看", pi);
//获取系统的NotificationManager服务
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//发送通知
notificationManager.notify(NOTIFICATION_ID, notify);

}
});

cancle.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// 获取系统的NotificationManager服务
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

//取消通知
notificationManager.cancel(NOTIFICATION_ID);
}
});
}
}


多源动态最优潮流的分布鲁棒优化方法(IEEE118节点)(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的多源动态最优潮流的分布鲁棒优化方法,适用于IEEE118节点电力系统。该方法结合两阶段鲁棒模型与确定性模型,旨在应对电力系统中多源输入(如可再生能源)的不确定性,提升系统运行的安全性与经济性。文中详细阐述了分布鲁棒优化的建模思路,包括不确定性集合的构建、目标函数的设计以及约束条件的处理,并通过Matlab编程实现算法求解,提供了完整的仿真流程与结果分析。此外,文档还列举了大量相关电力系统优化研究案例,涵盖微电网调度、电动汽车集群并网、需求响应、储能配置等多个方向,展示了其在实际工程中的广泛应用价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源系统优化工作的工程师。; 使用场景及目标:①用于研究高比例可再生能源接入背景下电力系统的动态最优潮流问题;②支撑科研工作中对分布鲁棒优化模型的复现与改进;③为电力系统调度、规划及运行决策提供理论支持与仿真工具。; 阅读建议:建议读者结合提供的Matlab代码与IEEE118节点系统参数进行实操演练,深入理解分布鲁棒优化的建模逻辑与求解过程,同时可参考文中提及的其他优化案例拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值