2011-08-04 12 views
0

私はAndroidを勉強し始めました。私はJavaの知識は限られていますが、C/C++のobjective Cなどで半対応できます。私は持って来ましたが、私はpg73の "試してみてください:ステータスバーに通知を表示する"とは言いません。notificationIDは変数に解決することはできません

私はそれをすべて甘く書いてしまいましたが、アンドロイドのSDKとEclipse IDEに慣れていますが、このエラーは私のNotificationActivity.javaファイルにあります。

package com.androidtestingfun.www; 

import android.app.Activity; 
import android.os.Bundle; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Intent; 
import android.view.View; 
import android.widget.Button; 

public class NotificationsActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button button = (Button) findViewById(R.id.btn_displaynotif); 
     button.setOnClickListener(new Button.OnClickListener() { 
      public void onClick(View v) { 
       displayNotification(); 
      } 
     }); 
    } 

    protected void displayNotification() 
    { 
     //---PendingIntent to launch activity if the user selects this notification--- 
     Intent i = new Intent(this, NotificationView.class); 
     i.putExtra("notificationID", notificationID); //-----the second parameter here is getting an error 

     PendingIntent pendingIntent = 
       PendingIntent.getActivity(this, 0, i, 0); 

     NotificationManager nm = (NotificationManager) 
       getSystemService(NOTIFICATION_SERVICE); 

     Notification notif = new Notification(
       R.drawable.icon, 
       "Reminder: Meeting starts in 5 minutes", 
       System.currentTimeMillis()); 

     CharSequence from = "System Alarm"; 
     CharSequence message = "Meeting with customer at 3pm..."; 

     notif.setLatestEventInfo(this, from, message, pendingIntent); 

     //---100ms delay, vibrate for 250ms, pause for 100ms and then vibrate for 500ms--- 
     notif.vibrate = new long[] {100, 250, 100, 500}; 
     nm.notify(notificationID, notif);//-----the first parameter here is getting an error 
    } 
} 

私を聞くことができる任意のアイデアは非常に私は私のビルドを掃除しようとしたが、それdidntのは助けるために何でもする、いただければ幸いです。

答えて

3

notificationIDという変数がありません。

スニペットの例を参照、クラスにこの変数を追加します。

確か
public class NotificationsActivity extends Activity { 

    private static final int notificationID = 1234; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     // ........ 
    } 

    protected void displayNotification() 
    { 
     //---PendingIntent to launch activity if the user selects this notification--- 
     Intent i = new Intent(this, NotificationView.class); 
     i.putExtra("notificationID", notificationID); 

     PendingIntent pendingIntent = 
       PendingIntent.getActivity(this, 0, i, 0); 

     NotificationManager nm = (NotificationManager) 
       getSystemService(NOTIFICATION_SERVICE); 

     Notification notif = new Notification(
       R.drawable.icon, 
       "Reminder: Meeting starts in 5 minutes", 
       System.currentTimeMillis()); 

     CharSequence from = "System Alarm"; 
     CharSequence message = "Meeting with customer at 3pm..."; 

     notif.setLatestEventInfo(this, from, message, pendingIntent); 

     notif.vibrate = new long[] {100, 250, 100, 500}; 
     nm.notify(notificationID, notif); 
    } 
} 
+0

を...何ばか、明らかカントーを指摘して..私はそれが何か他のものだったと確信していた申し訳ありませんおかげで、それをソートしています。 –

+0

btw助けてくれてありがとう。 –

+0

問題なし、うれしい – MByD