Change the battery level of android emulator (AVD)

$ adb devices
List of devices attached 
emulator-5554 device
$ telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK
help
Android console command help:

    help|h|?         print a list of commands
    event            simulate hardware events
    geo              Geo-location commands
    gsm              GSM related commands
    cdma             CDMA related commands
    kill             kill the emulator instance
    network          manage network settings
    power            power related commands
    quit|exit        quit control session
    redir            manage port redirections
    sms              SMS related commands
    avd              control virtual device execution
    window           manage emulator window
    qemu             QEMU-specific commands
    sensor           manage emulator sensors

try 'help <command>' for command-specific help
OK
power
allows to change battery and AC power status

available sub-commands:
    display          display battery and charger state
    ac               set AC charging state
    status           set battery status
    present          set battery present state
    health           set battery health state
    capacity         set battery capacity state

KO: missing sub-command
power capacity 77
OK

PHP SoapClient: Function ("hoge") is not a valid method for this service. / SoapServer: Procedure "hoge" not present

SoapClient

$client = new SoapClient("http://www.example.com/soap");
$client->hoge("fuga"); // <-exception occurred!
Exception Message
Function ("hoge") is not a valid method for this service.
but...

SoapServer

Of course, WSDL definitions are correct (Function 'hoge' is added).
$server = new SoapServer("http://www.example.com/soap");
$server->handle(); // <-exception occurred!
Exception Message
Procedure "hoge" not present

set soap.wsdl_cache_enabled to 0.

Add below, Both SoapClient and SoapServer.

SoapClient

ini_set("soap.wsdl_cache_enabled", 0);
$client = new SoapClient("http://www.example.com/soap");
$client->hoge("fuga"); // <-exception occurred!

SoapServer

ini_set("soap.wsdl_cache_enabled", 0);
$server = new SoapServer("http://www.example.com/soap");
$server->handle(); // <-exception occurred!

Intent com.android.camera.action.CROP ActivityNotFoundException

Intent intent = new Intent("com.android.camera.action.CROP");

    /* Not work. ActivityNotFoundException occurs. */
    //intent.setType("image/*");
    //intent.setData(uri);

    intent.setDataAndType(uri, "image/*"); // works!

    startActivityForResult(intent, REQUEST_CODE_IMAGE_CROP);
(マジ?)

日本でも使えますよ?Chromecastの設定用apkを入手する

Googleのスマホ連携用HDMIスティック「Chromecast」が直輸入、ただし…
ただし、現時点ではChromecast用アプリを国内のGoogle Play/iTunesアカウントから入手することができず、使用するのは難しい状態。どちらのアカウントでも「このアプリは日本では利用できない」という旨のメッセージが表示され、端末にアプリを導入することはできなかった。
そう、正規ルートだとChromecast設定用アプリを入手することは出来ない。けど、
■ Chromecastの設定APKは落ちている
こちらでも紹介されてるし、APKの直リンはここ
■ Chromecastマジで(・∀・)イイ!!
2013版のNexus 7をリモコンにしてベットに寝転びながら、YouTubeの登録チャンネルから配信された新しい動画をボケーッと観てる。

Nexus 7 2012とNexus 7 2013を比較

2012(16GBモデル) 2013(16GB/WiFiモデル)
androidバージョン 4.3 4.3
モデル番号 Nexus 7 Nexus 7
カーネルバージョン 3.1.10-g1e8b3d8 3.4.0-g6537a16
ビルド番号 JWR66Y JSS15Q
ディスプレイインチ 7.3 6.8
Density tvdpi(213dpi) xhdpi(320dpi)
解像度(px) 800x1280 1200x1920
解像度(dp) 601.5x962.4 600x960
Size large large
Aspect ratio notlong notlong
おまけ重さ 340g 290g(ちょい軽い!)
厚さ 10.45mm 8.65mm(ちょい薄い!)
バッテリー 4325mAH 3950mAH(え!?)
RAM 1GB 2GB
CPU 1.2GHz
(NVIDIA Tegra 3)
1.5 GHz
(Qualcomm Snapdragon S4 Pro)
お値段(Google Play) ¥19,800 ¥27,800

twitpic "Could not authenticate you (header rejected by twitter)."

twitpic
なんか知らないんだけどtwitpicっていうのを使っているサービスがあって、今更、例のtwitter API 1.1対応みたいなお仕事したんですが、twitpicのAPIを叩くと、
Could not authenticate you (header rejected by twitter).
って言われちゃう。
なのでtwitpicのAPIドキュメントのこれ↓
http://dev.twitpic.com/docs/2/upload/
をみたところ、
X-Verify-Credentials-Authorization (Required)
Header Example
1 OAuth realm="http://api.twitter.com/",
2 oauth_consumer_key="GDdmIQH6jhtmLUypg82g",
3 oauth_signature_method="HMAC-SHA1",
4 oauth_token="819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw",
5 oauth_timestamp="1272325550",
6 oauth_nonce="oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y",
7 oauth_version="1.0",
8 oauth_signature="U1obTfE7Rs9J1kafTGwufLJdspo%3D"  

X-Auth-Service-Provider (Required)
https://api.twitter.com/1/account/verify_credentials.json
って書いてあるんだけど、X-Auth-Service-Providerを
https://api.twitter.com/1.1/account/verify_credentials.json
にするのはもちろん、oauth_signatureを作っているURLも
https://api.twitter.com/1.1/statuses/update.json
とかにする必要があったです。はい。

