Может ли кто-нибудь предложить некоторые советы о том, как настроить уведомления о статусе в Android?
Мой набор навыков основан на дизайне/интерфейсе dev (следовательно, с помощью phonegap), поэтому я новичок в Eclipse.
Я прочитал этот учебник - http://androidforbeginners.blogspot.com/2010/02/how-to-create-status-bar-notifications.html и вставил код в область действия моего файла манифеста Android. Но я не совсем понимаю, как это будет работать. Если я буду компилировать это сейчас как APK и установить его на телефон - теперь он готов получать уведомления? Если да, то как мне их отправить и где я набираю код отправки?
Надеюсь, это довольно просто, так как мой босс надеется, что он будет завершен до Рождества!
Приветствую вас за помощь. Все лучшее
Вы хотите уведомление о статусной строке? Если да... вам повезло... вот плагин, который я уже создал для телефонного разговора. Осмотрите, как встроить внешний плагин в android.
https://github.com/phonegap/phonegap-plugins/tree/master/Android/StatusBarNotification
Здесь вы можете найти более подробное объяснение с исходными кодами об уведомлениях.
Уведомление может быть реакцией на какое-то событие. Например, вы можете создать простое приложение с помощью одной кнопки. Когда вы нажимаете эту кнопку, в строке состояния будет отображаться уведомление.
О развитии. Вы должны установить Android SDK, создать эмулятор устройства. Также очень полезно установить Android ADT - это плагин для Eclipse, который поможет разрабатывать приложения для Android. После этого при создании приложения он будет автоматически установлен на эмулятор.
Вот код, как сделать простое уведомление:
package your.package
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AcNotificationTestMain extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private static final int SEND_ID = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button mBtnSend = (Button) findViewById(R.id.button1);
mBtnSend.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
Log.v("","OnClick...");
// Create an object of Notification manager
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.sym_action_email; // icon from resources
CharSequence tickerText = "New Notification"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = "My notification"; // expanded message title
CharSequence contentText = "Click me!"; // expanded message text
Intent notificationIntent = new Intent(this, AcNotificationTestMain.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(SEND_ID, notification);
}
}
И файл макета:
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/>
<Button android:id="@+id/button1" android:text="@string/AcNotificationTest_BtnSendNotificationText" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>