我正在做一個非常簡單的例子,我想要一個按鈕來生成通知。我不是在尋找互動(所以沒有意圖);只是要發佈一個簡單的通知。 用戶界面只包含一個按鈕,單擊該按鈕即可生成通知。MainActivity在手機上失敗
下面的代碼:
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)的加載。然而,其他例子工作得很好。
有什麼線索可能會出錯?
在此先感謝!
你能提供logcat報告嗎? – Dimmerg
對於收集logcat報告使用'adb logcat' – Arseniy
@Dimmerg您是指Eclipse IDE中的logcat報告?它在我看來相當大。我應該在這裏粘貼一切還是上傳文本文件並提供鏈接? (對不起,如果問題是愚蠢的!) – dotslash