GCM が私の電話に通知を送信しており、私の電話はそれらを受け取ることができます (アプリが既に開かれている場合。アプリが実行されていない場合、アプリは開きません。これも問題です。)
ただし、現在、受信した通知をクリックするとどうなるかに注目しています。特に、何も起こりません。インテントを介してアプリを開くように設定しましたが、機能しません。
私のapp.jsの関連部分は次のとおりです。
var senderId = 'XXXXXXXXXX';
var c2dm = require('com.findlaw.c2dm');
Ti.API.info("module is => " + c2dm);
Ti.API.info('Registering...');
c2dm.registerC2dm(senderId, {
success:function(e) {
Ti.API.info('JS registration success event: ' + e.registrationId);
var params = {devicecode: e.registrationId, deviceType: "Android"};
JOURNAL.webApi.webCallPOST(JOURNAL.serviceLocatorModel.urls.Membership, "/registerdevice", params, JOURNAL.registerDeviceComplete, JOURNAL.registerDeviceError);
},
error:function(e) {
Ti.API.error("Error during registration: "+e.error);
var message;
if(e.error == "ACCOUNT_MISSING") {
message = "No Google account found; you'll need to add one (in Settings/Accounts) in order to activate notifications";
} else {
message = "Error during registration: "+e.error
}
Titanium.UI.createAlertDialog({
title: 'Push Notification Setup',
message: message,
buttonNames: ['OK']
}).show();
},
callback:function(e) // called when a push notification is received
{
Ti.API.info('JS message event: ' + JSON.stringify(e.data));
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_MAIN,
flags: Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,
className: 'com.geneca.journaling.GenecaJournalingActivity',
//className: 'org.appcelerator.titanium.TiActivity',
packageName: 'com.geneca.journaling'
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
// This is fairly static: Not much need to be altered here
var pending = Ti.Android.createPendingIntent({
activity: Ti.Android.currentActivity,
intent: intent,
type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
});
var notification = Ti.Android.createNotification({
contentIntent: pending,
contentTitle: 'New message',
contentText: e.data.message,
tickerText: "New message"
});
Ti.Android.NotificationManager.notify(1, notification);
}
});
そして、ここに私の tiapp.xml からの関連部分があります
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<activity android:name="com.geneca.journaling.GenecaJournalingActivity" />
<permission android:name="com.geneca.journaling.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.geneca.journaling.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application>
<service android:name="com.findlaw.c2dm.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="com.geneca.journaling"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.geneca.journaling"/>
</intent-filter>
</receiver>
</application>
</manifest>
</android>
<modules>
<module platform="android" version="0.1">com.findlaw.c2dm</module>
</modules>
ログキャットを実行しましたが、通知とインテントを取得していますが、これを吐き出し、アプリを開きません:
I/ActivityManager( 307): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 pkg=com.geneca.journaling cmp=com.geneca.journaling/.GenecaJournalingActivity bnds=[0,102][720,230] u=0} from pid -1
W/KeyguardViewMediator( 307): verifyUnlock called when not externally disabled
W/InputMethodManagerService( 307): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41c18038 attribute=android.view.inputmethod.EditorInfo@42319798
(真ん中はいつも出てくるわけではないので関係ないと思います。)
余談ですが、アプリが開いていない場合、ログの猫は私Bad notification posted from package com.geneca.journaling.mobile: Couldn't create icon
に、そしてたくさんのエラーを与えます.