问题现象:在老外网站上找到的,生成的APP,运行后,取服务就报错。不知哪位大神可以帮助看一下代码出错在哪里呀。跪求!
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 FMX.Controls.Presentation, FMX.StdCtrls, 9 Androidapi.Helpers,//需要引入 10 AndroidAPI.jni.OS,//需要引入 11 Androidapi.JNIBridge, // 12 Androidapi.JNI.GraphicsContentViewText, 13 Androidapi.JNI.JavaTypes, 14 FMX.Helpers.Android; // 15 16 type 17 TForm1 = class(TForm) 18 Button1: TButton; 19 procedure Button1Click(Sender: TObject); 20 private 21 { Private declarations } 22 public 23 { Public declarations } 24 end; 25 type 26 JConsumerIrManager_CarrierFrequencyRange = interface; 27 28 JConsumerIrManager_CarrierFrequencyRangeClass = interface(JObjectClass) 29 [‘{191A7F08-B93B-40D4-9B6E-3D908B37578E}‘] 30 {class} function init(min, max: Integer): JConsumerIrManager_CarrierFrequencyRange; cdecl; 31 end; 32 33 [JavaSignature(‘android/hardware/ConsumerIrManager$CarrierFrequencyRange‘)] 34 JConsumerIrManager_CarrierFrequencyRange = interface(JObject) 35 [‘{5AC0C73D-9DA2-49B0-A072-55EA03FE3B78}‘] 36 function getMaxFrequency: Integer; cdecl; 37 function getMinFrequency: Integer; cdecl; 38 end; 39 TJConsumerIrManager_CarrierFrequencyRange = class(TJavaGenericImport<JConsumerIrManager_CarrierFrequencyRangeClass, JConsumerIrManager_CarrierFrequencyRange>) end; 40 41 JConsumerIrManagerClass = interface(JObjectClass) 42 [‘{C8AB7EEA-046F-429C-8585-EF69EBB53718}‘] 43 end; 44 45 [JavaSignature(‘android/hardware/ConsumerIrManager‘)] 46 JConsumerIrManager = interface(JObject) 47 [‘{FF469731-5B57-46AB-9C83-4FB51CA6F2BA}‘] 48 function getCarrierFrequencies: TJavaArray<JConsumerIrManager_CarrierFrequencyRange>; cdecl; 49 function hasIrEmitter: Boolean; cdecl; 50 procedure transmit(carrierFrequency: Integer; pattern: TJavaArray<Integer>); cdecl; 51 end; 52 TJConsumerIrManager = class(TJavaGenericImport<JConsumerIrManagerClass, JConsumerIrManager>) end; 53 54 55 var 56 Form1: TForm1; 57 58 implementation 59 60 {$R *.fmx} 61 function MakeJavaIntArray(arr: array of Integer): TJavaArray<Integer>; 62 var 63 I: Integer; 64 begin 65 Result := TJavaArray<Integer>.Create(Length(arr)); 66 for I := Low(arr) to High(arr) do 67 Result.Items[I] := arr[I]; 68 end; 69 70 71 procedure TForm1.Button1Click(Sender: TObject); 72 var 73 mCIR: JConsumerIrManager; 74 mRanges: TJavaArray<JConsumerIrManager_CarrierFrequencyRange>; 75 mRange: JConsumerIrManager_CarrierFrequencyRange; 76 I, DesiredFrequency: Integer; 77 HasDesiredFrequency: Boolean; 78 begin 79 mCIR := TJConsumerIrManager.Wrap((SharedActivityContext.getSystemService(TJContext.JavaClass.CONSUMER_IR_SERVICE) 80 as ILocalObject).GetObjectID); 81 if mCIR.hasIrEmitter then 82 begin 83 // use mCIR as needed... 84 85 DesiredFrequency := 3800; 86 HasDesiredFrequency := False; 87 88 mRanges := mCIR.getCarrierFrequencies; 89 for I := 0 to mRanges.Length-1 do 90 begin 91 mRange := mRanges.Items[I]; 92 if (DesiredFrequency >= mRange.getMinFrequency) and (DesiredFrequency <= mRange.getMaxFrequency) then 93 begin 94 HasDesiredFrequency := True; 95 Break; 96 end; 97 end; 98 99 if HasDesiredFrequency then 100 mCIR.transmit(DesiredFrequency, MakeJavaIntArray([8950,4350,650,500,600,500,550,600,550,550,600,500,550,550,600,550,600,500,550,1650,600,1600,650,1600,550,1700,600,1600,600,1600,600,1650,600,1600,650,1600,550,1650,650,1600,600,550,550,550,550,550,550,550,600,500,600,550,550,550,550,550,550,1650,650,1600,600,1600,600,1650,600,1600,600])); //pattern values here 101 end; 102 end; 103 104 end.
原文:http://www.cnblogs.com/FKdelphi/p/7248301.html