ボタンで通知を生成する非常に単純な例を実行しています。私はインタラクティブ性を探していません(つまり、インテントはありません)。簡単な通知を発行する必要があるだけです。UI には、通知を生成するためにクリックされるボタンが 1 つだけ含まれています。
コードは次のとおりです。
package ank.notificationdemo;
import android.R.drawable;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button btn_notify;
Notification noti;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_notify = (Button) findViewById(R.id.btn_notify);
noti = new Notification.Builder(MainActivity.this)
.setContentTitle("Alert!").setContentText("Shipwreck at 22N-56E. Hurry!").setSmallIcon(drawable.ic_dialog_alert)
.build();
btn_notify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
mgr.notify(100, noti);
}
});
}
}
問題は、これがエミュレーターで機能することですが、メインのアクティビティが私の Android フォン (ICS を実行している) に読み込まれないことです。ただし、他の例はうまく機能しています。
何がうまくいかないのかについての手がかりはありますか?
前もって感謝します!