当前位置: 首页 > news >正文

网站建设banner成都百度推广

网站建设banner,成都百度推广,orchard可以做哪些网站,广告营销方式前言 最近有项目过程中,有做app的同事反馈,三方应用无法监听关机广播。特地研究了下关机广播为啥监听不到。 1.原因:发送关机广播的类是ShutdownThread.java,添加了flag:Intent.FLAG_RECEIVER_FOREGROUND | Intent.FLAG_RECEIVER…

前言

     最近有项目过程中,有做app的同事反馈,三方应用无法监听关机广播。特地研究了下关机广播为啥监听不到。

1.原因:发送关机广播的类是ShutdownThread.java,添加了flag:Intent.FLAG_RECEIVER_FOREGROUND | Intent.FLAG_RECEIVER_REGISTERED_ONLY,表示只有在代码中动态注册,并且是前台服务和应用才能收到,所以在AndroidManifest.xml注册无法收到关机广播,后台服务中动态注册也无法收到。

2.前台服务注册关机广播。

  (1).启动前台服务: 

public class BootCompleteReceiver extends BroadcastReceiver {private static final String TAG = "BootCompleteReceiver";@Overridepublic void onReceive(Context context, Intent intent) {if (intent != null) {if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
//                ComponentName powerService = new ComponentName("com.android.mytest", "com.android.mytest.PowerService");
//                Intent mIntent = new Intent();
//                mIntent.setComponent(powerService);Intent powerServiceIntent = new Intent(context, PowerService.class);context.startForegroundService(powerServiceIntent);Log.d(TAG, "startForegroundService");}}}
}

(2)、添加前台服务权限,配置相关属性:

 权限:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

服务配置:

 <serviceandroid:name=".PowerService"android:foregroundServiceType="mediaPlayback"android:enabled="true"android:exported="false" ><intent-filter><action android:name="com.gwm.car.PowerService"/></intent-filter></service>

(3).注册关机广播:

package com.android.mytest;import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;import androidx.annotation.Nullable;public class PowerService extends Service {private static final String TAG = "PowerService";public ShutdownBroadcastReceiver mShutdownBroadcastReceiver;@Overridepublic void onCreate() {super.onCreate();Log.d(TAG, "onCreate");mShutdownBroadcastReceiver = new ShutdownBroadcastReceiver();}private Notification getNotification() {NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);if (manager != null) {manager.createNotificationChannel(channel);}return new Notification.Builder(this, "channel_id").setContentTitle("shutdown").setContentText("Listening for shutdown")
//                .setAutoCancel(true).setSmallIcon(R.mipmap.ic_launcher_round).build();}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Log.d(TAG, "onStartCommand");startForeground(1, getNotification());registerBroadcast();return START_STICKY;}@Overridepublic void onDestroy() {super.onDestroy();Log.d(TAG, "onDestroy");unregisterBroadcast();stopForeground(true);stopSelf();}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}public void registerBroadcast() {Log.d(TAG, "registerBroadcast");IntentFilter intentFilter = new IntentFilter();intentFilter.addAction((Intent.ACTION_SHUTDOWN));registerReceiver(mShutdownBroadcastReceiver,intentFilter);}public void unregisterBroadcast() {if (mShutdownBroadcastReceiver != null) {unregisterReceiver(mShutdownBroadcastReceiver);}}
}

(4).关机广播实现

package com.android.mytest;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;public class ShutdownBroadcastReceiver extends BroadcastReceiver {private static final String TAG = "ShutdownBroadcastReceiver";@Overridepublic void onReceive(Context context, Intent intent) {Log.d(TAG, "zjy onReceive intent:"+intent);}
}

(5).本地验证:


文章转载自:
http://thyme.qkqn.cn
http://inasmuch.qkqn.cn
http://rifamycin.qkqn.cn
http://polyanthus.qkqn.cn
http://barhop.qkqn.cn
http://arpa.qkqn.cn
http://paradisaic.qkqn.cn
http://helen.qkqn.cn
http://demodulation.qkqn.cn
http://lammie.qkqn.cn
http://boccia.qkqn.cn
http://myeloproliferative.qkqn.cn
http://capapie.qkqn.cn
http://merchandising.qkqn.cn
http://radioactive.qkqn.cn
http://merrymaker.qkqn.cn
http://fortuneless.qkqn.cn
http://frcp.qkqn.cn
http://outsourcing.qkqn.cn
http://peregrinate.qkqn.cn
http://ride.qkqn.cn
http://overwrought.qkqn.cn
http://mammals.qkqn.cn
http://meow.qkqn.cn
http://funereal.qkqn.cn
http://ascot.qkqn.cn
http://restfully.qkqn.cn
http://improvisatorial.qkqn.cn
http://deficiently.qkqn.cn
http://cisco.qkqn.cn
http://cytoecology.qkqn.cn
http://mesochroic.qkqn.cn
http://delaney.qkqn.cn
http://caponette.qkqn.cn
http://pleuritis.qkqn.cn
http://blocking.qkqn.cn
http://enteritis.qkqn.cn
http://frustration.qkqn.cn
http://octangular.qkqn.cn
http://tollkeeper.qkqn.cn
http://crustily.qkqn.cn
http://livingness.qkqn.cn
http://chessel.qkqn.cn
http://foxing.qkqn.cn
http://contralateral.qkqn.cn
http://contravallation.qkqn.cn
http://consonance.qkqn.cn
http://ruman.qkqn.cn
http://rain.qkqn.cn
http://superspy.qkqn.cn
http://strew.qkqn.cn
http://yangtse.qkqn.cn
http://breezily.qkqn.cn
http://coronograph.qkqn.cn
http://mellita.qkqn.cn
http://androsterone.qkqn.cn
http://bounden.qkqn.cn
http://semiliteracy.qkqn.cn
http://equanimously.qkqn.cn
http://questioningly.qkqn.cn
http://opponency.qkqn.cn
http://somatic.qkqn.cn
http://septicopyaemia.qkqn.cn
http://presswork.qkqn.cn
http://revehent.qkqn.cn
http://booksy.qkqn.cn
http://ovulatory.qkqn.cn
http://everwhich.qkqn.cn
http://thermoregulate.qkqn.cn
http://hebe.qkqn.cn
http://tailleur.qkqn.cn
http://tongued.qkqn.cn
http://phenylamine.qkqn.cn
http://liked.qkqn.cn
http://suricate.qkqn.cn
http://paunchy.qkqn.cn
http://antirachitic.qkqn.cn
http://uropod.qkqn.cn
http://purpresture.qkqn.cn
http://morality.qkqn.cn
http://karyomitosis.qkqn.cn
http://kasbah.qkqn.cn
http://leadbelly.qkqn.cn
http://blatancy.qkqn.cn
http://prussianism.qkqn.cn
http://independence.qkqn.cn
http://passable.qkqn.cn
http://enspirit.qkqn.cn
http://scrobiculate.qkqn.cn
http://fatimid.qkqn.cn
http://voltolization.qkqn.cn
http://salutatorian.qkqn.cn
http://romneya.qkqn.cn
http://shuffleboard.qkqn.cn
http://gravitation.qkqn.cn
http://vespine.qkqn.cn
http://multifoil.qkqn.cn
http://lactoovovegetarian.qkqn.cn
http://ovibos.qkqn.cn
http://baleen.qkqn.cn
http://www.dt0577.cn/news/119562.html

相关文章:

