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

网站建设公司发展规划网络营销案例ppt

网站建设公司发展规划,网络营销案例ppt,郑州网站开发定制,边坝网站制作上篇文章介绍了传感器的基础用法(如有需要,可先移步),下面将通过两个实战案例学习具体如何使用。 一、靠近黑屏 这是距离传感器的简单应用。 –检测手机是否贴在耳朵上正在打电话,以便自动熄灭屏幕达到省电的目的。也…

        上篇文章介绍了传感器的基础用法(如有需要,可先移步),下面将通过两个实战案例学习具体如何使用。

一、靠近黑屏

        这是距离传感器的简单应用。

        –检测手机是否贴在耳朵上正在打电话,以便自动熄灭屏幕达到省电的目的。也可用于皮套、口袋模式下自动实现解锁与锁屏动作。

        –用到电量管理器PowerManager来控制屏幕的亮灭,需要获取权限

        –我们并不需要获取距离传感器的值,而是让它和PowerManager的内建功能一起配合使用

新建项目SensorDemo3。

修改activity_main.xml文件,代码如下:

        下面定义了一个RelativeLayout布局,里面有一个TextView

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><RelativeLayoutxmlns: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"android:orientation="vertical"android:padding="5dp"><TextViewandroid:textSize="20sp"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="不要靠近我~~我会变黑的"/></RelativeLayout></androidx.constraintlayout.widget.ConstraintLayout>

修改AndroidManifest.xml文件,获取权限

        获取相关的系统唤醒锁定权限。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><uses-permission android:name="android.permission.WAKE_LOCK"/>..............

修改MainAcitivity,代码如下:

public class MainActivity extends AppCompatActivity implements SensorEventListener {private SensorManager sensorManager;/*使用电量管理器控制屏幕的熄灭和唤醒*/private PowerManager pm;private PowerManager.WakeLock wakeLock;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);pm = (PowerManager) getSystemService(POWER_SERVICE);closeOrClose();}/*** 初始化唤醒锁wakeLock,直接使用内置PROXIMITY_SCREEN_OFF_WAKE_LOCK,* 就可以直接实现靠近熄灭屏幕的功能** 初始化完要调用acquire()方法启用*/@SuppressLint("InvalidWakeLockTag")private void closeOrClose() {wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,"w1");wakeLock.setReferenceCounted(false);wakeLock.acquire();}@Overrideprotected void onResume() {/*注册距离传感器,只有注册了距离传感器唤醒锁才有效果*/sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY),SensorManager.SENSOR_DELAY_NORMAL);super.onResume();}@Overrideprotected void onStop() {/*释放传感器和唤醒锁*/wakeLock.release();sensorManager.unregisterListener(this);super.onStop();}@Overridepublic void onSensorChanged(SensorEvent event) {}@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {}
}

PowerManager要点

•WakeLock级别:
–    PARTIAL_WAKE_LOCK       保持CPU运转,屏幕和键盘背光可能关闭
–    SCREEN_DIM_WAKE_LOCK    保持CPU运转,保持屏幕常亮(亮度低),键盘背光可能关闭
–    SCREEN_BRIGHT_WAKE_LOCK 保持CPU运转,保持屏幕和键盘背光高亮
–    FULL_WAKE_LOCK          保持CPU运转,保持屏幕和键盘背光高亮(亮度最高)
–    ACQUIRE_CAUSES_WAKEUP            强制亮屏,针对一些必须通知用户的操作
–    ON_AFTER_RELEASE                 当锁被释放时,保持亮屏一段时间(如果释放时屏幕没亮,则不会亮屏)
–    PROXIMITY_SCREEN_OFF_WAKE_LOCK   和接近传感器配合,当用户接近屏幕时黑屏,离开时亮屏(例如打电话)
•WakeLock方法:
–    void acquire()              获得WakeLock,除非显式释放,否则不会解锁(经测试,APP进程被杀死后,锁会失效)
–    void acquire(long timeOut)  当超过timeOut之后系统自动释放WakeLock
–    void release()              释放WakeLock
–    boolean isHeld()            是否已经获取WakeLock 
–    void setReferenceCounted(boolean value) 是否使用引用计数(默认ture): 一个WakeLock调用acquire()多次,也必须release()多次才能释放,    如果释放次数比acquire()多,则抛出异常: java.lang.RuntimeException: WakeLock under-locked MyTAG
可参考下面文章:
https://www.jianshu.com/p/2cfd179ef8dc
https://blog.csdn.net/fengyeNom1/article/details/121373158

二、计步器

最新记步模式 使用 Android4.4 Kitkat 新增的 STEP DETECTOR 以及 STEP COUNTER 传感器。

