このチュートリアルhttps://phonegappro.com/tutorials/apache-cordova-phonegap-push-notification-tutorial-part-3/からすべてを実装しました。アクションボタン「はい」「いいえ」を使用してプッシュ通知を実装しようとしています。クリックすると結果がデータベースに返されます。しかし、私は多くのチュートリアルを行ってきましたが、これらのアクション ボタンをプッシュ通知に実装できませんでした。
GCMIntentService.java
public void createNotification(Context context, Bundle extras) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
String packageName = context.getPackageName();
Resources resources = context.getResources();
int notId = parseInt(NOT_ID, extras);
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra(PUSH_BUNDLE, extras);
notificationIntent.putExtra(NOT_ID, notId);
int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(fromHtml(extras.getString(TITLE)))
.setTicker(fromHtml(extras.getString(TITLE)))
.setContentIntent(contentIntent)
.setAutoCancel(true);
SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
String localIcon = prefs.getString(ICON, null);
String localIconColor = prefs.getString(ICON_COLOR, null);
boolean soundOption = prefs.getBoolean(SOUND, true);
boolean vibrateOption = prefs.getBoolean(VIBRATE, true);
Log.d(LOG_TAG, "stored icon=" + localIcon);
Log.d(LOG_TAG, "stored iconColor=" + localIconColor);
Log.d(LOG_TAG, "stored sound=" + soundOption);
Log.d(LOG_TAG, "stored vibrate=" + vibrateOption);
/*
* Notification Vibration
*/
setNotificationVibration(extras, vibrateOption, mBuilder);
/*
* Notification Icon Color
*
* Sets the small-icon background color of the notification.
* To use, add the `iconColor` key to plugin android options
*
*/
setNotificationIconColor(extras.getString("color"), mBuilder, localIconColor);
/*
* Notification Icon
*
* Sets the small-icon of the notification.
*
* - checks the plugin options for `icon` key
* - if none, uses the application icon
*
* The icon value must be a string that maps to a drawable resource.
* If no resource is found, falls
*
*/
setNotificationSmallIcon(context, extras, packageName, resources, mBuilder, localIcon);
/*
* Notification Large-Icon
*
* Sets the large-icon of the notification
*
* - checks the gcm data for the `image` key
* - checks to see if remote image, loads it.
* - checks to see if assets image, Loads It.
* - checks to see if resource image, LOADS IT!
* - if none, we don't set the large icon
*
*/
setNotificationLargeIcon(extras, packageName, resources, mBuilder);
/*
* Notification Sound
*/
if (soundOption) {
setNotificationSound(context, extras, mBuilder);
}
/*
* LED Notification
*/
setNotificationLedColor(extras, mBuilder);
/*
* Priority Notification
*/
setNotificationPriority(extras, mBuilder);
/*
* Notification message
*/
setNotificationMessage(notId, extras, mBuilder);
/*
* Notification count
*/
setNotificationCount(context, extras, mBuilder);
/*
* Notification count
*/
setVisibility(context, extras, mBuilder);
/*
* Notification add actions
*/
createActions(extras, mBuilder, resources, packageName, notId);
mNotificationManager.notify(appName, notId, mBuilder.build());
}