Apache HBase "Could not reserve enough space for heap offset array"

  1. Run "./bin/hbase shell",
    $ ./bin/hbase shell
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    Error occurred during initialization of VM
    Could not reserve enough space for heap offset array
    
  2. "Could not reserve enough space for heap"?
  3. Edit "./conf/hbase-env.sh",
    $ vi conf/hbase-env.sh
    export _JAVA_OPTIONS='-Xmx256m -Xms64m'
    
    # Extra Java CLASSPATH elements.  Optional.
    # export HBASE_CLASSPATH=
    
    # The maximum amount of heap to use, in MB. Default is 1000.
    export HBASE_HEAPSIZE=128
    

~/.pam_environment

  1. Open "~/.pam_environment",
    LANGUAGE=ja_JP:zh_CN:en
    LANG=ja_JP.UTF-8
    LC_NUMERIC=ja_JP.UTF-8
    LC_TIME=ja_JP.UTF-8
    LC_MONETARY=ja_JP.UTF-8
    LC_PAPER=ja_JP.UTF-8
    LC_NAME=ja_JP.UTF-8
    LC_ADDRESS=ja_JP.UTF-8
    LC_TELEPHONE=ja_JP.UTF-8
    LC_MEASUREMENT=ja_JP.UTF-8
    LC_IDENTIFICATION=ja_JP.UTF-8
  2. wtf? "zh_CN"?
  3. I edited "LANGUAGE" line to,
    LANGUAGE=ja_JP:en
    

Screen freezed at "Checking battery state..." at startup of ubuntu 12.10.

  1. Open "/etc/default/grub" file.
    $ sudo vi /etc/default/grub
    
    Edit "GRUB_CMDLINE_LINUX_DEFAULT" like this,
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash console=tty1"
    
  2. Update grub settings.
    $ sudo update-grub
    
  3. Reboot system.
see also: http://ubuntuforums.org/showthread.php?t=1860674
see also: http://steadyassimilation.blogspot.jp/2012/04/note-ubuntu-1204lts.html

APK Expansion Files

Development environment.
  • Ubuntu 11.10 (Oneiric)
  • JDK 1.6.0_24-b07
  • Eclipse 3.7.3 (Indigo)
    • Android Development Toolkit 17.0.0

Preparing.
  1. Get a publisher account here for Google Play, if you don't have yet.
  2. Download two packages from the SDK Manager.('Google Play APK Expansion Library' and 'Google Play Licensing Library')
    Android SDK Manager
  3. Create two library projects from existing source.
    • <sdk>/extras/google/play_apk_expansion/downloader_library
    • <sdk>/extras/google/play_licensing/library
  4. Create a new project which you want to use APK Expansion Files and add above two library project to your new project's build path.
    Add a reference to a library project

Implementing.
  1. Downloader service.
    // Extends com.google.android.vending.expansion.downloader.impl.DownloaderService class and override three methods.
    public class ExpansionFileDownloaderService extends DownloaderService {
     // the Base64-encoded RSA public key for your publisher account
     private static final String PUBLIC_KEY = "{YOU_PUBLIC_KEY}";
     // Generate 20 random bytes, and put them here.
     private static final byte[] SALT = new byte[] {};
     @Override public String getPublicKey() {
      return PUBLIC_KEY;
     }
     @Override public byte[] getSALT() {
      return SALT;
     }
     @Override public String getAlarmReceiverClassName() {
      return ExpansionFileAlarmReceiver.class.getName();
     }
    }
    
  2. Alarm receiver.
    public class ExpansionFileAlarmReceiver extends BroadcastReceiver {
     @Override public void onReceive(Context context, Intent intent) {
      try {
       DownloaderClientMarshaller.startDownloadServiceIfRequired(
         context, intent, ExpansionFileDownloaderService.class);
      } catch (NameNotFoundException e) {
       Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e);
      }
     }
    }
    
  3. Main activity.
    @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      
      // Check whether the file have been downloaded.
      String mainFileName = Helpers.getExpansionAPKFileName(this, true, 1);
      boolean fileExists = Helpers.doesFileExist(this, mainFileName, 32921796L, false);
      if (!fileExists) {
       Intent launcher = getIntent();
       Intent fromNotification = new Intent(this, getClass());
       fromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
       fromNotification.setAction(launcher.getAction());
       if (launcher.getCategories() != null) {
        for (String cat : launcher.getCategories()) {
         fromNotification.addCategory(cat);
        }
       }
       PendingIntent pendingIntent = PendingIntent.getActivity(
         this, 0, fromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
       try {
        // Start the download
        int result = DownloaderClientMarshaller.startDownloadServiceIfRequired(
          this, pendingIntent, ExpansionFileDownloaderService.class);
        if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {
         // implement Downloading UI.
         return;
        }
       } catch (NameNotFoundException e) {
        Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e);
       }
      }
      // expansion file is available. start your application.
     }
    

Manifest declarations.
  • uses-permission
    <!-- Required to access Android Market Licensing -->
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
    <!-- Required to download files from Android Market -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Required to keep CPU alive while downloading files (NOT to keep screen awake) -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- Required to poll the state of the network connection and respond to changes -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Required to check whether Wi-Fi is enabled -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <!-- Required to read and write the expansion files on shared storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
  • application
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".ExpansionFileDownloaderService" android:label="@string/app_name" />
        <receiver android:name=".ExpansionFileAlarmReceiver" android:label="@string/app_name" />
    </application>
    

Testing APK Expansion Files
  1. Upload the application APK file and Expansion Files using the Google Play Developer Console.
    Uploading APK and Expansion file.
  2. Fill in the necessary application details. Click the Save button. Do not click Publish.
  3. Install the application on your test device and launch the app. Download will start soon.