免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

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

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

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

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

這是一個(gè)片段,可以讓您更好地了解我的問(wèn)題.注意“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) {                         }

這個(gè)片段在里面

public NdefMessage createNdefMessage(NfcEvent event)

你可以找到一個(gè)模板here

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

解決方法:

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

@Overridepublic 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);    }}

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

@Overridepublic 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"));    }}
來(lái)源:https://www.icode9.com/content-1-360851.html
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android Device Administration 設(shè)備管理器——實(shí)現(xiàn)一鍵鎖屏
NFC之demo
Android AppWidget 開(kāi)發(fā)中PendingIntent傳送數(shù)據(jù)丟失解決辦法
Android下NFC的簡(jiǎn)單使用
jsp:fmt
Android中NFC功能流程圖解析及代碼演示
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服