2013-12-16 144 views
1

Android解析sdk推送通知正在模擬器上工作,但是當我使用usb調試在手機上運行它時,推送通知在後端觸發,並且可以在我的parse.com帳戶中看到但手機沒有收到推送通知。Android解析sdk推送通知

public class Profile_InviteActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_profile__invite); 

     Bundle extras = getIntent().getExtras();  
     ParseQuery<ParseObject> query = ParseQuery.getQuery("UserProfile"); 
     Log.d("id",""+extras.getInt("fid")); 

     query.whereEqualTo("fid", ""+extras.getInt("fid")); 
     query.findInBackground(new FindCallback<ParseObject>() { 
      public void done(final List<ParseObject> scoreList, ParseException e) { 
       if (e == null) { 

        TextView name = (TextView) findViewById(R.id.profile_name); 
        TextView location = (TextView) findViewById(R.id.profile_location); 


        name.setText(scoreList.get(0).getString("name")); 
        location.setText(scoreList.get(0).getString("location")); 



        ParseFile img1 = (ParseFile)scoreList.get(0).get("profileimage"); 

        img1.getDataInBackground(new GetDataCallback() { 

         public void done(byte[] data, 
           ParseException e) { 
          if (e == null) { 
           Log.d("test", 
             "We've got data in data."); 
           // Decode the Byte[] into 
           // Bitmap 
           ImageView image = (ImageView) findViewById(R.id.profimg); 


           image.setImageBitmap(BitmapFactory 
             .decodeByteArray(
               data, 0, 
               data.length)); 
          } else { 
           Log.d("test", 
             "There was a problem downloading the data."); 
          } 
         } 
        }); 

       } else { 
        Log.d("score", "Error: " + e.getMessage()); 
       } 
      } 
     }); 

    } 

    public void inviteToTrain(View v) 
    { 
     Log.d("inviting","now"); 

     Bundle extras = getIntent().getExtras(); 

     //ParseInstallation installation = ParseInstallation.getCurrentInstallation();  

     //installation.put("fids",true); 
     //installation.saveInBackground(); 

     ParseQuery pushQuery = ParseInstallation.getQuery(); 
     //pushQuery.whereEqualTo("fid", extras.getInt("fid")); 
     pushQuery.whereEqualTo("fids", true); 
     // Send push notification to query 
     ParsePush push = new ParsePush(); 
     push.setQuery(pushQuery); // Set our Installation query 
     push.setMessage("Someone would like to join you at your event "); 
     push.sendInBackground(); 
     Log.d("invited","now"); 
    } 

}

請幫助我。

感謝

+0

哪裏是你的代碼? – GrIsHu

+0

代碼已更新 – rohit

回答

2

爲了得到推送通知,

你必須寫廣播接收機來處理。

示例代碼: 初始化解析細節後,在烏拉圭回合清單文件然後添加這個

PushService.setDefaultPushCallback(this, SampleClass.class); 

,添加此

<receiver android:name="com.parse.ParseBroadcastReceiver" > 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     <action android:name="android.intent.action.USER_PRESENT" /> 
    </intent-filter> 
</receiver> 

然後去分析儀表盤,並手動發送推序,以檢查是否推動進入你的手機。使用JSON格式是這樣,

{ "alert": "Notification", "title": "Push", "objectId": "objectId", 
"objectType": "type", "action": "Your Action Name" } 

更多詳細信息,請參閱

How to trigger an event using Parse for Android via push notification?

+0

謝謝,但我已經完成了這項工作。只有當我每次創建一個像這樣的新對象時,我纔會在手機上收到推送通知。它不適用於較早註冊的對象。 ParseInstallation installation = ParseInstallation.getCurrentInstallation(); installation.put(「fids」,true); installation.saveInBackground(); – rohit

+0

我沒有得到你在說什麼..在這裏貼一些示例代碼 –