C2DM / Phonegap plugin? - android

I would like to add Push messaging to my Phonegap Android App and believe that C2DM is the waybest way to make this work - could point me in the right direction to set this up?
Is there a plugin or tutorial to help with this?
Also - do I actually need a plugin - is it possible to add C2dm to my app the traditional Android way without messing up my phonegap setup?

Yes, C2DM is the Android Push solution. On https://github.com/awysocki/C2DM-PhoneGap you can find an example implementation.
The files in the com.google namespace have to be included unchanged, they are from the session "Google IO Session Overview: Android + App Engine: A Developer’s Dream Combination", see http://bradabrams.com/2011/05/google-io-session-overview-android-app-engine-a-developers-dream-combination/
So these are the steps you should perform:
Add the 3 com.google classes to your project
Create a class called C2DMReceiver (naming convention) which inherits from C2DMBaseReceiver and implement the necessary abstract events
Set up the AndroidManifest.xml
The AndroidManifest looks like
<!-- set up an own permission to secure our C2DM mesages -->
<permission android:name="your.namespace.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<!-- List of permission -->
<uses-permission android:name="your.namespace.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application ..>
<!-- Your implementation of the class C2DMReceiver, base class is Googles C2DMBaseReceiver -->
<service android:name=".C2DMReceiver" />
<!-- Googles broadcast receiver, it delegates to your.namespace.C2DMReceiver -->
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="your.namespace" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="your.namespace" />
</intent-filter>
</receiver>
</application>
If you receive on the emulator the error "E/CSE Notifications(401): Registration error ACCOUNT_MISSING", you have to add a Google account to your emulator.
For your second question: it depends what you want to do. When you receive the message and you just want to display a notification so that the user is able to start your app then you don't need a Phonegap plugin. In that case you can solve everything in java.

In case you get to this answer, notice C2DM is absolete and now you have to use GCM.
Moreover there is an official PhoneGap plugin supporting notification for both Android and iPhone. Check out the PushPlugin at https://github.com/phonegap-build/PushPlugin

Related

Firebase dynamic link for not installed application

I have a problem with dynamic link at Firebase not redirecting me to Play Store if the application is not installed.
The dynamic link is defined as following:
The link preview (debug) show following picture:
according to this one if I click on the link and application is not installed I would be brought to Play Store. However it just opens a browser and opens the web link. The "Play Store" link though is functioning and brings me to the Play Store.
One more detail. When I click on the dynamic link on my Android phone I see three steps:
A browser window with "google.com" URL opens shortly.
Browser window is closed and I see original screen where I clicked on the link with a ring rotating for less than a second.
A browser windows opens again but this time with web link opened
And same happens even if the application is installed.
Is there a way to debug this behavior and get some better understanding of what's the reason?
The AndroidManifest.xml is defined as following:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
<application
android:label="myapp"
android:name="${applicationName}"
android:icon="#mipmap/icon">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Deep linking -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="myapp.com" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
As you mentioned it is in debug , i believe here that application is not present on playstore right now and that's why it is not redirecting you to playstore in case of app is not installed on your device but yes , it should open your app if it is already installed on your device
so make sure above scenario .. if flow is working same as mentioned then no worries everything is fine but if it is not working as mentioned then you need to mention code of creating link , manifest file , activity where you are handling it etc ..
So, it turned out my approach to dynamic links building was wrong. Dynamik link creation as shown in the question is a way to establish static links that don't change and have no parameters. It's usable to bring users to a specific part of your application that never changes.
In case of using dynamic link, which is dynamic in its nature like in my case - invitation link that allows to install application if it's not yet installed, run it and bring the user to a specific part of the application with parameters would be:
Define a URL prefix
Publish the application at Play Store at least in closed testing mode. Internal testing seems not to be enough because it's available only by internal testing ID and not the package ID.
Generate URL of type: https://myapp.page.link/?link=https://myapp.com/join/invitation_id&apn=com.myapp
That is enough to make work for Android. For iOS it's not tackled yet.

Android - Google OAuth 2 - twice response with different verifier code

