Appcelerator UrbanAirship and android (launch app) - android

I am using UrbanAirship module in my Appcelerator project to receive push notifications. I am receiving push notifications but when a user clicks on a notification from their notification center on their android device the app doesn't launch. It does on the iPhone though. Any ideas how to fix this?
Thanks.
Update
Below is the code used to subscribe to push notification on the android
UrbanAirship = require("ti.urbanairship")
Ti.API.log "UrbanAirship.pushEnabled " + UrbanAirship.pushEnabled
Ti.API.log "UrbanAirship.pushId " + UrbanAirship.pushId
UrbanAirship.options =
PRODUCTION_APP_KEY: "XXXX"
PRODUCTION_APP_SECRET: "XXXX"
DEVELOPMENT_APP_KEY: "XXXX"
DEVELOPMENT_APP_SECRET: "XXXX"
LOGGING_ENABLED: true
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_CALLBACK, (e) ->
Ti.API.info "UrbanAirship: Received message " + e.message
alert e.message
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_SUCCESS, (e) ->
token = e.deviceToken
Ti.App.Properties.setString "device_token", token
Ti.API.info "UrbanAirship: Received device token " + token
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_ERROR, (e) ->
Ti.API.info "UrbanAirship: Error " + e.error
UrbanAirship.pushEnabled = true
And on the server side:
notification = {"android" => {"alert" => message}, "apids" => android_device_tokens}
Urbanairship.push(notification)
Here is the android related code in the tiapp.xml
<property name="ti.android.debug" type="bool">true</property>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:installLocation="preferExternal"
android:versionCode="10" android:versionName="1.0.6"/>
<manifest>
<supports-screens android:anyDensity="false"/>
<application>
<activity
android:configChanges="keyboardHidden|orientation"
android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
</application>
</manifest>
</android>
Below is the airshipconfig.properties
developmentAppKey = xxx
developmentAppSecret = xxx
productionAppKey = xxx
productionAppSecret = xxx
transport = c2dm
c2dmSender = xxxx#gmail.com
inProduction = true
iapEnabled = false
And here is the auto generated AndroidManifest.xml
<?xml version="1.0" ?>
<manifest android:installLocation="preferExternal" android:versionCode="10" android:versionName="1.0.6" package="com.batmanadventure" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="false"/>
<uses-sdk android:minSdkVersion="8"/>
<permission android:name="com.batmanadventure.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<application android:debuggable="false" android:icon="#drawable/appicon" android:label="BatmanAdventure" android:name="BatmanadventureApplication">
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
<receiver android:name="com.urbanairship.CoreReceiver">
<!-- REQUIRED IntentFilter - For Helium and Hybrid -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
</intent-filter>
</receiver>
<receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actuggal message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.batmanadventure"/>
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.batmanadventure"/>
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService"/>
<receiver android:name="ti.modules.titanium.urbanairship.IntentReceiver"/>
<activity android:configChanges="keyboardHidden|orientation" android:label="BatmanAdventure" android:name=".BatmanadventureActivity" android:theme="#style/Theme.Titanium">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiTranslucentActivity" android:theme="#android:style/Theme.Translucent"/>
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiModalActivity" android:theme="#android:style/Theme.Translucent"/>
<activity android:configChanges="keyboardHidden|orientation" android:name="ti.modules.titanium.ui.TiTabActivity"/>
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
<service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"/>
</application>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.batmanadventure.permission.C2D_MESSAGE"/>
</manifest>

Firstly, it surely is not a problem with urbanairship library. Because urbanairship won't miss on something this basic.
Check Custom Handling of Push Events
Here, the launch of activity is being handled a little differently by checking for PushManager.ACTION_NOTIFICATION_OPENED and then calling UAirship.shared().getApplicationContext().startActivity(launch);
In your ti.modules.titanium.urbanairship.IntentReceiver
public class IntentReceiver extends BroadcastReceiver {
private static final String logTag = "PushSample";
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));
logPushExtras(intent);
Intent launch = new Intent(Intent.ACTION_MAIN);
launch.setClass(UAirship.shared().getApplicationContext(), MainActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UAirship.shared().getApplicationContext().startActivity(launch);
}
}
You can set the activity to be launched in launch.setClass(UAirship.shared().getApplicationContext(),MainActivity.class);

It could be a problem with urbanairship library. If they did not add a PendingIntent to the notification, it will not open your app.
I just looked at urbanairship.com but it does not seem they provide source code for Android, only the jar.

Related

Android AIDL - Unable to start service Intent

