私はAndroidを初めて使用し、正常に動作しているGCMクライアントとサーバーを持っています。アプリの実行中、サーバーから通知を受け取ります。
しかし、アプリが実行されていないとき、私は何の応答も得られませんでした。
通知を生成するために使用するコードは次のとおりです。
private void generateNotification(Context context, String message) {
int icon = 1;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, DemoActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
これは次のように呼び出されます。
@Override
protected void onMessage(Context context, Intent intent) {
generateNotification(context, "Tock Tock");
}
logcatを見ると、次のようなエラーが発生します。
Unable to find resource: 1
W/ImageView( 58): android.content.res.Resources$NotFoundException: Resource ID #0x1
W/ImageView( 58): at android.content.res.Resources.getValue(Resources.java:892)
W/ImageView( 58): at android.content.res.Resources.getDrawable(Resources.java:580)
W/ImageView( 58): at android.widget.ImageView.resolveUri(ImageView.java:489)
W/ImageView( 58): at android.widget.ImageView.onMeasure(ImageView.java:592)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:989)
W/ImageView( 58): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
W/ImageView( 58): at android.widget.ScrollView.onMeasure(ScrollView.java:286)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
W/ImageView( 58): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
W/ImageView( 58): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
W/ImageView( 58): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
W/ImageView( 58): at android.view.View.measure(View.java:8171)
W/ImageView( 58): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
W/ImageView( 58): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
W/ImageView( 58): at android.os.Handler.dispatchMessage(Handler.java:99)
W/ImageView( 58): at android.os.Looper.loop(Looper.java:123)
W/ImageView( 58): at com.android.server.ServerThread.run(SystemServer.java:506)
どこを間違えているのかわからない。ここからサンプルチュートリアルをフォローしています。
前もって感謝します。