我在我的服务器和Android App之间使用GCM。 当我发送新文章时,如果内容土耳其语, 我得到空指针异常。
这是我的java代码
GcmNotificationService.java
@Override
protected void onHandleIntent(Intent intent) {
get_extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
crud = new CRUD( getApplicationContext() );
if (!get_extras.isEmpty()) {
if( get_extras.getString( DatabaseControl.POSTS_TITLE ) != null ){
// Bunların tam olarak ne olduğunu anlayamadım.
if( !GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals( messageType ) ||
!GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType ) ) {
String get_category_content = get_extras.getString( DatabaseControl.POSTS_CONTENT );
Log.d( "get_content", get_category_content );
List<CategoryHelper> new_content = new ArrayList<CategoryHelper>();
new_content.add(new CategoryHelper(
get_extras.getString( DatabaseControl.POSTS_IMAGE ),
get_extras.getString( DatabaseControl.POSTS_TITLE ),
get_extras.getString( DatabaseControl.POSTS_EXCERPT ),
get_extras.getString( DatabaseControl.POSTS_CONTENT ),
get_extras.getString( DatabaseControl.POSTS_DATE )
));
long insert_id = crud.add_posts( new_content, Integer.valueOf( get_extras.getString("category_number") ), 0 );
if( insert_id != 0 ){
send_notification();
}
Log.d( "extras_detail", get_extras.toString() );
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}
}
}
这是我的PHP代码
//this block is to post message to GCM on-click
$pushStatus = "";
if(!empty($_GET["push"])) {
$gcmRegID = "xxxxxxxxxxxxxx";
$pushMessage = $_POST["message"];
if (isset($gcmRegID) && isset($pushMessage)) {
$gcmRegIds = array($gcmRegID);
$today = date("Y-m-d");
$message = array(
"category_image" => "http://www.medyasef.com/wp-content/themes/medyasefnewtheme/img/companylogo.png",
"category_title" => "Bu Başlık",
"category_excerpt" => $pushMessage,
"category_content" => $pushMessage,
"category_date" => "$today",
"category_number" => "5"
);
$pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);
}
}
这是我的错误
03-26 11:48:49.591 29416-29495/com.medyasef.bulenttirasmobileapp.bulenttirascom E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[GcmNotificationService]
Process: com.medyasef.bulenttirasmobileapp.bulenttirascom, PID: 29416
java.lang.NullPointerException
at com.medyasef.bulenttirasmobileapp.bulenttirascom.GCM.GcmNotificationService.onHandleIntent(GcmNotificationService.java:50)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
这是GcmNotificationService.java:50
Log.d( "get_content", get_category_content );
请帮忙。 谢谢。