[英]How to show a specific page on clicking a notification in a project that works with Android and cordova?
I am using cordova 3.3.1 in my project. 我在我的项目中使用cordova 3.3.1 。
I intend to display my notifications in my status bar notification in android devices. 我打算在Android设备的状态栏通知中显示通知。 In order to implement that I manipulated createNotification() function in GCMIntentService class, and now I recieve the notifications.
为了实现这一点,我在GCMIntentService类中操纵了createNotification()函数,现在我收到了通知。
Now I am going to show a specific page when I click on the notifications (It depends to notification type). 现在,我将在单击通知时显示特定页面(取决于通知类型)。 Do you have any idea about it, i don't know how implement this part?
您对此有任何想法吗,我不知道该如何实施? I just know that if I modify my java class which extend CordovaActivity, then whenever I run "cordova build" command, I'll lose all the codes because this class will be genarated by cordova.
我只知道,如果我修改扩展CordovaActivity的java类,那么每当我运行“ cordova build”命令时,我都会丢失所有代码,因为该类将由cordova生成。 Here comes my code:
这是我的代码:
--------------in my class GCMIntentService---------------------------
public void createNotification(Context context, Bundle extras)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
Intent notificationIntent = new Intent(this, G3Tracker.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent);
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText("You recieved a new notification: " + message);
} else {
mBuilder.setContentText("message");
}
-----------------------------------------------------
public class G3Tracker extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
}
}
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notif = new Notification(com.project.R.drawable.app_icon, "heading title", System.currentTimeMillis());
CharSequence from = "application name";
CharSequence message = "message which you want to show";
intent = new Intent(MyActivity.this,ShowActivity.class);
intent.putExtra("NotifID", notifID);
pendingIntent= PendingIntent.getActivity(MyActivity.this, notifID, intent, PendingIntent.FLAG_UPDATE_CURRENT| PendingIntent.FLAG_ONE_SHOT);
notif.setLatestEventInfo(this, from, message, intent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.vibrate = new long[] { 100, 250, 100, 500 };
nm.notify(notifID, notif);
finish();
Try this code it works for me, if you have any query then reply me. 尝试使用此代码对我有用,如果您有任何疑问,请回复我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.