相关资料:

http://blog.csdn.net/qq_21752153/article/details/50244717
https://developer.xamarin.com/api/type/Android.Hardware.ConsumerIrManager/

https://forums.embarcadero.com/thread.jspa?messageID=876851

结果:

1.在取出来的支持Hz范围不知道为什么出错,哪位大神了解的,可以指点一下。谢了。

2.注意一定要增加红外线权限。

3.发送的信息最多2秒时间。

实例代码:

 unit Unit1;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls,
Androidapi.Helpers,//需要引入
AndroidAPI.jni.OS,//需要引入
Androidapi.JNIBridge,//需要引入
Androidapi.JNI.GraphicsContentViewText,//需要引入
Androidapi.JNI.JavaTypes,//需要引入
FMX.Helpers.Android;//需要引入 type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; //外国大神写的
type
JConsumerIrManager_CarrierFrequencyRange = interface; JConsumerIrManager_CarrierFrequencyRangeClass = interface(JObjectClass)
['{191A7F08-B93B-40D4-9B6E-3D908B37578E}']
{class} function init(min, max: Integer): JConsumerIrManager_CarrierFrequencyRange; cdecl;
end; [JavaSignature('android/hardware/ConsumerIrManager$CarrierFrequencyRange')]
JConsumerIrManager_CarrierFrequencyRange = interface(JObject)
['{5AC0C73D-9DA2-49B0-A072-55EA03FE3B78}']
function getMaxFrequency: Integer; cdecl;
function getMinFrequency: Integer; cdecl;
end;
TJConsumerIrManager_CarrierFrequencyRange = class(TJavaGenericImport<JConsumerIrManager_CarrierFrequencyRangeClass, JConsumerIrManager_CarrierFrequencyRange>) end; JConsumerIrManagerClass = interface(JObjectClass)
['{C8AB7EEA-046F-429C-8585-EF69EBB53718}']
end; [JavaSignature('android/hardware/ConsumerIrManager')]
JConsumerIrManager = interface(JObject)
['{FF469731-5B57-46AB-9C83-4FB51CA6F2BA}']
function getCarrierFrequencies: TJavaArray<JConsumerIrManager_CarrierFrequencyRange>; cdecl;
function hasIrEmitter: Boolean; cdecl;
procedure transmit(carrierFrequency: Integer; pattern: TJavaArray<Integer>); cdecl;
end;
TJConsumerIrManager = class(TJavaGenericImport<JConsumerIrManagerClass, JConsumerIrManager>) end; var
Form1: TForm1; implementation {$R *.fmx} function MakeJavaIntArray(arr: array of Integer): TJavaArray<Integer>;
var
I: Integer;
begin
Result := TJavaArray<Integer>.Create(Length(arr));
for I := Low(arr) to High(arr) do
Result.Items[I] := arr[I];
end; procedure TForm1.Button1Click(Sender: TObject);
var
mCIR: JConsumerIrManager;
mRanges: TJavaArray<JConsumerIrManager_CarrierFrequencyRange>;
mRange: JConsumerIrManager_CarrierFrequencyRange;
I, DesiredFrequency: Integer;
HasDesiredFrequency: Boolean;
begin
//得到红外服务
mCIR := TJConsumerIrManager.Wrap((SharedActivityContext.getSystemService(TJContext.JavaClass.CONSUMER_IR_SERVICE)
as ILocalObject).GetObjectID);
//查看手机是否支持红外功能
if mCIR.hasIrEmitter then
begin
//根据需要使用红外线
DesiredFrequency := ;//一般的遥控板都是38KHz
HasDesiredFrequency := False;
//mRanges := mCIR.getCarrierFrequencies;//获得支持的Hz范围(不知道为什么我得到一个范围,取里面的值时出错了,我只能注掉)
//for I := 0 to mRanges.Length-1 do
//begin
//mRange := mRanges.Items[I];
//if (DesiredFrequency >= mRange.getMinFrequency) and (DesiredFrequency <= mRange.getMaxFrequency) then
//begin
//HasDesiredFrequency := True;
//Break;
//end;
//end;
//
//if HasDesiredFrequency then
//发送红外信号内容
mCIR.transmit(DesiredFrequency, MakeJavaIntArray([,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,])); //pattern values here
end;
end; end.

