捕获Home键
来源:互联网 发布:js获取整数的最大数值 编辑:程序博客网 时间:2024/05/16 23:42
<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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="捕获到Home健,跳转到此界面" /></RelativeLayout>
<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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /></RelativeLayout>
package com.example.homedemo;import android.app.Service;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.content.SharedPreferences.Editor;import android.os.IBinder;import android.widget.Toast;public class HomeService extends Service{private HomeReceiver homeReceiver;private Intent newActivity;@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stubreturn null;}@Overridepublic void onCreate() {super.onCreate();homeReceiver = new HomeReceiver();IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);registerReceiver(homeReceiver, homeFilter);}/** * 捕获home键 * @author Administrator * */public class HomeReceiver extends BroadcastReceiver{final String SYSTEM_DIALOG_REASON_KEY = "reason";final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";@Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {Toast.makeText(getApplicationContext(), "捕获到Home键", 0).show();return;}}}}@Overridepublic void onDestroy() {unregisterReceiver(homeReceiver);homeReceiver = null;super.onDestroy();}}
package com.example.homedemo;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Intent intent = new Intent(this,HomeService.class);startService(intent);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.homedemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.homedemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="com.example.homedemo.HomeService"></service> </application></manifest>
0 0
- android 捕获home键
- 捕获Home键!!!!!!!
- home键的捕获
- android捕获home键
- Android捕获home键
- android捕获Home键
- android捕获home键
- 捕获到Home键
- Android 捕获HOME键
- 捕获Home键
- android系统捕获home键
- android 中捕获home键
- 捕获Home键的方法
- android+捕获home键方法
- 捕获Home键的方法
- android+捕获home键方法
- Android中捕获HOME键
- Android 4.0 捕获Home键
- zigbee cc2530环境搭建及程序开发大概流程
- AndroidStudio一个工程内查看多个项目的实现
- python高阶函数
- hibernate的映射配置文件
- js判断输入的数据是否是正整数,包括100.00(100.000)
- 捕获Home键
- 替换a b 的值,不借助过度变量(两值相互替换不借助中间变量)
- ble4.0节省功耗原因
- 机器学习笔记(一)——线性回归算法
- C#委托和事件的困惑
- onvif学习笔记8:最近写的一个ONVIF客户端的心得小结
- Android Studio 修改包名packageName
- UML类图几种关系的总结
- iOS Debug 速查表