我是Android开发的新手。我为此搜索了很多,但找不到任何正确的答案。我想制作一个弹出/对话框屏幕,该屏幕在服务中发生时会显示。
手机锁定时也应提供此屏幕。我已经发现,您可以在对话样式或具有透明背景的活动中进行活动。但是我认为这不是正确的方法。这是其中一个屏幕(右图):链接
您可以滚动浏览所有消息并响应所有消息。我的调试电话具有Android 4.0.2(因此是API级别14),我希望它用作我的应用的最低要求。
编辑:感谢您的答复,但我已经测试了通知。问题是,仅在通知栏中显示了小型孔。我没有带有标题或内容的通知窗口或弹出窗口...所以这是我的实现:
import com.google.android.gms.gcm.GoogleCloudMessaging;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
public GcmIntentService() {
super("GcmIntentService");
}
public static final String TAG = "GCM test";
@Override
protected void onHandleIntent(Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!intent.getExtras().isEmpty()) { // has effect of unparcelling Bundle
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + intent.getExtras().toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " + intent.getExtras().toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// Post notification of received message.
sendNotification("message:n" + intent.getStringExtra("message"));
Log.i(TAG, "Received: " + intent.getExtras().toString());
}
}
// Release the wake lock provided by the WakefulBroadcastReceiver.
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_check)
.setContentTitle("My notification")
.setContentText(msg);
Intent resultIntent = new Intent(this, PopupMessageActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(PopupMessageActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
通知是您要寻找的
这是指向Android开发人员页面的链接:http://developer.android.com/guide/topics/ui/notifiers/notifications.html
吐司也可能对您有所帮助:http://developer.android.com/guide/topics/ui/notifiers/toasts.html
祝你好运!
您正在谈论在lockscreen
上运行的应用程序小部件..所以你可以阅读此页面并使用此页https://developer.android.com/guide/topics/appwidgets/index.html