Android 打开通知时如何在地图上显示lat lng点?
我正在开发一个应用程序,我想在打开通知时显示地图,我成功地收到了通知,但当我打开通知时,并没有用那个lat long值打开地图 GCMINENT服务类Android 打开通知时如何在地图上显示lat lng点?,android,google-maps,android-notifications,Android,Google Maps,Android Notifications,我正在开发一个应用程序,我想在打开通知时显示地图,我成功地收到了通知,但当我打开通知时,并没有用那个lat long值打开地图 GCMINENT服务类 public class GcmIntentService extends IntentService{ Context context; public static int notify_no=0; //System.currentTimeMillis(); private NotificationManager mNotificati
public class GcmIntentService extends IntentService{
Context context;
public static int notify_no=0;
//System.currentTimeMillis();
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public static final String TAG = "GCM NOTIFICATION";
public GcmIntentService() {
super("GcmIntentService");
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
Bundle extras = intent.getExtras();
String msg = intent.getStringExtra("message");
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
// sendNotification(RegIdDTO.REG_ID,"Send error: " + extras.toString());
sendNotification(this,msg);
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
// sendNotification(RegIdDTO.REG_ID,"Deleted messages on server: " +
// extras.toString());
sendNotification(this,msg);
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i=0; i<5; i++) {
Log.i(TAG, "Working... " + (i+1)
+ "/5 @ " + SystemClock.elapsedRealtime());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
// Post notification of received message.
//sendNotification("Received: " + extras.toString());
// sendNotification(RegIdDTO.REG_ID,msg);
sendNotification(this,msg);
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private static void sendNotification(Context context,String message) {
int icon = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
NotificationCompat.Builder nBuilder;
Uri alarmSound = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
nBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("header")
.setLights(Color.BLUE, 500, 500).setContentText(message)
.setAutoCancel(true).setTicker("Notification from Traffic")
.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
.setSound(alarmSound);
String consumerid = null;
Integer position = null;
// write your click event here
Intent resultIntent = new Intent(context, ShowMapActivity.class);
resultIntent.putExtra("message", message);
// resultIntent.setData(Uri.parse("content://"+when));
PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
notify_no, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Show the max number of notifications here
if (notify_no < 9) {
notify_no = notify_no + 1;
} else {
notify_no = 0;
}
nBuilder.setContentIntent(resultPendingIntent);
NotificationManager nNotifyMgr = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
nNotifyMgr.notify(notify_no + 2, nBuilder.build());
}
}
Logcat
ComponentInfo{com.technowellServices.traffic/com.technowellServices.traffic.ShowMapActivity}:
java.lang.NullPointerException
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1728)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1747)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.access$1500(ActivityThread.java:155)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.os.Handler.dispatchMessage(Handler.java:130)
03-06 13:03:40.187: E/AndroidRuntime(18546): at android.os.Looper.loop(SourceFile:351)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.main(ActivityThread.java:3814)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
java.lang.reflect.Method.invokeNative(Native Method)
03-06 13:03:40.187: E/AndroidRuntime(18546): at j
ava.lang.reflect.Method.invoke(Method.java:538)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
03-06 13:03:40.187: E/AndroidRuntime(18546): at dalvik.system.NativeStart.main(Native
Method)
03-06 13:03:40.187: E/AndroidRuntime(18546): Caused by: java.lang.NullPointerException
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.technowellServices.traffic.ShowMapActivity.onCreate(ShowMapActivity.java:66)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1692)
你不能把这叫做
Intent noticeIntent = getIntent();
在onCreate()方法之前
您应该将其放在onCreate()方法中
把这个从
String message = noticeIntent.getExtras().getString("message");
到
您应该在
ShowMapActivity
中创建noticecontent
内部onCreate(..)
Intent noticeIntent = getIntent();
String message = noticeIntent.getStringExtras("message");
您的活动是否正在打开?您的活动是否在
manifest.xml
中注册?否不选择我的活动是否在manifesti中注册在logcat中添加了exeption请查看Y以了解延迟响应及其即将到来的映射,但我想直接转到我的位置,而不从映射中缩小,。如何可能请告诉我您可以使用CameraUpdate CameraUpdate=CameraUpdateFactory.newLatLngZoom(latLng,10);map.animateCamera(cameraUpdate);是的,它只工作了一次,从第二次通知开始,没有直接显示它现在来了,但标记只是com和过去了我的logcat错误时间倒退:上一次1392207807105446(ioctl)对下一次139220780698404(ioctl),tid=19417发生了什么?标记来了,但在几秒钟后又消失了,地图上没有标记
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map);
Intent noticeIntent = getIntent();
// ...
}
String message = noticeIntent.getExtras().getString("message");
String message = noticeIntent.getStringExtras("message");
Intent noticeIntent = getIntent();
String message = noticeIntent.getStringExtras("message");