我正在尝试使用Flurry发送深层链接通知,而是该通知无法打开应用程序并且不会播放声音,为此我正在使用自动集成,并且我有MyFlurryMessagingListener类,它来自Flurry文档。我没有任何错误,只是这个问题,是的,我确定在创建Flurry仪表板中的推入时选择“深层链接”。
构建Gradle
implementation 'com.flurry.android:analytics:11.6.0@aar'
implementation 'com.flurry.android:marketing:11.6.0@aar'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
MyApplication类
public class MyApplication extends Application {
private static final String TAG = "MyApplication";
@Override
public void onCreate() {
super.onCreate();
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "REGISTERED TOKEN: " + refreshedToken);
FlurryMarketingOptions flurryMessagingOptions = new FlurryMarketingOptions.Builder()
.setupMessagingWithAutoIntegration()
.withDefaultNotificationIconResourceId(R.drawable.ic_notification)
.withDefaultNotificationIconAccentColor(getResources().getColor(R.color.colorPrimaryDark))
.build();
FlurryMarketingModule marketingModule = new FlurryMarketingModule(flurryMessagingOptions);
new FlurryAgent.Builder()
.withLogEnabled(true)
.withModule(marketingModule)
.build(this, "CCCCCTESTTESTTESTTEST");
}
}
MyFlurryMessagingListener类
public class MyFlurryMessagingListener implements FlurryMessagingListener {
final static String LOG_TAG = MyFlurryMessagingListener.class.getCanonicalName();
Context context;
public MyFlurryMessagingListener(Context context) {
this.context = context;
}
@Override
public boolean onNotificationReceived(FlurryMessage flurryMessage) {
// determine if you'd like to handle the received notification yourself or not
boolean handled = false;
// flurry will not show notification if app is in foreground, so handle it appropriately
if (FlurryMessaging.isAppInForeground()) {
// handle the notification using data from FlurryMessage
// NOTE: since you are handling the notification, be sure to call logNotificationOpened and logNotificationCancelled after this
handled = true;
}
return handled;
}
@Override
public boolean onNotificationClicked(FlurryMessage flurryMessage) {
// NOTE: THIS WILL ONLY BE CALLED IF FLURRY HANDLED onNotificationReceived callback
// determine if you'd like to handle the clicked notification yourself or not
boolean handled = false;
return handled;
}
@Override
public void onNotificationCancelled(FlurryMessage flurryMessage) {
Log.d(LOG_TAG, "Notification cancelled!");
}
@Override
public void onTokenRefresh(String refreshedToken) {
Log.d(LOG_TAG, "Token refreshed - " + refreshedToken);
}
@Override
public void onNonFlurryNotificationReceived(Object nonFlurryMessage) {
// If Flurry receives a non-Flurry message, it will be passed to you here. You can cast the object
// based on the push provider. For example...
if (nonFlurryMessage instanceof RemoteMessage) {
RemoteMessage firebaseMessage = (RemoteMessage) nonFlurryMessage;
}
}
}
答案 0 :(得分:1)
要使用深度链接,即使使用自动集成,也需要执行其他集成步骤。
<activity android:name=".DeeplinkTestActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- This will open deeplinks structured like - "testapp://deeplink/example" --> <data android:scheme="testapp" android:host="deeplink" android:pathPrefix="/example" /> </intent-filter> </activity>
@Override
public boolean onNotificationClicked(FlurryMessage flurryMessage) {
// NOTE: THIS METHOD WILL ONLY BE CALLED IF FLURRY HANDLED onNotificationReceived callback
// determine if you'd like to handle the clicked notification yourself or not
boolean handled = false;
// see if notification contains deeplink
if (flurryMessage.getAppData() != null && flurryMessage.getAppData().containsKey("deeplink")) {
String deeplink = flurryMessage.getAppData().get("deeplink");
// create the Intent
final Intent deeplinkIntent = new Intent(Intent.ACTION_VIEW);
deeplinkIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
deeplinkIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// set the data using your deeplink
deeplinkIntent.setData(Uri.parse(deeplink));
// add the FlurryMessage to extras
FlurryMessaging.addFlurryMessageToIntentExtras(deeplinkIntent, flurryMessage);
// make sure the deeplink resolves to an activity, then open it
if (deeplinkIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(deeplinkIntent);
// tell flurry you've handled the notification
handled = true;
}
}
return handled;
}
答案 1 :(得分:0)
只需在单击通知的方法上将此代码添加到您急促的消息传递侦听器中,并在您要加载URL或单击的位置上获取活动意图即可。
public boolean onNotificationClicked(FlurryMessage flurryMessage) {
// NOTE: THIS WILL ONLY BE CALLED IF FLURRY HANDLED onNotificationReceived callback
// determine if you'd like to handle the clicked notification yourself or not
boolean handled = false;
if (flurryMessage.getAppData() != null && flurryMessage.getAppData().containsKey("deeplink")) {
String deeplink = flurryMessage.getAppData().get("deeplink");
// create the Intent
Log.e("App data",""+flurryMessage.getAppData());
final Intent deeplinkIntent = new Intent(Intent.ACTION_VIEW);
// deeplinkIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// deeplinkIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// set the data using your deeplink
deeplinkIntent.setData(Uri.parse(deeplink));
// add the FlurryMessage to extras
Log.e("deeplinkurl", "" + Uri.parse(deeplink));
FlurryMessaging.addFlurryMessageToIntentExtras(deeplinkIntent, flurryMessage);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// make sure the deeplink resolves to an activity, then open it
if (intent.resolveActivity(getApplicationContext().getPackageManager())!=null){
intent.putExtra("deeplink", deeplink);
getApplicationContext().startActivity(intent);
// tell flurry you've handled the notification
handled = true;
}
}
return handled;
}