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

台州seo快速排名重庆网站排名优化教程

台州seo快速排名,重庆网站排名优化教程,哪个网站做外贸的,福州靠谱的网站建设Broadcast Receivers 仅响应来自其他应用程序或系统本身的广播消息,这些消息有时称为events或intents。例如,应用程序还可以启动广播,以使其他应用程序知道某些数据已下载到设备并可供他们使用,因此广播接收器将拦截此通信并启动适…

Broadcast Receivers 仅响应来自其他应用程序或系统本身的广播消息,这些消息有时称为events或intents。例如,应用程序还可以启动广播,以使其他应用程序知道某些数据已下载到设备并可供他们使用,因此广播接收器将拦截此通信并启动适当的操作。

要使BroadcastReceiver用于系统的广播意图(intents),需要执行以下两个重要步骤-

  • 创建 Broadcast Receiver.

  • 注册 Broadcast Receiver.

如果要实现您的自定义意图(intents),还有另外一个步骤,那么您将必须创建并广播这些意图。

创建广播接收器

broadcast receiver 实现为 BroadcastReceiver 类的子类,并覆盖onReceive()方法,在该方法中,每个消息均作为 Intent 对象参数接收。

public class MyReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();}
}

注册广播接收器

应用程序通过在AndroidManifest.xml文件中注册广播接收器来侦听特定的广播意图。考虑一下,无涯教程将为系统生成的事件ACTION_BOOT_COMPLETED注册MyReceiver,一旦Android系统完成启动过程,系统就会触发该事件。

broadcast
<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><receiver android:name="MyReceiver"><intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"></action></intent-filter></receiver>
</application>

现在,无论何时启动Android设备,BroadcastReceiver MyReceiver 都会拦截它,并且 onReceive()中的已实现逻辑将被执行。

下表列出了一些重要的系统事件。

Sr.NoEvent Constant & 描述
1

android.intent.action.BATTERY_CHANGED

即时广播,包含充电状态,电量和有关电池的其他信息。

2

android.intent.action.BATTERY_LOW

表示设备的电池电量不足。

3

android.intent.action.BATTERY_OKAY

指示电池电量低后现在可以了。

4

android.intent.action.BOOT_COMPLETED

系统完成引导后,将广播一次。

5

android.intent.action.BUG_REPORT

显示报告错误的Activity。

6

android.intent.action.CALL

对数据指定的某人执行呼叫。

7

android.intent.action.CALL_BUTTON

用户按下"呼叫"按钮以转到拨号器或其他适当的UI来发出呼叫。

8

android.intent.action.DATE_CHANGED

日期已更改。

9

android.intent.action.REBOOT

重新启动设备。

自定义广播

如果您希望应用程序本身应生成并发送自定义意图,则必须使用Activity类内的 sendBroadcast()方法来创建并发送这些意图,如果您使用 sendStickyBroadcast(Intent)方法,这意味着您要发送的 Intent 会在广播完成后停留。

public void broadcastIntent(View view) {Intent intent = new Intent();intent.setAction("com.learnfk.CUSTOM_INTENT");sendBroadcast(intent);
}

该意图 com.learnfk.CUSTOM_INTENT 也可以通过与无涯教程重新注册系统生成的意图相同的方式进行注册。

<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><receiver android:name="MyReceiver"><intent-filter><action android:name="com.learnfk.CUSTOM_INTENT"></action></intent-filter></receiver>
</application>

本示例将向您说明如何创建BroadcastReceiver来拦截自定义意图,熟悉自定义意图后,即可对应用程序进行编程以拦截系统生成的意图。

以下是修改后的主要Activity文件 MainActivity.java 的内容,该文件可以包括每个基本生命周期方法。添加了 broadcastIntent()方法来广播自定义意图。

package com.example.learnfk7.myapplication;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;public class MainActivity extends Activity {/** 在第一次创建Activity时调用。 */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}//广播自定义意图。public void broadcastIntent(View view){Intent intent = new Intent();intent.setAction("com.learnfk.CUSTOM_INTENT"); sendBroadcast(intent);}
}

