首页 文章 精选 留言 我的

精选列表

搜索[android wear],共10000篇文章
优秀的个人博客,低调大师

android多功能按钮二——基础编

很开心写了第二个多功能按钮使用Notification编写,实现方法与上一次的功能差不多(每一个按钮都会有相应的提示。至于方法,我都写在了Activity里面。欢迎大家下载参考)。是基础编。先让我们看一下图先。 Main.java代码 packagecom.smart.activity; importandroid.app.Activity; importandroid.app.Notification; importandroid.app.NotificationManager; importandroid.app.PendingIntent; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; publicclassMainextendsActivityimplementsOnClickListener{ privateNotificationManagernm; //使用默认的方法 privatevoidsetDefaults(StringtickerText,StringcontentTitile,StringcontentText,intid,intresId,intdefaults){ Notificationnotification=newNotification(resId,tickerText,System.currentTimeMillis()); PendingIntentconIntent=PendingIntent.getActivity(this,0,newIntent(this,Main.class),0); notification.setLatestEventInfo(this,contentTitile,contentText,conIntent); notification.defaults=defaults; nm.notify(id,notification); } //心情方法 privatevoidshowNotification(StringtickerText,StringcontentTitle,StringcontentText,intid,intresId){ Notificationnotification=newNotification(resId,tickerText,System.currentTimeMillis()); PendingIntentcontentTntent=PendingIntent.getActivity(this,0,getIntent(),0); notification.setLatestEventInfo(this,contentTitle,contentText,contentTntent); nm.notify(id,notification); } @Override publicvoidonClick(Viewv){ switch(v.getId()){//根据点击不同的按钮,弹出相应的提示 caseR.id.btnSmile: showNotification("情人节到了,我想你!","情人节到了,我想你!", "情人节到了,与你一起度过,yeah!",R.drawable.smile, R.drawable.smile); break; caseR.id.btnWhy: showNotification("情人节,你没送礼物给我","所以心情不好。","以后要记得", R.drawable.why,R.drawable.wrath); break; caseR.id.btnClear: nm.cancelAll(); break; caseR.id.btnRing: setDefaults("使用默认的声音","使用默认的声音","使用默认的声音",R.id.btnRing,R.drawable.smile, Notification.DEFAULT_SOUND); break; caseR.id.btnVibrate: setDefaults("使用默认的震动","使用默认的震动","使用默认的震动",R.id.btnVibrate,R.drawable.smile, Notification.DEFAULT_SOUND); break; caseR.id.btnLight: setDefaults("使用默认的Light","使用默认的Light","使用默认的Light",R.id.btnLight,R.drawable.smile, Notification.DEFAULT_SOUND); break; caseR.id.btnRingAndVibrate: setDefaults("所有的都使用默认值","所有的都使用默认值","所有的都使用默认值",R.id.btnRingAndVibrate,R.drawable.smile, Notification.DEFAULT_SOUND); break; } } @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); ButtonbtnSmile=(Button)findViewById(R.id.btnSmile); ButtonbtnWhy=(Button)findViewById(R.id.btnWhy); ButtonbtnWrath=(Button)findViewById(R.id.btnWrath); ButtonbtnClear=(Button)findViewById(R.id.btnClear); ButtonbtnRing=(Button)findViewById(R.id.btnRing); ButtonbtnVibrate=(Button)findViewById(R.id.btnVibrate); ButtonbtnLight=(Button)findViewById(R.id.btnLight); ButtonbtnRingAndVibrate=(Button)findViewById(R.id.btnRingAndVibrate); btnSmile.setOnClickListener(this); btnWrath.setOnClickListener(this); btnClear.setOnClickListener(this); btnRing.setOnClickListener(this); btnVibrate.setOnClickListener(this); btnLight.setOnClickListener(this); btnRingAndVibrate.setOnClickListener(this); } } 附件:http://down.51cto.com/data/2357582 本文转自 llb988 51CTO博客,原文链接:http://blog.51cto.com/llb988/494931,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android:进程(process)优先级、startForeground

进程(process)的优先级(从高到低): 1. 前台进程 Foreground process 1) 当前用户操作的Activity所在进程 2) 绑定了当前用户操作的Activity的Service所在进程 3) 调用了startForeground()的Service 典型场景:后台播放音乐 <1>提高Service优先级的方法: 在Service中调用startFroeground(int id, Notification notify) <2>恢复Service优先级的方法: 在Service中调用stopFroeground(boolean removeNotify) 2. 可见进程Visible process 1) 处于暂停状态的Activity 2) 绑定到暂停状态的Activity的Service 3. 服务进程Service process 通过startService()启动的Service 4. 后台进程Background process 1) 处于停止状态的Activity 5. 空进程Empty process Activity端: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 public class MainActivity extends Activity implements OnClickListener { private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.button_startservice).setOnClickListener( this ); findViewById(R.id.button_stopservice).setOnClickListener( this ); findViewById(R.id.button_stopforeground).setOnClickListener( this ); textView =(TextView) findViewById(R.id.textView1); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true ; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button_startservice: StartService(); break ; case R.id.button_stopservice: StopService(); break ; case R.id.button_stopforeground: StopForeground(); break ; default : break ; } } private void StopForeground() //恢复优先级,但不停止服务。oncreate只执行一次,但onstart每点一次就会执行一次 { Intent intent = new Intent( this , MyService. class ); intent.putExtra( "isStop" , true ); startService(intent ); } private void StopService() //停止服务 { Intent intent = new Intent( this , MyService. class ); stopService(intent ); } private void StartService() //启动服务,发出通知,设为前台优先级 { Intent service = new Intent( this , MyService. class ); startService(service ); } } Service端: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 public class MyService extends Service { @Override public void onCreate() { super .onCreate(); Notification notification = new Notification(R.drawable.ic_launcher, "启动服务发出通知" , System.currentTimeMillis()); //设置内容和点击事件 Intent intent = new Intent( this , MainActivity. class ); PendingIntent contentIntent = PendingIntent.getActivity( this , 0 ,intent , 0 ); notification.setLatestEventInfo( this , "优先级通知" , "提高优先级" , contentIntent); notification.flags =Notification.FLAG_AUTO_CANCEL; //设置为点击后自动取消 // NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // manager.notify(1235, notification); startForeground( 1235 , notification); //该方法已创建通知管理器,设置为前台优先级后,点击通知不再自动取消 } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent.getBooleanExtra( "isStop" , false )) //在onStart中降低优先级而不关闭服务 { Log.e( "Myservice" , "huifu()" ); huifu(); } return super .onStartCommand(intent, flags, startId); } private void huifu() //恢复优先级 { stopForeground( true ); } @Override public void onDestroy() { Log.e( "Myservice" , "onDestroy()" ); super .onDestroy(); } @Override public IBinder onBind(Intent intent) { throw new UnsupportedOperationException( "Not yet implemented" ); } } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1205265,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码