我正在尝试使用Android
和Urban Airship
在我的GCM
应用程序中启用推送通知。我使用here给出的说明创建GCM
帐户,并在Urban Airship
上设置开发应用程序。然后,我从显示为here的示例应用程序中复制了代码。
现在,当我运行我的应用程序时,我得到
E/ActivityThread﹕ Failed to find provider info for com.my.package.urbanairship.provider
接着
E/ActivityThread﹕ Failed to find provider info for com.my.package.urbanairship.provider
E/XXXX - UALib﹕ Failed to insert in UrbanAirshipProvider.
java.lang.IllegalArgumentException: Unknown URL content://com.my.package.urbanairship.provider/preferences
我想念什么?
app / src / main / assets / airshipconfig.properties
developmentAppKey = <my developmentAppKey>
developmentAppSecret = <my developmentAppSecret>
productionAppKey =
productionAppSecret =
gcmSender = <my gcmSender>
inProduction = false
# LogLevel is "VERBOSE", "DEBUG", "INFO", "WARN", "ERROR" or "ASSERT"
developmentLogLevel = DEBUG
productionLogLevel = ERROR
minSdkVersion = 15
app / src / main / AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" /> <!-- Required for Push -->
<!-- Urban airship -->
<permission android:name="com.my.package.permission.UA_DATA" android:protectionLevel="signature" />
<uses-permission android:name="com.my.package.permission.UA_DATA" />
<!-- The two elements above ensure that only this application has access to the Urban Airship provider -->
<!-- GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- This app has permission to register with GCM and receive message -->
<!-- MODIFICATION REQUIRED - Replace PACKAGE_NAME with your package name -->
<permission android:name="com.my.package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.my.package.permission.C2D_MESSAGE" />
<!-- The two elements above ensure that only this application can receive the messages and registration result -->
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Urban Airship and GCM -->
<activity android:name="com.urbanairship.CoreActivity"/>
<!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
<!-- Replace the receiver below with your package and class name -->
<receiver android:name=".GCMIntentReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.urbanairship.push.CHANNEL_UPDATED" />
<action android:name="com.urbanairship.push.OPENED" />
<action android:name="com.urbanairship.push.DISMISSED" />
<action android:name="com.urbanairship.push.RECEIVED" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.my.package" />
</intent-filter>
</receiver>
<!-- REQUIRED for PlayServiceUtils.handleAnyPlayServicesError to handle Google Play services recoverable errors. -->
<activity
android:name="com.urbanairship.google.PlayServicesErrorActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- REQUIRED for Urban Airship Push. The priority is important to be set lower than the
application's push intent receiver in order for the push intent receiver to handle push intents
before the core receiver. This allows the application to launch any activities before Urban
Airship performs any actions or falls back to launching the application launch intent. -->
<receiver android:name="com.urbanairship.CoreReceiver"
android:exported="false">
<intent-filter android:priority="-999">
<action android:name="com.urbanairship.push.OPENED" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.my.package" />
</intent-filter>
</receiver>
<!-- REQUIRED for GCM -->
<receiver
android:name="com.urbanairship.push.GCMPushReceiver"
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" />
<!-- MODIFICATION REQUIRED - Use your package name as the category -->
<category android:name="com.my.package" />
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service" />
<!-- ... -->
</application>
</manifest>
app / src / main / java / com / my / package / MyApp
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
/* ... */
/* Urban Airship */
UAirship.takeOff(this, new UAirship.OnReadyCallback() {
@Override
public void onAirshipReady(UAirship airship) {
// Perform any airship configurations here
// Create a customized default notification factory
DefaultNotificationFactory defaultNotificationFactory = new DefaultNotificationFactory(getApplicationContext());
defaultNotificationFactory.setSmallIconId(R.drawable.ic_launcher);
defaultNotificationFactory.setColor(NotificationCompat.COLOR_DEFAULT);
// Set it
airship.getPushManager().setNotificationFactory(defaultNotificationFactory);
// Enable Push
airship.getPushManager().setPushEnabled(true);
}
});
}
}
app / src / main / java / com / my / package / GCMIntentService
package com.my.package;
import android.content.Context;
import android.util.Log;
import com.urbanairship.push.BaseIntentReceiver;
import com.urbanairship.push.PushMessage;
public class GCMIntentReceiver extends BaseIntentReceiver {
private static final String TAG = "GCMIntentReceiver";
@Override
protected void onChannelRegistrationSucceeded(Context context, String channelId) {
Log.i(TAG, "Channel registration updated. Channel Id:" + channelId + ".");
// Broadcast that the channel updated. Used to refresh the channel ID on the main activity.
//LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MainActivity.ACTION_UPDATE_CHANNEL));
}
@Override
protected void onChannelRegistrationFailed(Context context) {
Log.i(TAG, "Channel registration failed.");
}
@Override
protected void onPushReceived(Context context, PushMessage message, int notificationId) {
Log.i(TAG, "Received push notification. Alert: " + message.getAlert() + ". Notification ID: " + notificationId);
}
@Override
protected void onBackgroundPushReceived(Context context, PushMessage message) {
Log.i(TAG, "Received background push message: " + message);
}
@Override
protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {
Log.i(TAG, "User clicked notification. Alert: " + message.getAlert());
return false;
}
@Override
protected boolean onNotificationActionOpened(Context context, PushMessage message, int notificationId, String buttonId, boolean isForeground) {
Log.i(TAG, "User clicked notification button. Button ID: " + buttonId + " Alert: " + message.getAlert());
return false;
}
@Override
protected void onNotificationDismissed(Context context, PushMessage message, int notificationId) {
Log.i(TAG, "Notification dismissed. Alert: " + message.getAlert() + ". Notification ID: " + notificationId);
}
}
最佳答案
我看不到清单中定义的提供程序。您应该具有以下内容:
<provider
android:name="provider"
android:authorities="com.my.package.urbanairship.provider"
android:exported="false"/>