Добрый день, на самом деле у меня проблемы с моим кодом, когда я обращаюсь к тегу NFC к мобильному телефону, поддерживающему NFC, вместо моего приложения отображается «Службы NFC».
Я пришел к выводу, что это может быть AndroidManifest.xml, но я уже изменил его, чтобы получать события MIME из фильтра намерений, вот код:
app.component.ts
import firebase from 'firebase';
import { Component, ViewChild } from '@angular/core';
import {Keyboard} from '@ionic-native/keyboard';
import { Platform, Nav, App, AlertController} from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { WelcomePage } from '../pages/welcome/welcome';
import { LoginPage } from '../pages/login/login';
import { PpPage } from '../pages/menu/pago/pp/pp';
import { NosotrosPage } from '../pages/menu/nosotros/nosotros';
import { ConfigPage } from '../pages/menu/config/pp/config';
import { SavlistPage } from '../pages/savlist/savlist';
import { AuthService } from '../services/auth';
import { MenuController } from 'ionic-angular';
import { InicioPage } from '../pages/inicio/inicio';
import { Observable } from 'rxjs';
import { AngularFireDatabase } from 'angularfire2/database';
import { Toast } from '@ionic-native/toast';
import { NFC } from '@ionic-native/nfc';
import { window } from 'rxjs/operator/window';
import { Message } from '@angular/compiler/src/i18n/i18n_ast';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav:Nav;
rootPage: any = WelcomePage;
rootPageParams: any;
loginPage: LoginPage;
users: Observable<any>;
usdata: any = "npc";
name: string;
showSplash = true;
isAthenticated = false;
constructor(platform: Platform, statusBar: StatusBar,
splashScreen: SplashScreen,
private menuCtrl: MenuController,
private authService: AuthService,
private af: AngularFireDatabase,
private app: App,
private alrtCtrl: AlertController,
private toast: Toast,
public keyboard: Keyboard,
public nfc: NFC)
{
if (!firebase.apps.length)
{
firebase.initializeApp({
apiKey: "XXXXXX",
authDomain: "XXXXXXXX",
databaseURL: "XXXXXXXX",
projectId: "XXXXXX",
storageBucket: "XXXXXX",
messagingSenderId: "XXXXXXXX"
});
}
firebase.auth().onAuthStateChanged( user => {
if(user)
{
this.isAthenticated = true;
this.rootPage = InicioPage;
this.nfc.addNdefListener().subscribe((data)=>{
console.log(data)
});
this.nfc.addMimeTypeListener('text/plain').subscribe((data)=>{
console.log(data)
});
try
{
this.usdata = firebase.auth().currentUser.email;
}
catch(e)
{
console.log("No ha iniciado sesion");
}
this.users = this.af.object("/users").valueChanges();
this.users.subscribe(data => {
for (let p in data)
{
let value = data[p];
if (value.correo_u == this.usdata)
{
this.name = value.name_u;
}
}
});
}
else
{
this.nfc.addNdefListener().subscribe((data)=>{
let payload = data.tag.ndefMessage[0].payload;
let tagContent = this.nfc.bytesToString(payload).substring(3);
console.log(data)
this.alrtCtrl.create({
message: tagContent,
}).present();
});
this.nfc.addMimeTypeListener('text/plain').subscribe((data)=>{
console.log(data)
this.alrtCtrl.create({
message: data,
}).present();
});
this.isAthenticated = false;
this.rootPage = WelcomePage;
}
});
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
this.keyboard.disableScroll(true);
});
platform.registerBackButtonAction(() => {
// Catches the active view
let nav = app.getActiveNav();
let activeView = nav.getActive();
// Checks if can go back before show up the alert
if (activeView.name == 'InicioPage')
{
platform.exitApp();
}
if (activeView.name == 'WelcomePage')
{
platform.exitApp();
}
if(activeView.name == 'ListsPage')
{
activeView.instance.volver();
}
else
{
activeView.dismiss();
}
});
}
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="XXXXXXXXXX" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" 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/plain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
</provider>
<activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
<meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXXXXXXXXXXXXX" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver" />
</application>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.hardware.location" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> </manifest>
и вот что он показывает:
услуги
Я уже искал из этого источника:
Приложение под названием "NFC services" заменяет мое собственное приложение
Запуск приложения из чтения метки NFC
https://github.com/don/nfc-launch/blob/master/README.md
https://github.com/chariotsolutions/phonegap-nfc/issues/57
Ионный:
ионный (Ionic CLI): 4.10.2
Система:
NodeJS: v10.14.2 npm: 6.7.0 ОС: Linux 4.15
phonegap-nfc 1.0.3 "NFC"
Cordova версия: 8.1.1