乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

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

       印度阿三17 2019-07-27

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

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

      我知道設備所有者配置的標準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

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

      解決方法:

      下面的代碼應該是您正在尋找的.為簡潔起見,我只設置包名稱加上兩個將發(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);
          }
      }
      

      下一個片段將進入您的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)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多