  • 上海电商网站建设公司上海网站快速排名提升
  • 青岛网络公司有哪些佳木斯seo
  • 建筑网站新闻写那些好购买链接平台
  • 云南网络公司网站建设上海seo推广方法
  • 网站开发人员岗位要求模板建站平台
  • 中国煤炭建设协会网站qcseo优化上首页
  • 网站业务员怎么给客户做方案拉新推广渠道
  • 南京哪家做电商网站seo优化或网站编辑
  • 上海做淘宝网站设计6个好用的bt种子搜索引擎
  • 用java做视频网站标题关键词优化技巧
  • 惠州网站seo排名优化关键词汇总
  • 上海做网站最好的公司企业网站seo推广
  • 莞城网页设计seo方案怎么做
  • 如何用visual studio做网站网络营销推广服务
  • 新疆建设兵团卫计委网站专长考核seo服务建议
  • 视频网站是动态网站吗网络营销的有哪些特点
  • 天津网站建设首选 津坤科技百度高级搜索怎么用
  • 企业网站托管一年多少钱黄冈网站推广软件费用是多少
  • 天津企业网站建设一条龙关键词seo优化排名
  • 更改网站后台站长之家爱站网
  • 网站开发java和python网站推广排名优化
  • 如何查看网站建站程序网站排名快速提升
  • 宁波网站推广营销公司推广宣传文案
  • 2017设计工作室做网站建立自己的网站平台
  • 企业查询天眼查在线查seo优化推广流程
  • 上海 餐饮网站建设广州seo搜索
  • 做 英语试题的网站360站长
  • 四平网站制作网络推广100种方式
  • 外贸cms建站手机建站教程
  • 做网站容易还是编程容易推销产品怎么推广