The error I am receiving is
2022-01-28 11:10:42.186 1651-3045/? W/ActivityManager: Unable to start service Intent { act=nveeaidle pkg=com.rchan.nveeapplication } U=0: not found
I have ensured the following code in both my applications (client and server). In my server manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rchan.nveeapplication">
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.NveeApplication">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="nveeaidle" />
</intent-filter>
</service>
<receiver android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"/>
<!-- <receiver-->
<!-- android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"-->
<!-- android:exported="false"-->
<!-- android:process=":remote"-->
<!-- android:permission="com.google.android.gms.permission.ACTIVITY_RECOGNITION">-->
<!-- <intent-filter>-->
<!-- <action android:name="action.TRANSITIONS_DATA" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
</application>
</manifest>
In my client, I have this in my fragment:
private fun connectToRemoteService() {
val intent = Intent("nveeaidle")
val pack = "com.rchan.nveeapplication"
pack?.let {
intent.setPackage(pack)
activity?.applicationContext?.bindService(
intent, this, Context.BIND_AUTO_CREATE
)
}
}
I am not sure what is causing this warning, and I have tried out different solutions after searching on stackoverflow and google.
How do I test is:
Launch my server application
Launch my client application
I see the warning
Thank you for taking the time to read my question.
After recent changes, You can use <queries> <package android:name ="your package name" /> </queries>
https://developer.android.com/training/package-visibility/declaring
I did more searching and finally found the answer... All credits go to the SO answer here:
https://stackoverflow.com/a/55712326/3718584
TLDR:
Had to change the intent from implicit to explicit due to API 21
intent.setClassName("com.rchan.nveeapplication","com.rchan.nvee_sdk.detectedactivity.DetectedActivityService")

handshakeexception handshake error in client (os error wrong_version_number tls_record cc 242) Flutter app/Node server

I'm getting an handshakeexception handshake error in client (os error wrong_version_number tls_record cc 242) error whenever making an http request( I also tried https ) but from only one ( Cyclist app ) of the two Flutter apps that connect to Node.js server. I'm using the same IP address and port on both, the Android tablet on which I'm testing both apps and for my machine. I checked Manifest Android/src/main/AndroidManifest.xml to see if I was using android:usesCleartextTraffic="true"`on the working app ( Shop app ) but I'm not..
What else could I check to see what's causing the error in the Cyclist app??
This is the request:
Map<String, String> headers = {
'Content-Type': 'application/json',
'api_key': Environment.dbApiKey
};
// final Uri uri = Uri.https(Environment.dbUrl, '/api/routes');
final Uri uri = Uri.http(Environment.dbUrl, '/api/routes');
await post(uri, headers: headers, body: jsonEncode(route.toMap()))
.then((resp) {
print(
'RouteMongoRepository.saveRoute response status code is: ${resp
.statusCode}, \n response is : ${jsonDecode(resp.body)}');
UserRoute saved = UserRoute.fromMap(jsonDecode(resp.body)['data']);
print('saved route to Mongo is : ${saved.toMap().toString()}');
}) .catchError((e) => print('RouteMongoRepository.saveRoute error: $e')) ;
This is the Shop app manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vinny.fixit_shop_flutter">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="fixit shop"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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>
and this is the Cyclist app manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="fixit"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
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"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<!-- 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>
Found it..I was missing <uses-permission android:name="android.permission.INTERNET" />in Cyclist app AndroidManifest.xml

Android&Quickblox (api 3.2): Subscribing to push notifications

I'm not able to subscribe to push notifications. I did:
1) I created a firebase application, with the same package name as my MainActivity package name;
2) I downloaded the google-service.json file and stored it in my /app/ next to the gradle file;
3) I added the C2D and WAKE-LOCK permissions as the google guide showed;
4) I added the API-KEY in the pushnotification's setting tab in quickblox admin panel;
5) I modified the manifest as showed by the quickblox guide;
6) I added a push-notification listener and a local broadcast receiver as shown by the same guide as above.
That's how my manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.unical.sistemidistribuiti.ddf.appraia">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"/>
<meta-data android:name="com.quickblox.messages.TYPE" android:value="FCM" />
<meta-data android:name="com.quickblox.messages.SENDER_ID" android:value="#string/sender_id" />
<meta-data android:name="com.quickblox.messages.QB_ENVIRONMENT" android:value="DEVELOPMENT" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="#style/AppTheme"
android:name="it.unical.sistemidistribuiti.ddf.appraia.AppraiaApplication">
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.StartActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.NewsDetailActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.CreatePostActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.UserProfileActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service
android:name="com.quickblox.messages.services.fcm.QBFcmPushListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
Since I'm using 3.2 sdk version, the app should automatically subscribe the user to push-notifications, but this not happen. Actually the listener code prints nothing:
//This is in AppraiaApplication extends Application
#Override
public void onCreate() {
super.onCreate();
QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
QBPushManager.getInstance().addListener(new QBPushManager.QBSubscribeListener() {
#Override
public void onSubscriptionCreated() {
System.out.println("onSubscriptionCreated");
}
#Override
public void onSubscriptionError(final Exception e, int resultCode) {
System.out.println("onSubscriptionError" + e);
if (resultCode >= 0) {
System.out.println("Google play service exception");
}
System.out.println("onSubscriptionError " + e.getMessage());
}
});
QBSettings.getInstance().setEnablePushNotification(true);
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver,
new IntentFilter("new-push-event"));
System.out.println("Application creation ended");
}
What am I doing wrong?
Looks like you don't make signIn with user, and subscription is not performed. Also have a look in logs, there is can be info something like D/QBASDK: SubscribeService: SubscribeService created. So, you can figure out whether the subscription is executed at all.

