Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
For andriod SDK 12 i have installed Visual Studio Community 2022 (64-bit) - Preview Version 17.4.0 Preview 1.0 and installed Andriod sdk 12 successfully after update andriod os 12 Fcm device token not generating when install the app. The below code im using for FCM device token.
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public string NewToken;
public override void OnTokenRefresh()
{
NewToken = FirebaseInstanceId.Instance.Token;
Xamarin.Forms.Application.Current.Properties["SaveNewToken"] = NewToken;
Xamarin.Forms.Application.Current.SavePropertiesAsync();
// SendRegistrationToServer(NewToken);
}
}
//Hit when Message received only when app is in foreground
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
private string DataTitle;
private string DataBody;
public MyFirebaseMessagingService()
{
}
public override void OnMessageReceived(RemoteMessage Message)
{
base.OnMessageReceived(Message);
object obj1 = Message.Data.TryGetValue("title", out DataTitle);
object obj2 = Message.Data.TryGetValue("body", out DataBody);
new NotificationHelper().CreateNotification(DataTitle, DataBody);
}
}
And Andriodmanifest.xml
android:installLocation="preferExternal"
package="com.edmatix.parent.shemida"
android:versionName="production.release.1.0.0.0"
android:versionCode="20220818">
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="SHEMIDA INTERNATIONAL SCHOOL" android:requestLegacyExternalStorage="true" android:preserveLegacyExternalStorage="true" android:icon="@drawable/SHEMIDA_Launcher" android:networkSecurityConfig="@xml/network_security_config">
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyAnvG581Y_oVWbDcwYNDy6v4CfRdtmU2CY" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<service android:name="com.microsoft.appcenter.push.TokenService" android:exported="false"/>
<service android:name="crc6494e14b9856016c30.PNFirebaseIIDService" android:exported="true" />
<service android:name="crc6494e14b9856016c30.PNFirebaseMessagingService" android:exported="true" />
<receiver android:name="crc64a93b901f58a35d0f.PushReceiver" android:exported="true"/>
<service android:name="crc646c47bac7b09c0b0e.MyFirebaseIIDService" android:exported="true" />
<service android:name="crc646c47bac7b09c0b0e.MyFirebaseMessagingService" android:exported="true"/>
<service android:enabled="true" android:name=".MyFirebaseIIDService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
</manifest>
Added all the services. Kindly help on this