AndroidのBroadcastReceiverでNotificationManagerを作る

一日三回もブログ更新してんだから暇だよね。
ActivityとかServiceからgetSystemServiceできんだけど
インテントレシーバーからは出来ないので、Service作るかと思っていたんだけど、出来たので覚書

public void onReceive(Context ctx, Intent intent) {
    Bundle extras = intent.getExtras();
    //バイブレーション
    Vibrator vibrator =
    (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = {3000, 1000, 2000, 5000, 3000, 1000}; // OFF/ON/OFF/ON...
    vibrator.vibrate(pattern, -1);
    //ノティフィケーションマネージャの取得
    NotificationManager nm=
    (NotificationManager)ctx.getSystemService(
    Context.NOTIFICATION_SERVICE);
}

まぁ当たり前だろって言われたらそうだけど、そうだよね。
いやーそうか?このContextにはなに入ってんだろうね。ルートの画面みたいなもんかね、AndroidのContextって解かんね、不思議だね。調べる気は起きないなあ
でもまあこれで出来たら、アラームとかも出来るし、サービスとかいらねーんじゃねーのって思ったんだけど、あれだわな、中断が出来ないから、そこはデメリット。それよりなによりノティフィケーションマネージャは動かしてないから知らない。
こけなかったよレベル

AndroidでProperties

  public static void writeProperties(Context context,HashMap map ,String fileName)
    throws Exception {
    OutputStream out=null;
    Properties properties = new Properties();
    try{
     out=context.openFileOutput(
        fileName,Context.MODE_WORLD_READABLE);
      Set keys = map.keySet();  
      for (Iterator i = keys.iterator(); i.hasNext();) {
        String key = (String) i.next();
        String value = (String) map.get(key);
        properties.setProperty(key, value);
      }
      properties.setProperty("aa", "bb");
      properties.store(out, "test");
    } catch (Exception e) {
      try {
        if (out!=null) out.close();
      } catch (Exception e2) {
      }
      throw e;
    }
    
  }

とまあ、こんなんを作ってみたんだけど、
1.properties
2.properties
と作って、エミュレーター落として
再起動すると……
2.propertiesが0バイトになってる……
なんでだ?
あと、Propertiesのインスタンスがめちゃくちゃ重い
Propertiesは使うべきじゃないのかな

っと、思いきや

      properties.store(out, "test");
      out.close();

で、いけた。重いのは相変わらずだけど
finallyでcloseしたら駄目だったんだけど、なにだろうなー
エミュレーターが不安定なのかな

Androidでバイブ!

早速エラーが出た

java.lang.RuntimeException: Unable to start activity ComponentInfo{test/test.activity.XXXX: java.lang.SecurityException: Requires VIBRATE permission

AndroidManifest.xmlを見る

あるじゃねーか!
もっかいやってやっぱ駄目。死ね!!!!!!!!!!

んで解決
肝はタグの外に

これ入れる。エラー出なくなった
でもエミュレーターじゃバイブ動いているのか解からない
死ね!!