日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

java – Android NFC設(shè)備所有者配置:發(fā)送自定義屬性.可能嗎?

 印度阿三17 2019-07-27

我正在開發(fā)一個應(yīng)用程序,并有以下問題.

在使用NFC進(jìn)行設(shè)備所有者配置時(shí),我想發(fā)送一個字符串,該字符串將由新設(shè)備所有者應(yīng)用程序使用.

我知道設(shè)備所有者配置的標(biāo)準(zhǔn)MIME屬性,找到了here

這是一個片段,可以讓您更好地了解我的問題.注意“myCustomValue”屬性.

Properties properties = new Properties();
properties.put("myCustomValue", value);
properties.put(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.example.some.app");
try {                    
    properties.store(stream, "NFC Provisioning");            
    ndefMessage = new NdefMessage(new NdefRecord[{NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, stream.toByteArray())});
} catch (IOException e) {                         

}

這個片段在里面

public NdefMessage createNdefMessage(NfcEvent event)

你可以找到一個模板here

如果可能,我也想知道如何在配置的應(yīng)用程序啟動后立即檢索該字符串值.

解決方法:

下面的代碼應(yīng)該是您正在尋找的.為簡潔起見,我只設(shè)置包名稱加上兩個將發(fā)送到DeviceAdminReceiver的字符串.

@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    try {
        Properties p = new Properties();

        p.setProperty(
                DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                "com.example.some.app");

        Properties extras = new Properties();
        extras.setProperty("Key1", "TestString1");
        extras.setProperty("Key2", "TestString2");
        StringWriter sw = new StringWriter();
        try{
            extras.store(sw, "admin extras bundle");
            p.put(DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE,
                    sw.toString());
            Log.d(TAG, "Admin extras bundle="   p.get(
                    DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE));
        } catch (IOException e) {
            Log.e(TAG, "Unable to build admin extras bundle");
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStream out = new ObjectOutputStream(bos);
        p.store(out, "");
        final byte[] bytes = bos.toByteArray();

        NdefMessage msg = new NdefMessage(NdefRecord.createMime(
                DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));
        return msg;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

下一個片段將進(jìn)入您的DeviceAdminReceiver,以便接收“Admin Extras”…如果您不覆蓋onReceive,則需要覆蓋onProfileProvisioningComplete并在其中處理EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE.

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive "   intent.getAction());
    if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(intent.getAction())) {
        PersistableBundle extras = intent.getParcelableExtra(
                EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE);
        Log.d(TAG, "onReceive Extras:"   extras.getString("Key1")   " / "    extras.getString("Key2"));
    }
}
來源:https://www./content-1-360851.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多