近期遇到一个场景,
静态代码块里,无法拿到context,context.getPackageManager只在运行时适用,而静态代码块里无法做到,那么如何拿到PackageManager?
例如:
static {
if(判断条件) {
//执行静态方法;
}
}
从NfcAdapater里边找到了启发。
package android.nfc;
/**
* Represents the local NFC adapter.
* <p>
* Use the helper {@link #getDefaultAdapter(Context)} to get the default NFC
* adapter for this Android device.
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For more information about using NFC, read the
* <a href="{@docRoot}guide/topics/nfc/index.html">Near Field Communication</a> developer guide.</p>
* <p>To perform basic file sharing between devices, read
* <a href="{@docRoot}training/beam-files/index.html">Shari