Parse server notifications for android not logging in GCM and not received on device

I'm new to android so please bear with me.
I've tried my very best to configure parse server (on Heroku) to send notifications to my android app and I've (hopefully) appropriately configured AndroidManifest.xml as well (see below).
When I send a notification using parse dashboard it seems to suggest that it has been sent in the Heroku logs (i'm not developing for iOS hence the error on the second line):
Heroku Logs:
2016-11-16T20:33:29.713489+00:00 heroku[router]: at=info method=POST path="/parse/push" host=heartofengland.herokuapp.com request_id=03ac09c2-3209-4d12-a7eb-e2e7f72e2dde fwd="104.238.169.124" dyno=web.1 connect=0ms service=7ms status=200 bytes=482
2016-11-16T20:33:29.761488+00:00 app[web.1]: Can not find sender for push type ios, {"where":{},"data":{"alert":"Test message"}}
The issue is however nothing logs in GCM nor do i get a notification on my device.
From the numerous guides I have followed, they would all seem to suggest I have configured parse and AndroidManifest.xml correctly - obviously I seem to be missing something (See below).
Any ideas as to what I'm doing wrong?
Thanks in advance
Parse index.js:
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || '',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || '',
masterKey: process.env.MASTER_KEY || '',
serverURL: process.env.SERVER_URL || '',
push: {
android: {
senderId: 'XXXXXXXXXX', //Obscured for security
apiKey: 'XXXXXXXXXXXXXXXX'
}
}
});
var app = express();
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a web site.');
});
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.alexwoodhouse.drawview.drawviewtest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:protectionLevel="signature" android:name="${packageName}.permission.C2D_MESSAGE" />
<uses-permission android:name="${packageName}.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="#string/gcm_sender_id"/>
<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" />
<category android:name="${packageName}" />
</intent-filter>
</receiver>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="Heart of England"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TimeTable"
android:label="Timetable"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Twitter"
android:label="Twitter Feed" />
<activity
android:name=".Emails"
android:label="School Email"></activity>
</application>
</manifest>

Notification is received but not displayed using Parse Unity SDK + Android

I'm using Parse Unity SDK for Android.
I've managed to register the device successfully.
void Start() {
//Parse Installation
if (ParseInstallation.CurrentInstallation != null && !string.IsNullOrEmpty(ParseInstallation.CurrentInstallation.DeviceToken))
{
Debug.Log("Device Token : " + ParseInstallation.CurrentInstallation.DeviceToken);
}
else
{
ParseInstallation installation = ParseInstallation.CurrentInstallation;
installation.Channels = new List<string> { Config.Instance.GetUserInfo().GetEmail() };
installation.SaveAsync().ContinueWith(t => {
if (t.IsFaulted || t.IsCanceled)
{
Debug.Log("Push subscription failed.");
}
else
{
Debug.Log("Push subscription success.");
}
});
//installation.
}
}
Only to discover that the notification is "received" but not being displayed neither in the app nor in the notifications bar.
I/GCM ( 1285): GCM message com.ahmed.app 0:1433935471473270%3f8fc5dbf9fd7ecd
I/ParsePushService( 7057): Push notification received. Payload: {"alert":"test","push_hash":"098f6bcd4621d373cade4e832627b4f6"}
I/ParsePushService( 7057): Push notification is handled while the app is foregrounded.
W/GCM-DMM ( 1285): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.ahmed.app (has extras) }
Also, Unity does not receive the notification (see code)
void Awake() {
ParsePush.ParsePushNotificationReceived += (sender, args) => {
#if UNITY_ANDROID
AndroidJavaClass parseUnityHelper = new AndroidJavaClass("com.parse.ParseUnityHelper");
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
//Debugging the payload
Debug.Log("Calling Parse from Unity and Payload is : " + args.StringPayload);
// Call default behavior.
parseUnityHelper.CallStatic("handleParsePushNotificationReceived", currentActivity, args.StringPayload);
#endif
};
}
This event doesn't get triggered.
Here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ahmed.app" android:theme="#android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature" android:name="com.ahmed.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.ahmed.app.permission.C2D_MESSAGE" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="#string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
<activity android:name="com.outlinegames.unibill.PurchaseActivity" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<service android:name="com.parse.ParsePushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver" 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="com.ahmed.app" />
</intent-filter>
</receiver>
</application>
Any idea what's the problem?
I have answered the same kind of question, I just wanted to let you know.
Parse Unity Push Sample not working
Basically, this line of your code is wrong:
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
You have to replace it by
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("com.unity3d.player.UnityPlayerNativeActivity");
Rather than downloading the SDK manually, I've downloaded the Parse Push sample project and copied the files to my project. Using the SDK 1.5.2 sample project, it works now.

Categories

Resources