Skip to content

Instantly share code, notes, and snippets.

@schoentoon
Created January 13, 2013 23:40
Show Gist options
  • Select an option

  • Save schoentoon/4526851 to your computer and use it in GitHub Desktop.

Select an option

Save schoentoon/4526851 to your computer and use it in GitHub Desktop.

Revisions

  1. schoentoon created this gist Jan 13, 2013.
    38 changes: 38 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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);
    }
    }
    };
    }
    15 changes: 15 additions & 0 deletions README
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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.