I have an issue with Oauth Google on Android 9 and lower.
Settings :
I develop an application with :
Nativescript 7
Angular 11
nativescript-oauth2:3.0.3 plugin
The problem :
I am not sure the problem is from the nativescript-oauth2 plugin, perhaps my android application configuration or Google Frame.
I develop an OAuth login with Facebook and Google provider.
For Facebook, no problem.
Facebook use a web view browser, and Google use a native view browser.
For Google, see bellow :
on emulator with android 10 : all work fine
on emulator with android 8 or 9 :
it open the browser to login with Google => I choose my account => redirect to a Google Page with Waiting message => it never redirect to my app, and after a moment, it redirect to www.google.com
on real device (android 9) with multiple Google account, I have 2 behaviors :
First : it open the browser to login with Google => I choose my account => redirect to a Google Page with "Waiting" message => redirect to my App with The login operation was canceled error message
Second : it open the browser to login with Google => I wait a moment (per example 1 minute) => I choose my account => redirect to a Google Page with Waiting message => redirect to my App => it work fine
on other real Device with just one account Google (in android settings), it is ok
More details :
I debugged the application and the nativescript-oauth2 plugin.
I saw that the Google Frame with Waiting message (after choose a google account) send 2 events to Android with differents values for the "code" parameter.
Of course the first code is expired/revoked and Google return an error.
In the OAuth Google documentation, this is the Step 4 which send 2 responses with 2 codes.
My question
Why the Google Frame browser send me 2 events ?
Code :
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:launchMode="singleTask"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="#style/LaunchScreenTheme">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="#style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Custom URL Schemes -->
<data android:path="/auth"
android:scheme="com.googleusercontent.apps.xxxxxxxx-yyyyyyyyyyyyyyyyyy"/>
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxxxxxxxxxxxxxxx" />
</application>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

How to enable Firebase after setting "firebase_messaging_auto_init_enabled" to "false" and retrieve a token/push messages

I have a problem receiving any tokens or push notifications with my custom FirebaseMessagingService, after i disabled the auto initialisation of firebase messaging by setting the key firebase_messaging_auto_init_enabled to false in my AndroidManifest.xml.
When not setting the key to false my Service does receive a token.
I mean it is obvious, that i do need to initialise firebase messaging in order to retrieve a token, but all methods i tried did not seems to work.
In order to prevent legal problems i only want to enable firebase/server communication after the user of my Android app did accept the terms of use.
That is why i want to prevent the auto initialisation. After the user did accept the terms of use i want initialise the app and send my retrieved token to my backend.
Methods i already tried:
FirebaseApp.initializeApp(<Context>)
FirebaseMessaging.getInstance().setAutoInitEnabled(true)
I can actually get a token by using the method FirebaseInstanceId.getInstance().getInstance() but i would really prefer to use my FirebaseMessagingService which seems to be the much cleaner way.
Here is some of the code in my AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:usesCleartextTraffic="true">
<meta-data
android:name="firebase_messaging_auto_init_enabled"
android:value="false" />
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<service
android:name="de.itkl.smartmobile.module.push.implementation.SMPushMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>

Firebase notifications not received on Android app

I am trying to send notifications from Firebase to an Android mobile app developed in Visual Studio 2015.
I tried to implement each step that is presented in this tutorial, but I still can't receive notifications.
One weird thing that I noticed is related to this part of the tutorial:
Log.Debug(TAG, "google app id: " + Resource.String.google_app_id);
The google_app_id value logged to the output window should match the mobilesdk_app_id value recorded in google-services.json.
The result of the log that I quotted above doesn't match the mobilesdk_app_id value recorded in google-services.json, although I made every step presented in the tutorial.
Also, when I try to send notification that has the target set to "single device" and I write in the FCM registration token the result of the FirebaseInstanceId.Instance.Token, the message status is "failed" (Unregistered registration token).
How can I fix this issues?
Later edit:
The difference between the possible duplicate post and mine is that my FirebaseInstanceId.Instance.Token is not equal to mobilesdk_app_id value recorded in google-services.json.
Any ideas?
Content of manifest file (between application tags):
<application android:label="RTSD_Firebase">
<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>

Android Push notifications not recieving

This is driving me really crazy. I am new to Android development but experienced in iOS development. I wanted to implement Parse Push notifications to an Android app and all is going fine:
The devices are registered at Parse
While sending a test Push message the Parse system tells me that the message is received
BUT: I don't receive anything on my Android test devices.
I have already created new Parse Apps and Android Studio projects but without any luck. Any help on debugging this or is this a Android studio related issue?
EDIT: I just followed the Push service quick guide so I added some lines to the Manifest and added this to my code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inlog);
Parse.initialize(this, "xxx", "xxx");
ParseFacebookUtils.initialize("1515015192073818");
ParseInstallation.getCurrentInstallation().saveInBackground();
Manifest:
<receiver android:name="com.parse.GcmBroadcastReceiver"
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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.pootentieel.andrew.sbpootentieel" />
</intent-filter>
</receiver>
Did you changed com.parse.starter to match your package name and have you registered push callback receiver activity?
EDIT:
goto this link github.com/ParsePlatform/PushTutorial and import the android project and change the keys. Then run the android project and send a push to see if it works. If it works check both the projects side by side to see what is causing the problem. Please mark this answer as correct if it helped thanks :)

Categories

Resources