App called “NFC services” replacing my own app

自闭症网瘾萝莉.ら 提交于 2020-01-25 23:43:30

问题


I want my Android app to start after scanning an NFC tag, so to make some tests I modified the tiapp.xml of Favebooks (a simple tutorial app for Titanium) by adding the following lines:

<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
    <uses-permission android:name="android.permission.NFC"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-sdk android:minSdkVersion="14"/>
    <uses-feature android:name="android.hardware.nfc" android:required="true"/>
    <application android:theme="@style/Theme.Titanium">
        <activity
        android:configChanges="keyboardHidden|orientation"
        android:label="Favebooks"
        android:launchMode="singleTop"
        android:name=".FavebooksActivity" android:screenOrientation="portrait">
            <intent-filter>
                <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:host="test.it" android:scheme="https"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
</android>

Unfortunately, another APP called "Nfc service", which looks exactly like Favebooks, starts instead of it after scanning a tag. I have tried every launchMode available to no avail. What am I doing wrong? Here's a screenshot.

EDIT

For simplicity's sake, let's put this in index.js.

Ti.API.info('Launch Intent ' + Ti.App.Android.launchIntent.getData());

var win = Ti.UI.createWindow({
    layout : 'vertical',
    height : 'auto'
});

var text = Ti.UI.createTextField({
    name : 'test',
    hintText : 'test'
});
win.add(text);

win.open();

Now let's try start the app by approaching our device to a tag. It does so correctly:

[INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.Test.app.TestActivity@42a0df48 [INFO] : Launch Intent https://test.com

Bit if we press the home button, click on the app icon and go check our logs we can see than the activity id of what just started is different. So for example anything that we had written in the text field got lost. I don't want this to happen.

[INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null [INFO] : Launch Intent null [INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.Test.app.TestActivity@42cb8370


回答1:


I think the answer to your question would be to replace this line of code android:launchMode="singleTop" by this one: android:launchMode="singleTask".

I posted an answer to the same question here.

Hope this helps!




回答2:


What you see is actually your app. Your app being displayed as "Nfc Service" (possily with a different icon) in the recent apps history seems to be a bug(?) in Android (or certain Android versions???).

Also see this question: When reading a NDEF tag the content it's showed in “NFC service” instead of the app.




回答3:


I had a similar problem and I have understood that the cause was android:name=".FavebooksActivity", if I deleted the name of activity, there was not a replacing of the app. I hope this can help you.



来源:https://stackoverflow.com/questions/28938074/app-called-nfc-services-replacing-my-own-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!