我在android和phonegap中有一个应用程序,我正在使用Parse来发送推送。 我安装它时一切正常:我可以发送和接收通知。
5个小时后,它开始推迟推动,一天之后,它停止了,我再也无法收到它。
我在信息中心看到了通知,但没有在设备中看到。
有人可以给我消化吗?
的Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.meeto1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:name="com.example.meeto1.ParseApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.meeto1.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.example.meeto1.PushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<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>
<meta-data android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_launcher"/>
</application>
</manifest>
PushReceiver.java:
package com.example.meeto1;
import org.json.JSONException;
import org.json.JSONObject;
import com.parse.ParsePushBroadcastReceiver;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class PushReceiver extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked2");
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data") : "";
JSONObject jObject;
try {
jObject = new JSONObject(message);
for (int i=0; i < 10; i++)
{
Toast toast = Toast.makeText(context, jObject.getString("alert"), Toast.LENGTH_LONG);
toast.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected Class<? extends Activity> getActivity(Context context, Intent intent) {
Log.v("Parse", "getActivity called");
return super.getActivity(context, intent);
}
@Override
protected void onPushReceive(Context context, Intent intent) {
Log.v("Parse", "onPushReceive called");
super.onPushReceive(context, intent);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.v("Parse", "onReceive Called");
super.onReceive(context, intent);
}
}
MainActivity.java:
package com.example.meeto1;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.cordova.DroidGap;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
this.appView.addJavascriptInterface(new MainActivity(), "Android");
this.appView.addJavascriptInterface(new MeusMetodos(), "MeusMetodos");
this.appView.getSettings().setJavaScriptEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onStop() {
Log.w(TAG, "App stopped");
super.onStop();
}
@Override
public void onDestroy() {
Log.w(TAG, "App destoryed");
super.onDestroy();
}
}
ParseApplication.java
package com.example.meeto1;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.PushService;
import android.app.Application;
public class ParseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "xxx", "xxx");
ParsePush.subscribeInBackground("todosUsuarios");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
答案 0 :(得分:0)
只是为了让你知道我解决了它。
在我的清单中,在<application>
内,我使用了GCM Parse支持,我的通知现在正在运行:
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.meeto1" />
</intent-filter>