마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

현재 GCM이용 php 페이지 입력창에 url을 받아 이미지로 보내서 비트맵 저장 후 푸시할 때 같이 뿌려주는 내용을 개발중인데 질문 해도될까요

0 추천
 
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String message = intent.getExtras().getString("price");
String imgurl = intent.getExtras().getString("values");
// displayMessage(context, message);
// notifies user
generateNotification(context, message);
}
 
/**
* Method called on receiving a deleted message
* */
@Override
protected void onDeletedMessages(Context context, int total) {
Log.i(TAG, "Received deleted messages notification");
String message = getString(R.string.gcm_deleted, total);
String imgurl = getString(R.string.gcm_deleted, total);
// displayMessage(context, message);
// notifies user
// generateNotification(context, message);
}
 
/**
* Method called on Error
* */
@Override
public void onError(Context context, String errorId) {
Log.i(TAG, "Received error: " + errorId);
// displayMessage(context, getString(R.string.gcm_error, errorId));
}
 
@Override
protected boolean onRecoverableError(Context context, String errorId) {
// log message
Log.i(TAG, "Received recoverable error: " + errorId);
// displayMessage(context,
// getString(R.string.gcm_recoverable_error, errorId));
return super.onRecoverableError(context, errorId);
}
 
/**
* Issues a notification to inform the user that server has sent a message.
*/
 
private void generateNotification(Context context, String message) {
 
 
 
 
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
 
 
Intent notificationIntent = new Intent(context, MainActivity.class);
// set intent so it does not start a new activity
// notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
// Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
 
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("NHMall")
.setSmallIcon(R.drawable.mainicon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.mainicon))
.setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE);
NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle();
bigPicStyle.bigPicture(bitmap);
bigPicStyle.setBigContentTitle("NHMall");
bigPicStyle.setSummaryText(message);
mBuilder.setStyle(bigPicStyle);
 
// notification.setLatestEventInfo(context, title, message, intent);
 
// // Play default notification sound
// notification.defaults |= Notification.DEFAULT_SOUND;
//
// // Vibrate if vibrate is enabled
// notification.defaults |= Notification.DEFAULT_VIBRATE;
// notificationManager.notify(0, notification);
 
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
 
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
 
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
 
}
 
public Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
 
 
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
 
 
 
}
 
GCMIntentService.java 소스가 현재 이렇게 되어있습니다. php 페이지 같은 경우는 php 내에서는 url 주소를 입력받아 제대로 넘겨주고 있습니다. 근데 여기서 어떻게 url 주소를 받아야 되는지 감이 안오네요..;; 도와주실분 계실까요
익명사용자 님이 2015년 1월 27일 질문

1개의 답변

0 추천
  1. gcm 이 제대로 넘어 오는가
  2. url을 가져왔는가
  3. url이 정확한가
  4. 이미지를 다운로드 받을 수 있는가(localhost나 뭐 그런..)
  5. 이미지가 저장되는가

 

이런 식으로 순서를 정해서 하나하나 살펴보시고, 어디서부터 안되는지를 적어야 답변을 얻을 수 있습니다.

개발자라고해서 정말 짧은 한 두 줄의 소스 아니면 남의 소스 보자마자 '저기가 문제군' 하는 경우는 절대 없어요.

쎄미 (162,410 포인트) 님이 2015년 1월 27일 답변
gcm 같은 경우는 웹에서 메시지를 보내면 정상적으로 보내집니다.
그리고
private void generateNotification(Context context, String message) {
 
Bitmap bitmap =getBitmapFromURL("http://cfile22.uf.tistory.com/image/1804141349BCFF752BCAD3");
getBitmapFromURL부분을 절대값으로 넣었을 시에는 웹 메시지와 함께 정상적으로 푸시로 넘어오는데 이 부분을 url 변수를 만들어서 넣어야하나요?
url 변수 선언하고 getBitmapFromURL안에 imgurl 값을 넣고 로그를 찍어봤더니 null이 나오더라구요 웹에서 디바이스로 url 값을 못넘겨주는 것 같은데..
웹에서 제대로 넘기는 것부터 알아보세요.
gcm 보내는 페이지는 https://gcmsender.herokuapp.com 입니다.
 메시지 필드의 json 부분이 의심이 가는군요
{
  "body": "{\"multicast_id\":7237449063548428678,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1422348846816606%a746be7df9fd7ecd\"}]}",
  "headers": "#",
  "status_code": 200,
  "response": "success",
  "canonical_ids": [

  ],
  "not_registered_ids": [

  ]
}
결과값이 이렇게 나옵니다
자꾸 질문드려서 죄송합니다..;
제대로 보냈다고 하네요
...