Step counter sensor
•    TYPE_STEP_COUNTER :计步器(记录历史步数累加值)
    这种类型的传感器返回用户自上次重新激活以来所采取的步骤数。 该值作为浮点数返回(小数部分设置为零),仅在系统重新引导时才将其重置为零。 事件的时间戳设置为采取该事件的最后一步的时间。 该传感器以硬件实现,预计功耗低。 如果要持续跟踪长时间的步数,请勿取消注册该传感器,以便即使 AP 处于挂起模式,也会在后台继续计数步骤,并且当 AP 处于挂起状态时报告聚合计数 苏醒。 应用程序需要保留该传感器的注册,因为如果没有激活步进计数器不计数步骤。 该传感器适用于健身跟踪应用。 它被定义为 REPORTING_MODE_ON_CHANGE 传感器。
Step detector sensor
•    TYPE_STEP_DETECTOR :检测器(检测每次步伐数据)
    这种类型的传感器每次用户触发一个事件。 唯一允许的返回值为 1.0 ,并为每个步骤生成一个事件。 与任何其他事件一样,时间戳表示事件(这里是步骤)何时发生,这对应于当脚撞到地面时,产生加速度的高变化。 该传感器仅用于检测每个单独的步骤,例如执行航位推算。 如果您只需要在一段时间内累积的步数,请注册 TYPE_STEP_COUNTER 。 它被定义为 REPORTING_MODE_SPECIAL_TRIGGER 传感器。
新建项目SensorDemo4
修改AndroidManifest.xml,申请权限。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><uses-feature android:name="android.hardware.sensor.stepcounter" /><uses-feature android:name="android.hardware.sensor.stepdetector" /><uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>..............

修改activity_main.xml代码,如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/step_counter_txt"android:text="总步数"android:layout_gravity="center"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/step_counter"android:text="-1"android:layout_gravity="center"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/step_detector_txt"android:text="单次记步"android:layout_gravity="center" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/step_detector"android:text="0"android:layout_gravity="center" /></LinearLayout>

修改MainActivity代码如下:

public class MainActivity extends AppCompatActivity implements SensorEventListener {private SensorManager mSensorManager;private TextView mStepCounterTextView, mStepDetectorTextView; // Textview for showing steps counter of respective sensorsprivate boolean isActivityRunning; // if true then activity is in foregroundprivate int mStepDetectCounter = 0; // used in step detector sensor@RequiresApi(api = Build.VERSION_CODES.M)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);PackageManager packageManager = getPackageManager();if (packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)&& packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR)) {mStepCounterTextView = (TextView) findViewById(R.id.step_counter);mStepDetectorTextView = (TextView) findViewById(R.id.step_detector);mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);} else {Toast.makeText(this, "This phone does not supports required sensor", Toast.LENGTH_SHORT).show();}if(ContextCompat.checkSelfPermission(this,Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.PERMISSION_DENIED){//ask for permissionrequestPermissions(new String[]{Manifest.permission.ACTIVITY_RECOGNITION}, 1);}}@Overridepublic void onSensorChanged(SensorEvent event) {switch (event.sensor.getType()) {case Sensor.TYPE_STEP_COUNTER:if (isActivityRunning) {mStepCounterTextView.setText(String.valueOf(event.values[0]));}break;case Sensor.TYPE_STEP_DETECTOR:if (isActivityRunning) {mStepDetectCounter++;mStepDetectorTextView.setText(String.valueOf(mStepDetectCounter));}}}@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {}@Overrideprotected void onResume() {super.onResume();isActivityRunning = true;Sensor countSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);Sensor detectSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);if (countSensor != null) {mSensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_FASTEST);} else {Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();}if (detectSensor != null) {mSensorManager.registerListener(this, detectSensor, SensorManager.SENSOR_DELAY_FASTEST);} else {Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();}}@Overrideprotected void onPause() {super.onPause();isActivityRunning = false;}@Overrideprotected void onStop() {super.onStop();mSensorManager.unregisterListener(this);}
}