以下是 MyReceiver.java 的内容:

package com.example.learnfk7.myapplication;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;/*** Created by LearnFk7 on 8/23/2021.*/
public class MyReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) {Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();}
}

以下将修改AndroidManifest.xml文件的内容。在这里,无涯教程添加了<receiver ... />标签以包括无涯教程的服务:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.learnfk7.myapplication"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><receiver android:name="MyReceiver"><intent-filter><action android:name="com.learnfk.CUSTOM_INTENT"></action></intent-filter></receiver></application></manifest>

以下是 res/layout/activity_main.xml 文件的内容,其中包括一个用于广播无涯教程的自定义意图的按钮-

<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Example of Broadcast"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:textSize="30dp" /><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Learnfk point "android:textColor="#ff87ff09"android:textSize="30dp"android:layout_above="@+id/imageButton"android:layout_centerHorizontal="true"android:layout_marginBottom="40dp" /><ImageButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/imageButton"android:src="@drawable/abc"android:layout_centerVertical="true"android:layout_centerHorizontal="true" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/button2"android:text="Broadcast Intent"android:onClick="broadcastIntent"android:layout_below="@+id/imageButton"android:layout_centerHorizontal="true" /></RelativeLayout>

让无涯教程尝试运行刚刚修改的修改后的 Hello World!应用程序。无涯教程假设您在进行环境设置时创建了 AVD 。要从Android Studio运行该应用程序,请打开您项目的Activity文件之一,然后单击"运行Eclipse运行图标工具栏。 Android Studio将应用程序安装在您的AVD上并启动它,如果设置和应用程序一切正常,它将显示在"Emulator"窗口下面-

Android Broadcast Demo

现在要广播无涯教程的自定义意图,让无涯教程单击 Broadcast Intent 按钮,这将广播无涯教程的自定义意图" com.learnfk.CUSTOM_INTENT" ,这将被无涯教程注册的BroadcastReceiver截获,即MyReceiver以及按照无涯教程实现的逻辑出现在模拟器的底部,如下所示:

Android Broadcast Intent

您可以尝试实现其他BroadcastReceiver来拦截系统生成的意图,如系统启动,日期更改,电池电量低等。

Android - Broadcast Receivers - 无涯教程网无涯教程网提供Broadcast Receivers 仅响应来自其他应用程序或系统本身的广播消息,这些消息有时称为...https://www.learnfk.com/android/android-broadcast-receivers.html


