【发布时间】:2013-09-19 05:44:39
【问题描述】:
我正在开发一个名为 TobaccoRoad 的应用程序,该应用程序使用了一个名为 BestApproach 的库项目。它使用 Parse 后端来显示自定义生成的内容并处理推送通知。直到几天前,一切都工作得很好,当时我一定在某处搞砸了一些设置,它似乎不再与解析系统建立连接。我很确定这是本地问题,因为我的第二部测试手机在几天内没有推送更新代码,但仍在接收通知并且可以查看自定义内容。
奇怪的是,即使在清理了我的工作空间并从我的雇主给我的(绝对好的)代码重新开始,并遵循 Parse.com 上的所有教程和故障排除指南之后(参见https://parse.com/docs/push_guide#installations/Android;https://parse.com/tutorials/android-push-notifications)我仍然没有连接到 Parse。我没有做出任何我能回忆起的重大改变,所以我不知道是什么原因造成的。
我知道这不是 applicationID 或 clientKey 错误的问题,因为即使将随机字符串替换到 Parse.initialize 调用中也会得到相同的结果,并且会出现关于无法进行身份验证的 logcat 错误。
这是我的清单文件中的相关位,首先是库项目...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestapproach.lib"
android:versionCode="8"
android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name"
android:theme="@style/Theme.BA" >
<activity android:name="com.bestapproach.lib.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="@style/Theme.BA.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Declarations for all of my Activities...-->
<service android:name="com.parse.PushService" />
<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>
</application>
</manifest>
清单对于我的依赖项目来说是完全一样的,除了我在最后定义了一个自定义接收器:
<service android:name="com.parse.PushService" />
<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>
<receiver android:name="com.bestapproach.lib.MyCustomReceiver">
<intent-filter>
<action android:name="com.bestapproach.lib.UPDATE_STATUS" />
</intent-filter>
</receiver>
这是我的主要活动 (SplashActivity) 中 onCreate() 方法的代码,其中初始化了 Parse 服务:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
String parseClientId = getString(R.string.parse_client_id);
String parseAppId = getString(R.string.parse_app_id);
//debug output
Log.v("parse should be initializing...", parseAppId+" "+parseClientId);
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
PushService.subscribe(this, "", MenuActivity.class);
PushService.setDefaultPushCallback(this, SplashActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
final Activity a = this;
// Fetches content if it doesn't exist.
StoreManager sm = StoreManager.getInstance(a);
ParseStoreManager psm = ParseStoreManager.getInstance(a);
return;
}
}
我发现的建议似乎可以满足我的需要,包括在每个活动的 onCreate() 中运行 Parse.initialize(),我真的不想这样做,因为它们很多那将是很多重复的代码,或者生成一个应用程序对象并从那里运行它。由于 TobaccoRoad 对库项目的依赖关系,一旦我将其添加到清单文件中,我所尝试的所有内容最终都会中断。
我知道,要深入研究的内容很多,但如有任何建议,我们将不胜感激。谢谢大家。
【问题讨论】:
-
您已将您的
AppId和ClientId与解析云中的实际值进行了比较?