多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
下面这个代码是关于安卓Nitification的,也就是手机的通知栏。这个小程序创建了通知栏的一个消息,主要是演示下格式。 ~~~ package com.example.mytest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Notification; import android.app.Notification.Builder; import android.app.NotificationManager; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { private Button bt; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt = (Button) findViewById(R.id.bt); bt.setOnClickListener(new OnClickListener() { @SuppressLint("NewApi") @Override public void onClick(View v) { // TODO Auto-generated method stub NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Builder(MainActivity.this); builder.setContentTitle("通知标题"); builder.setContentText("通知内容"); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.xiamu)); builder.setSmallIcon(R.drawable.ic_launcher); Notification notification = builder.build(); nm.notify(10, notification); } }); } } ~~~