相关疑难解决方法(0)

没有调用Android OnNewIntent

我看到了几种方法,我尝试了一切,但无法使它工作.我不知道为什么它如此复杂,在文档中它看起来如此简单!我想通过通知触发OnNewIntent(用户在通知栏中单击它).

目前我已将Activity设置为singleTop

<activity
    android:name="-.-.-.MainMenuActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait" >
</activity>
Run Code Online (Sandbox Code Playgroud)

这是我创建通知的代码:

public void showNotification(String text, String componentId){
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Title")   
            .setAutoCancel(true)
            .setContentText(text);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainMenuActivity.class);
    if(!componentId.equalsIgnoreCase("")){                         
        resultIntent.putExtra("componentId", componentId);
    }   
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);
    mBuilder.setFullScreenIntent(resultPendingIntent, false);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());
}
Run Code Online (Sandbox Code Playgroud)

这是我的MainMenuActivity中的OnNewIntent方法:

@Override
protected void …
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification onnewintent

12
推荐指数
2
解决办法
9613
查看次数

关闭的应用程序未调用 Xamarin Android OnNewIntent

什么是工作

我已经使用以下 Xamarin 指南为 Xamarin Forms 应用程序的 Android 端实现了推送通知:

https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/

这很有效,我们正确地在应用程序运行时和在后台调用 OnNewIntent。然后我们调用我们的方法来处理推送通知的意图,一切都很好。

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    GoogleListenerService.ReceivedRemoteNotification(intent);
}
Run Code Online (Sandbox Code Playgroud)

问题是什么

如果我们关闭应用程序,触发推送通知,然后单击推送通知,应用程序似乎不会调用 OnNewIntent,而是会像单击应用程序图标(调用 OnCreate)一样启动应用程序。

尝试了什么

我尝试实施的主要解决方法概述如下:

  1. 未调用 Android OnNewIntent

Xamarin 只有一个 GetIntent 方法,需要字符串 URL 输入,并使用以下结果在空数据中。

Intent intent = new Intent(this, typeof(MainActivity));
Bundle data = intent.Extras;
Run Code Online (Sandbox Code Playgroud)
  1. 未调用 onNewIntent

在第二篇文章中,我们的意图服务、MainActivity.cs 文件和清单文件中 LaunchMode = SingleTop 的所有更改都没有导致行为发生任何变化。

编辑

推送通知总是被接收并且 OnMessageReceived 总是被调用,无论应用程序是在后台还是完全关闭。此外, OnNewIntent 在应用程序处于后台时接收挂起的意图,而不是在它关闭时。

this.Intent.Extras;
Run Code Online (Sandbox Code Playgroud)

始终显示为 null(当前位于 OnResume 方法中)。

android-intent xamarin.android xamarin

7
推荐指数
1
解决办法
2280
查看次数

我的onNewIntent没有打电话

创建一个集成Twitter的应用程序.我用这个教程:

http://blog.blundell-apps.com/sending-a-tweet/

package com.blundell.tut.ttt;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;

public class TweetToTwitterActivity extends Activity {

    private static final String TAG = "Blundell.TweetToTwitterActivity";

    /** Name to store the users access token */
    private static final String PREF_ACCESS_TOKEN = "accessToken";
    /** Name to store the users access token secret */
    private static final String PREF_ACCESS_TOKEN_SECRET …
Run Code Online (Sandbox Code Playgroud)

twitter android android-intent

5
推荐指数
1
解决办法
7773
查看次数

Firefox 或互联网浏览器的 FitBit oAuth 问题

我已将 Fitbit 与我的 Android 应用程序集成。我在使用 Chrome 浏览器连接 Fitbit 时没有遇到任何挑战,但当我尝试将其连接到 Firefox 或默认互联网浏览器时,它不起作用。

以下是我正在使用的意图过滤器:

<activity
            android:name=".MyActivity"
            android:launchMode="singleTop"
            android:resizeableActivity="false"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">

            <!-- FitBit intent filter to get call back data for Authentication API -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:scheme="myfitbit"/>
            </intent-filter>
        </activity>
Run Code Online (Sandbox Code Playgroud)

请建议。

browser authentication android oauth fitbit

4
推荐指数
1
解决办法
167
查看次数