package com.krGCM_PHONE_LOCK;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gcm.GCMBaseIntentService;
import java.util.Iterator;
/**
* Created with IntelliJ IDEA.
* User: Parkjeehwan
* Date: 13. 6. 8
* Time: 오후 6:16
* To change this template use File | Settings | File Templates.
*/
public class GCMIntentService extends GCMBaseIntentService {
private static final String SENDER_ID = "136";
private static final String TAG = "GCMIntentService";
public GCMIntentService(){
this(SENDER_ID);
}
public GCMIntentService(String senderId) {
super(senderId);
}
@Override
protected void onMessage(Context context, Intent intent) {
//To change body of implemented methods use File | Settings | File Templates.
Vibrator vibrator = (Vibrator)getSystemService(context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
Toast.makeText(this, "HelloWorld", 1000 );
Bundle b = intent.getExtras();
Iterator<String> iterator = b.keySet().iterator();
while(iterator.hasNext()) {
String key = iterator.next();
String value = b.get(key).toString();
Log.d(TAG, "onMessage. "+key+" : "+value);
}
}
@Override
protected void onError(Context context, String s) {
//To change body of implemented methods use File | Settings | File Templates.
Log.d("ERROR", "errorId : "+s);
}
@Override
protected void onRegistered(Context context, String s) {
//To change body of implemented methods use File | Settings | File Templates.
Log.d("onRegistered", "onRegistered - regId : "+s);
}
@Override
protected void onUnregistered(Context context, String s) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
package com.krGCM_PHONE_LOCK;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gcm.GCMRegistrar;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "1");
} else {
Log.d("MyActivity", "oncreated regId = "+regId);
Log.d("MyActivity", "already registered.");
}
}
}
현재 A 폰에서 버튼을 누르면 B폰으로 메시지가 전송되는 것을 만드려고 합니다.
잘 안되네요... 도움의 손길을 주세요... ㅠ.ㅠ