实例配置:

 <?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="%package%"
android:versionCode="%versionCode%"
android:versionName="%versionName%"
android:installLocation="%installLocation%"> <!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="%targetSdkVersion%" />
<%uses-permission%>
<uses-feature android:glEsVersion="0x00020000" android:required="True"/>
<application android:persistent="%persistent%"
android:restoreAnyVersion="%restoreAnyVersion%"
android:label="%label%"
android:debuggable="%debuggable%"
android:largeHeap="%largeHeap%"
android:icon="%icon%"
android:theme="%theme%"
android:hardwareAccelerated="%hardwareAccelerated%"> <%application-meta-data%>
<%services%>
<!-- Our activity is a subclass of the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
android:label="%activityLabel%"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:launchMode="singleTask">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="%libNameValue%" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<%activity%>
<%receivers%>
</application>
<uses-permission android:name="android.permission.TRANSMIT_IR" />
<uses-feature android:name="android.hardware.consumerir" android:required="false"/>
</manifest>
<!-- END_INCLUDE(manifest) -->

Android实例-红外线操作(XE10.2+小米5)的更多相关文章

  1. Android实例-设置消息提醒(XE8+小米2)

    相关资料: 1.官网实例:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_the_Notification ...

  2. Android实例-读取设备联系人(XE8+小米2)

    相关资料: http://www.colabug.com/thread-1071065-1-1.html 结果: 1.将权限打开Read contacts设置为True,不然报图一的错误. 2.搜索空 ...

  3. Android实例-OrientationSensor方向传感器(XE8+小米2)

    相关资料: <修复 XE8 for Android 方向传感器 headingX,Y,Z 不会动的问题>:http://www.cnblogs.com/onechen/p/4497282. ...

  4. Android实例-TTabControl的使用(XE8+小米2)

    结果:  1.如果直接改变Tab的TabIndex,那样是没有动态效果的.如果想要动态效果需要用到ChangeTabAction1; 2.ChangeTabAction1可以直接为按钮指定Action ...

  5. Android实例-闪光灯的控制(XE8+小米2)

    unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Var ...

  6. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

  7. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)

    注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...

  8. Android实例-实现扫描二维码并生成二维码(XE8+小米5)

    相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...

  9. 调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

随机推荐

  1. 线代: N阶行列式

    线性变换 将 (x, y) 变成 (2 x + y, x - 3 y) 就叫做线性变换, 这就是矩阵乘法, 用于表示一切线性变换. 几何上看, 把平面上的每个点 (x, y) 都变到 (2 x + y ...

  2. 微信小程序-简易计算器

    代码地址如下:http://www.demodashi.com/demo/14210.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  3. js的7个技巧

    http://www.vaikan.com/seven-javascript-things-i-wish-i-knew-much-earlier-in-my-career/

  4. js getAttribute getAttributeNode

    getAttribute():返回属性值,是一个文本字符串 getAttributeNode("属性名"):返回属性节点,是一个对象 <p id="bj" ...

  5. 编译 boost

    不想深究,只是可以编译出想要的lib文件 1.打开visual studio 2012 命令提示 2.进入 boost目录 3.运行booststrp.bat得到b2.exe.bjam.exe.pro ...

  6. HDUOJ----(2064)汉诺塔III

    汉诺塔III Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. C++知识整理(进制)

    ++输出二进制.十进制.八进制和十六进制总结 分类: C++ 2013-01-14 02:26 592人阅读 评论(0) 收藏 举报 在C++中,默认状态下,数据按十进制输入输出.如果要求按八进制或十 ...

  8. Android开发之模仿UC浏览器的菜单

    这个内容内容涉及到的了两个知识点: PopupWindow:使用PopupWindow创建一个简单的菜单 使用TabHost创建标签:这个网上好多教程随便看看就好. 实现思路: 观察一下UC浏览器的菜 ...

  9. 支持向量机(SVM):应用实例

     SVM 应用实例(人脸识别): from __future__ import print_function from time import time import logging import m ...

  10. docker lnmp php

    使用 Docker 构建 LNMP 环境 https://segmentfault.com/a/1190000008833012 Docker 快速上手指南 https://segmentfault. ...