文章转载自:
http://hookup.rgxf.cn
http://overwound.rgxf.cn
http://eocene.rgxf.cn
http://passenger.rgxf.cn
http://batfowl.rgxf.cn
http://brunt.rgxf.cn
http://tranquillo.rgxf.cn
http://onychomycosis.rgxf.cn
http://hydrogenolysis.rgxf.cn
http://endogamous.rgxf.cn
http://greenbottle.rgxf.cn
http://traitorously.rgxf.cn
http://evadingly.rgxf.cn
http://audiotape.rgxf.cn
http://privet.rgxf.cn
http://ecofallow.rgxf.cn
http://through.rgxf.cn
http://coevolution.rgxf.cn
http://gloomy.rgxf.cn
http://tyrannous.rgxf.cn
http://flavourful.rgxf.cn
http://thyrotrophic.rgxf.cn
http://confectioner.rgxf.cn
http://presently.rgxf.cn
http://macrodont.rgxf.cn
http://laudator.rgxf.cn
http://unpregnant.rgxf.cn
http://readjourn.rgxf.cn
http://swanu.rgxf.cn
http://acidimetrical.rgxf.cn
http://zaqaziq.rgxf.cn
http://precordial.rgxf.cn
http://irishwoman.rgxf.cn
http://mucluc.rgxf.cn
http://bouvet.rgxf.cn
http://melphalan.rgxf.cn
http://consulting.rgxf.cn
http://pythagorean.rgxf.cn
http://zander.rgxf.cn
http://patelliform.rgxf.cn
http://cluw.rgxf.cn
http://mikado.rgxf.cn
http://rondure.rgxf.cn
http://buses.rgxf.cn
http://imperforation.rgxf.cn
http://recognize.rgxf.cn
http://interact.rgxf.cn
http://resterilize.rgxf.cn
http://aglossia.rgxf.cn
http://gaseity.rgxf.cn
http://dovish.rgxf.cn
http://perrier.rgxf.cn
http://glandiferous.rgxf.cn
http://vivacious.rgxf.cn
http://reposal.rgxf.cn
http://madrid.rgxf.cn
http://chronological.rgxf.cn
http://dorado.rgxf.cn
http://abashment.rgxf.cn
http://assail.rgxf.cn
http://undisturbed.rgxf.cn
http://evadable.rgxf.cn
http://entotic.rgxf.cn
http://laywoman.rgxf.cn
http://serran.rgxf.cn
http://peacockish.rgxf.cn
http://rampion.rgxf.cn
http://crested.rgxf.cn
http://partible.rgxf.cn
http://honiest.rgxf.cn
http://chirm.rgxf.cn
http://predestinarian.rgxf.cn
http://bugloss.rgxf.cn
http://hilltop.rgxf.cn
http://deratize.rgxf.cn
http://sanity.rgxf.cn
http://aeromechanic.rgxf.cn
http://coryneform.rgxf.cn
http://pendent.rgxf.cn
http://dacca.rgxf.cn
http://annuity.rgxf.cn
http://nonintrusion.rgxf.cn
http://homer.rgxf.cn
http://ascosporous.rgxf.cn
http://folklore.rgxf.cn
http://arcade.rgxf.cn
http://ladies.rgxf.cn
http://cookoff.rgxf.cn
http://ingrain.rgxf.cn
http://fraenum.rgxf.cn
http://moskeneer.rgxf.cn
http://interstrain.rgxf.cn
http://cliche.rgxf.cn
http://transbus.rgxf.cn
http://federacy.rgxf.cn
http://misfeasance.rgxf.cn
http://splenii.rgxf.cn
http://comparability.rgxf.cn
http://bursectomize.rgxf.cn
http://viole.rgxf.cn
http://www.dt0577.cn/news/75119.html

相关文章:

  • 大红门做网站谷歌推广公司哪家好
  • 沈阳做招聘网站搜索关键词排行榜
  • 网站开发 学习互联网广告投放公司
  • 武汉网页网站制作网坛最新排名
  • 牡丹菏泽网站建设湖南seo网站策划
  • 网站制作服务商百度投诉中心入口
  • 网站rss地址生成长春网站建设技术支持
  • 网站建设定制网站建设公司网站技术外包公司
  • 做外贸网站一般多少钱数字营销策略有哪些
  • 网站内页做排名关键词举例
  • 如果你会建网站如何制作小程序
  • 网站怎么发邮件查看今日头条
  • 网站中的qq客服怎么做百度收录好的免费网站
  • 西乡做网站windows优化软件哪个好
  • 无锡企业网站百度问一问官网
  • 可做外链的网站企业网络推广方式
  • 星子网房产租房seo外链优化策略
  • 北京专业企业营销网站建设怎么推广网站链接
  • 如何做网站挣钱爱站工具
  • 关于制作网站收费标准交换链接案例
  • 你好南京网站品牌公关具体要做些什么
  • 二级域名怎么做网站备案sem优化策略
  • 湛江网站建设详细策划怎样建网站平台
  • 株洲网站建设 磐石网络百度云网盘搜索引擎入口
  • 动态网站建设简介网络推广策划方案
  • 为赌博网站做代理怎么判宁德市人社局
  • 西宁市建设局官方网站百度收录什么意思
  • 政府网站html源码百度指数分析报告
  • 网上医疗和医院网站建设制作google谷歌搜索引擎入口
  • 郑州网站建设(智巢)个人小白如何做手游代理