このチュートリアル http://chrisrisner.com/31-Days-of-Android--Day-16%E2%80%93Notifications for show applictaion in notifdication bar を使用していますが、通知バーに私のアイコンが継続的に表示されますまたは一定時間後にアラート。
public class DaySixteenActivity extends BaseActivity {
private TextView lblTextViewOne;
private EditText editText1;
public static int notificationId = 0;
public static String MyStaticString;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("DaySixteenActivity", "onCreate Start");
lblTextViewOne = (TextView) findViewById(R.id.lblTextViewOne);
lblTextViewOne.setText(R.string.test_one);
editText1 = (EditText) findViewById(R.id.editText1);
editText1.setText(R.string.test_one);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
lblTextViewOne.setText(editText1.getText());
String notificationService = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager =
(NotificationManager) getSystemService(notificationService);
Notification notification = new
Notification(R.drawable.cherry_icon,
"Hello Notification!", System.currentTimeMillis());
Intent notificationIntent = new
Intent(getApplicationContext(), DaySixteenActivity.class);
PendingIntent contentIntent =
PendingIntent.getActivity(getApplicationContext(), 0,
notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(),
"Notification Title",
"CherryApplication", contentIntent);
notificationManager.notify(1, notification);
}
});
Log.i("DaySixTeenActivity", "onCreate End");
}
}
public class MyApplication extends Application {
private String myApplicationString;
public String getMyApplicationString() {
return myApplicationString;
}
public void setMyApplicationString(String myApplicationString) {
this.myApplicationString = myApplicationString;
}
}
public class PassableObject implements Parcelable {
private String myStringValue;
public PassableObject() {}
public PassableObject(Parcel inParcel) {
myStringValue = inParcel.readString();
}
public int describeContents() {
return 0;
}
public abstract class BaseActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
startActivity(new Intent(getApplicationContext(),
DaySixteenActivity.class));
//End the current activity
return true;
default:
return super.onContextItemSelected(item);
}
}
}
public void writeToParcel(Parcel outParcel, int flags) {
outParcel.writeString(myStringValue);
}
public String getMyStringValue() {
return myStringValue;
}
public void setMyStringValue(String myStringValue) {
this.myStringValue = myStringValue;
}
public static final Parcelable.Creator<PassableObject> CREATOR
= new Parcelable.Creator<PassableObject>() {
public PassableObject createFromParcel(Parcel in) {
return new PassableObject(in);
}
public PassableObject[] newArray(int size) {
return new PassableObject[size];
}
};
}