1
我在我的項目中使用cordova 3.3.1。如何在與Android和cordova一起使用的項目中單擊通知時顯示特定頁面?
我打算在android設備的狀態欄通知中顯示我的通知。爲了實現我操縱createNotification()函數GCMIntentService類,現在我收到通知。
現在我將顯示一個特定的頁面,當我點擊通知(取決於通知類型)。你有什麼想法嗎,我不知道如何實現這個部分? 我只是知道,如果我修改我的java類擴展CordovaActivity,然後每當我運行「cordova構建」命令,我會失去所有的代碼,因爲這個類將被指定爲 科爾多瓦。這裏說到我的代碼:
--------------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")
}
}
感謝您的回覆,但您在哪裏定義目的地? – Gilana
intent = new Intent(MyActivity.this,ShowActivity.class); – user2323471