【问题标题】:Android NFC Intent not working when app is started as launcher当应用程序作为启动器启动时,Android NFC Intent 不起作用
【发布时间】:2019-03-19 00:38:19
【问题描述】:

我正在开发一个允许用作启动器的应用程序。我们主要使用最近升级到 Android 5.1.1 的三星平板电脑,这似乎改变了我们的应用程序在用作启动器时的行为方式。

问题是Android似乎使用默认的com.android.nfc/.NfcRootActivity系统默认活动而不是我们的应用程序。当应用程序正常启动时它工作正常。这用于在三星部署更新之前工作。

这里是日志截图。

作为启动器启动时(NFC 不工作)

 Line 474: E/NxpNfcJni( 1457): setReconnectState = 0x0
Line 476: D/NativeNfcTag( 1457): Starting background presence check
Line 478: D/NfcDispatcher( 1457): tryStartActivity. Send intent.
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 480: D/PackageManager( 1014): Resolving for NFC Intent { flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) } flag 66688 user 0
Line 482: W/ResourcesManager( 1014): Asset path '/system/framework/com.broadcom.nfc.jar' does not exist or contains no resources.
Line 492: V/WindowManager( 1014): addAppToken: AppWindowToken{11f6a866 token=Token{513b8c1 ActivityRecord{951b5a8 u0 com.android.nfc/.NfcRootActivity t24}}} to stack=1 task=24 at 0
Line 492: V/WindowManager( 1014): addAppToken: AppWindowToken{11f6a866 token=Token{513b8c1 ActivityRecord{951b5a8 u0 com.android.nfc/.NfcRootActivity t24}}} to stack=1 task=24 at 0
Line 498: D/NfcPlugin( 1494): onPause Intent {  }
Line 502: D/NfcPlugin( 1494): stopNfc

当开始正常(工作)

 Line 261: E/NxpNfcJni( 1457): setReconnectState = 0x0
Line 263: D/PersonaManager( 1457): isNFCAllowed
Line 269: D/NativeNfcTag( 1457): Starting background presence check
Line 273: W/ActivityManager( 1014): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x24000000 cmp=com.bstmedia.xxx/yyy.KioskActivity (has extras) }
Line 277: D/NfcPlugin( 1494): onPause Intent {  }
Line 279: D/NfcPlugin( 1494): stopNfc

这是清单文件中的内容。

  <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <data android:mimeType="text/xxx" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>            
    </activity>

    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:keepScreenOn="true" android:label="My App Name" android:launchMode="singleInstance" android:name="yyy.KioskActivity" android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </activity>

【问题讨论】:

    标签: android nfc android-launcher


    【解决方案1】:

    当设备重新启动并且应用程序作为启动器打开时,似乎没有触发前台调度模式。我们没有找到改变这种行为的方法。

    然而,一个快速的解决方法是按下“最近的应用”按钮,然后在应用返回前台后激活 NFC 的前台调度模式。

    我们添加来自https://stackoverflow.com/a/32453115/2616377 的代码,以便在每次重新启动时自动执行此操作。

    我了解这不适用于所有设备或 Android 版本。但我们很高兴朝着这个方向前进,因为无论如何这个问题都是特定于特定三星更新的。

    【讨论】:

      【解决方案2】:

      您在使用 Cordova Kiosk 插件吗?

      我已经用 BOOT_COMPLETE BroadcastReceiver 完成了:

      public class BootReceiver extends BroadcastReceiver {
      
          @Override
          public void onReceive(Context context, Intent intent) {
      
              final Context myContext = context;
      
              Timer timer = new Timer();
              timer.schedule(new TimerTask(){
                  public void run() {
                      KioskActivity.closeActivity(); //closeActivity() runs finish(); in KioskActivity
                  }
              }, 10000);     
      
          }
      }
      

      然后在 KioskActivity 的 onPause 中添加: //KioskActivity.java

      ActivityManager activityManager = (ActivityManager) getApplicationContext()
                          .getSystemService(Context.ACTIVITY_SERVICE);
      activityManager.moveTaskToFront(getTaskId(), 0);
      

      *记得在AndroidManifest.xml中注册BOOT_COMPLETED接收器

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-20
        • 2020-08-08
        • 1970-01-01
        • 2012-08-09
        • 1970-01-01
        • 2018-07-18
        相关资源
        最近更新 更多