Created
February 24, 2014 00:57
-
-
Save six519/9179845 to your computer and use it in GitHub Desktop.
Using your Android device as a remote control (Sample Android Activity)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* By: Ferdinand E. Silva | |
* Tested From: Galaxy Tab 3 10.1 (jelly bean)" | |
* Tested To: Old Panasonic TV | |
****/ | |
package com.example.irtest; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.view.Menu; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.Toast; | |
public class MainActivity extends Activity { | |
public static final String PANASONIC_POWER = "38000,130,65,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,47,17,47,17,47,17,47,17,15,17,15,17,47,17,15,17,47,17,47,17,15,17,47,17,15,17,47,17,2779,130,65,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,15,17,47,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,15,17,47,17,15,17,47,17,47,17,47,17,47,17,15,17,15,17,47,17,15,17,47,17,47,17,15,17,47,17,15,17,47,17,5560"; | |
public static final String PANASONIC_MUTE = "36873,1,1,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,48,16,4719"; | |
public static final String PANASONIC_CHANNEL_DOWN = "38000,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,4719"; | |
public static final String PANASONIC_CHANNEL_UP = "38000,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,4719"; | |
public static final String PANASONIC_VOLUME_UP = "38000,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,4705"; | |
public static final String PANASONIC_VOLUME_DOWN = "38000,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,4705"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Button btnPower = (Button) findViewById(R.id.btPower); | |
Button btnMute = (Button) findViewById(R.id.btnMute); | |
Button btnChDown = (Button) findViewById(R.id.btnChDown); | |
Button btnChUp = (Button) findViewById(R.id.btnChUp); | |
Button btnVolDown = (Button) findViewById(R.id.btnVolDown); | |
Button btnVolUp = (Button) findViewById(R.id.btnVolUp); | |
btnPower.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_POWER); | |
} | |
}); | |
btnMute.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_MUTE); | |
} | |
}); | |
btnChDown.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_CHANNEL_DOWN); | |
} | |
}); | |
btnChUp.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_CHANNEL_UP); | |
} | |
}); | |
btnVolDown.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_VOLUME_DOWN); | |
} | |
}); | |
btnVolUp.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
irCommand(MainActivity.PANASONIC_VOLUME_UP); | |
} | |
}); | |
} | |
@Override | |
public 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; | |
} | |
public void irCommand(String cmd) { | |
Object irObject; | |
irObject = getSystemService("irda"); | |
try { | |
irObject.getClass().getMethod("write_irsend", new Class[] { String.class }).invoke(irObject, new Object[] { cmd }); | |
}catch(Exception e) { | |
Toast.makeText(getApplicationContext(), "Error sending IR command!", Toast.LENGTH_LONG).show(); | |
} | |
} | |
} |
Here the code to convert HexString to IntString
public static String convertProntoHexStringToIntString(String s) {
String[] codes = s.split(" ");
StringBuilder sb = new StringBuilder();
sb.append(getFrequency(codes[1]) + ",");
for (int i = 4; i < codes.length; i++) {
sb.append(Integer.parseInt(codes[i], 16) + ",");
}
return sb.toString();
}
public static String getFrequency(String s) {
int val = Integer.parseInt(s, 16);
Integer i = (int) (1000000 / (val * .241246));
return i.toString();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Ferdinand,
I'm trying to create my own remote control for XBOX 360 console.
I saw your code and is very easy to understand but I a have question I hope you can answer it.
I notice that variables like PANASONIC POWER and the other ones are integers separated by comma but when you search for a code on remotecentral.com it comes in other notation/format like this:
DIGIT 0 (T=0)
Device Code: 116.15 Function: 0 (T=0)
0000 0073 0000 0022 0060 0020 0010
So my question is, how did you perform the conversion?
Hope you can help me!
Thanks in advice