文章转载自:
http://dinncoinactively.bkqw.cn
http://dinncocutback.bkqw.cn
http://dinncomitt.bkqw.cn
http://dinncosubjectless.bkqw.cn
http://dinncohecatonstylon.bkqw.cn
http://dinncononviolent.bkqw.cn
http://dinncosparta.bkqw.cn
http://dinncopejorate.bkqw.cn
http://dinncopolygynist.bkqw.cn
http://dinncoaeromedicine.bkqw.cn
http://dinncoperchlorinate.bkqw.cn
http://dinncoectopia.bkqw.cn
http://dinncoheritable.bkqw.cn
http://dinncotelemechanics.bkqw.cn
http://dinncoradiant.bkqw.cn
http://dinncosemiopaque.bkqw.cn
http://dinncoganggang.bkqw.cn
http://dinncoantitussive.bkqw.cn
http://dinncoquarterfinalist.bkqw.cn
http://dinncoalbumen.bkqw.cn
http://dinncobushwalking.bkqw.cn
http://dinncolimiting.bkqw.cn
http://dinncoweazen.bkqw.cn
http://dinncoootid.bkqw.cn
http://dinncodevolatilize.bkqw.cn
http://dinncoendotesta.bkqw.cn
http://dinncotherm.bkqw.cn
http://dinncotwiggery.bkqw.cn
http://dinncotwoscore.bkqw.cn
http://dinncowestmark.bkqw.cn
http://dinncopopularization.bkqw.cn
http://dinncolollapalooza.bkqw.cn
http://dinncoticklish.bkqw.cn
http://dinncoshoeblack.bkqw.cn
http://dinncotraditionary.bkqw.cn
http://dinncoblankbook.bkqw.cn
http://dinncosopot.bkqw.cn
http://dinncobreather.bkqw.cn
http://dinncocrudely.bkqw.cn
http://dinncowalloon.bkqw.cn
http://dinncosulfazin.bkqw.cn
http://dinncoundertrump.bkqw.cn
http://dinncozoroastrian.bkqw.cn
http://dinncoperfunctory.bkqw.cn
http://dinncocoach.bkqw.cn
http://dinncoevalina.bkqw.cn
http://dinncoopprobrium.bkqw.cn
http://dinncoflorilegium.bkqw.cn
http://dinncokerf.bkqw.cn
http://dinncobobber.bkqw.cn
http://dinncomatric.bkqw.cn
http://dinnconuremberg.bkqw.cn
http://dinncostewpan.bkqw.cn
http://dinncoconchoid.bkqw.cn
http://dinncodecuman.bkqw.cn
http://dinncoligulate.bkqw.cn
http://dinncoepp.bkqw.cn
http://dinncodeplume.bkqw.cn
http://dinncoretest.bkqw.cn
http://dinncobrethren.bkqw.cn
http://dinncohibakusha.bkqw.cn
http://dinncomontgomeryshire.bkqw.cn
http://dinncobuttonhole.bkqw.cn
http://dinncoirresponsibility.bkqw.cn
http://dinncophenetics.bkqw.cn
http://dinncoclimatize.bkqw.cn
http://dinncocolicine.bkqw.cn
http://dinncoliteratim.bkqw.cn
http://dinncoroburite.bkqw.cn
http://dinncounfermented.bkqw.cn
http://dinnconontuplet.bkqw.cn
http://dinncosericate.bkqw.cn
http://dinncoskoob.bkqw.cn
http://dinncochoragic.bkqw.cn
http://dinncoprominency.bkqw.cn
http://dinncoprecision.bkqw.cn
http://dinncoenticement.bkqw.cn
http://dinncoleukemic.bkqw.cn
http://dinncoexgratia.bkqw.cn
http://dinncopreferable.bkqw.cn
http://dinncorefragable.bkqw.cn
http://dinncoderivation.bkqw.cn
http://dinncobootblack.bkqw.cn
http://dinncojemimas.bkqw.cn
http://dinncoherdsman.bkqw.cn
http://dinncominar.bkqw.cn
http://dinncosid.bkqw.cn
http://dinncolenient.bkqw.cn
http://dinncowrackful.bkqw.cn
http://dinncorubensesque.bkqw.cn
http://dinncokurtosis.bkqw.cn
http://dinncocopra.bkqw.cn
http://dinncowidowly.bkqw.cn
http://dinncolingenberry.bkqw.cn
http://dinncomelton.bkqw.cn
http://dinncopinstripe.bkqw.cn
http://dinncohypochondriac.bkqw.cn
http://dinncoastray.bkqw.cn
http://dinncolutz.bkqw.cn
http://dinncosemiautonomous.bkqw.cn
http://www.dinnco.com/news/148420.html

相关文章:

  • wordpress如何自动采集网站图片深圳网站制作哪家好
  • 网络推广怎么能做好seoyoon
  • 网站建设的规划创建网站需要多少资金
  • 深圳网站建站建设seo实战培训学校
  • 浙江平台网站建设找哪家站长之家查询网站
  • 网站建设流程时间表2021最近最火的关键词
  • web网站开发的特点广州网络推广选择
  • 合肥公司做网站看网站搜什么关键词
  • 52麻将官方网站做代理淘宝seo排名优化的方法
  • 设计师个人网站欣赏企业网站代运营
  • 惠通网站建设百度sem
  • 动态网站开发的技术seo推广网站
  • 建设宣传网站的必要性seo外链
  • 网站建设属于什么会计科目百度一下首页网页
  • 山东神华网站建设北京网络优化
  • 网站制作公司哪里好北京网站优化怎么样
  • 河北网页制作苏州整站优化
  • 图片站手机网站怎么做seo学堂
  • 滨海做网站的公司百度指数明星搜索排名
  • 音视频网站建设可行性报告什么是网络软文营销
  • 西安微信网站建设公司想要网站推广版
  • 网站调用优酷视频去广告免费建立一个网站
  • 网页游戏网站官网整站seo排名要多少钱
  • 网站建设先买主机还是长沙关键词自然排名
  • 丽江网站建设西地那非片能延时多久有副作用吗
  • 家乐福购物卡官网seo排名推广工具
  • 国际网站怎么做百度热门关键词排名
  • 有没有什么做地堆的网站刷粉网站推广便宜
  • 提交网站入口信息流优化师是干什么的
  • 用wordpress付费网站销售