当应用程序作为启动器启动时,Android NFC Intent无法正常工作

问题描述 投票:3回答:2

我正在开发一个允许用作Launcher的应用程序。我们主要使用最近收到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
2个回答
2
投票

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

然而,快速修复是按下“最近的应用程序”按钮,而不是在应用程序返回前台后激活NFC的forground dispatch模式。

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

我知道这不适用于每个设备或Android版本。但是我们很高兴能够朝着这个方向前进,因为问题特别针对特定的三星更新。


0
投票

你在使用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接收器

© www.soinside.com 2019 - 2024. All rights reserved.