Created
January 13, 2013 23:40
-
-
Save schoentoon/4526851 to your computer and use it in GitHub Desktop.
Simple documentation for the Mac2Vendor broadcast Interface
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
Documentation for the Mac2Vendor Broadcast interface. | |
Simply send a broadcast with the following requirements: | |
-The action field set to: "com.schoentoon.mac2vendor.LOOKUP_MAC_ADDRESS" | |
-A Bundle with the following field: "com.schoentoon.mac2vendor.MAC_ADDRESS" | |
For this Bundle you can simply use putExtra(String,String), make sure this is JUST the mac address. | |
The listen for broadcasts with the following action "com.schoentoon.mac2vendor.MAC_LOOKUP_RESPONSE" | |
The Bundle of this Intent will have 2 fields | |
-"com.schoentoon.mac2vendor.MAC_ADDRESS" ~ The mac address you supplied, useful when doing multiple lookups at a time. | |
-"com.schoentoon.mac2vendor.VENDOR" ~ The vendor that links to this mac address, this field will be "Unknown" when nothing was found. | |
Note: Be sure to register your broadcast reciever BEFORE you send your lookup broadcast! As it could reply so fast that it won't be caught. | |
This gist will contain a MainActivity.java which is simply an example of how to use this interface, this obviously won't just compile out of the box. Experiment with it yourself a bit. |
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
package com.example.mac2vendortest; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.IntentFilter; | |
import android.widget.TextView; | |
public class MainActivity extends Activity { | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
/* Be sure to register the receiver before you request the mac address */ | |
registerReceiver(receiver, new IntentFilter("com.schoentoon.mac2vendor.MAC_LOOKUP_RESPONSE")); | |
Intent intent = new Intent("com.schoentoon.mac2vendor.LOOKUP_MAC_ADDRESS"); | |
intent.putExtra("com.schoentoon.mac2vendor.MAC_ADDRESS", "<INSERT MAC ADDRESS HERE>"); | |
sendBroadcast(intent); | |
} | |
protected void onDestroy() { | |
super.onDestroy(); | |
unregisterReceiver(receiver); | |
} | |
private BroadcastReceiver receiver = new BroadcastReceiver() { | |
public void onReceive(Context context, Intent intent) { | |
final Bundle bundle = intent.getExtras(); | |
if (bundle != null && bundle.containsKey("com.schoentoon.mac2vendor.MAC_ADDRESS") | |
&& bundle.containsKey("com.schoentoon.mac2vendor.VENDOR")) { | |
TextView txt = (TextView) findViewById(android.R.id.text1); | |
String text = "(" + bundle.getString("com.schoentoon.mac2vendor.MAC_ADDRESS") + ") ~ " + bundle.getString("com.schoentoon.mac2vendor.VENDOR"); | |
txt.setText(text); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment