Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Notifications 点击OneSignal的通知不会打开结果活动!!!!-安卓_Notifications_Onesignal - Fatal编程技术网

Notifications 点击OneSignal的通知不会打开结果活动!!!!-安卓

Notifications 点击OneSignal的通知不会打开结果活动!!!!-安卓,notifications,onesignal,Notifications,Onesignal,现在我知道在这方面有很多问题,但我一点运气都没有,我想在这里问个问题 我有一个应用程序,它只运行一个splashscreen,然后是一个MainActivity(这只是一个WebView) 现在我将其与OneSignal集成,用于接收推送通知 一切都很好,我的意思是当我通过onesignal网站发送到我的手机时,我会收到一个通知——但我面临的问题是,点击通知并不能获得我的结果活动(只是一个显示祝酒词的活动) 我的代码片段如下所示: splashscreen.java: public class

现在我知道在这方面有很多问题,但我一点运气都没有,我想在这里问个问题

我有一个应用程序,它只运行一个splashscreen,然后是一个MainActivity(这只是一个WebView) 现在我将其与OneSignal集成,用于接收推送通知

一切都很好,我的意思是当我通过onesignal网站发送到我的手机时,我会收到一个通知——但我面临的问题是,点击通知并不能获得我的结果活动(只是一个显示祝酒词的活动)

我的代码片段如下所示:

splashscreen.java:

public class splashscreen extends Activity {
@Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.splash);
      Thread splashThread = new Thread() {
         @Override
         public void run() {
            try {
               int waited = 0;
               while (waited < 5000) {
                  sleep(100);
                  waited += 100;
               }
            } catch (InterruptedException e) {
               // do nothing
            } finally {
               finish();
               Intent i = new Intent();
               i.setClassName("com.google",
                              "com.google.Main");
               startActivity(i);
            }
         }
      };
      splashThread.start();
   }
   @Override
   protected void onPause() {
       super.onPause();
       OneSignal.onPaused();
   }
   @Override
   protected void onResume() {
       super.onResume();
       OneSignal.onResumed();
   }
} 
ResultActivity.java:

    public class ResultActivity extends Activity {
        /** Called when the activity is first created. */
         @Override
         protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          /*
          ImageView image = new ImageView(this);
          image.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));
          setContentView(image);
          Toast.makeText(getApplicationContext(), 
            "Do Something NOW", 
            Toast.LENGTH_LONG).show();
            */
          super.onCreate(savedInstanceState);
          setContentView(R.layout.splash);
          }
    }
舱单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.google.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.google.permission.C2D_MESSAGE" />



    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />
        <activity android:name="com.onesignal.NotificationOpenedActivity"  android:theme="@android:style/Theme.NoDisplay">
            </activity>


        <receiver
         android:name="com.onesignal.GcmBroadcastReceiver"
         android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.google" />
            </intent-filter>
        </receiver>
        <service android:name="com.onesignal.GcmIntentService" />

        <activity android:name=".splashscreen" android:label="@string/app_name">
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name=".Main" android:label="@string/app_name" > 

        </activity>


        <activity android:name=".ResultActivity"
           android:label="@string/app_name"
           android:exported="true">
        </activity>



         <receiver
            android:name="com.google.OneSignalBackgroundDataReceiver"
            android:exported="false">
            <intent-filter>
            <action android:name="com.onesignal.BackgroundBroadcast.RECEIVE" />
            </intent-filter>
         </receiver>


    </application>

</manifest>

这是痛苦的修改一行,并测试它的设备上!因为onesignal只允许在设备中进行测试。请帮助或至少指导我如何调试


测试apk的设备:运行Lolipop的三星Galaxy S4。

OneSignal。必须从启动程序活动调用init
,您需要将其移动到您的
splashscreen
活动。这将使您的
ExampleNotificationOpenedHandler
在打开OneSignal通知时触发

确保还将调用复制到
OneSignal.onPaused()
OneSignal.onresume()编码到splashscreen活动中。在
onPuase()
onResume()方法中的每个活动中都需要调用这些函数。

查看此链接: (搜索页面中的“更改通知的打开操作””以转到确切的段落)

这是一个例子:

我没有时间仔细阅读您的代码,但它似乎有一些问题:

  • 您在错误的位置初始化了一个信号

    “确保您正在使用初始化OneSignal 在数据库中的onCreate方法中设置NotificationOpenedHandler 应用程序类。您需要从此回调调用startActivity”(OneSignal的文档)

  • 您不需要AndroidManifest中的任何其他接收者来捕捉意图并打开目标活动,OneSignal。通知OpenedHandler已处理此问题。但不要忘记这一行,以防止OneSignal打开您的启动器活动:

  • 
    

    我在我的应用程序中使用此解决方案,效果很好。因为事情就是这样。

    谢谢你的回复。我试过了,但没有成功。这次没有收到任何通知!!移动初始化代码在这里-请帮助!您的AlertBuilder应该出现在notificationReceived类中,而不是notificationOpened类中。然后覆盖notificationOpened类以打开您选择的任何活动(默认情况下,它会打开Main活动,您必须已经了解)
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.google"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="21" />
    
        <uses-permission android:name="android.permission.INTERNET" />
    
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="com.google.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.google.permission.C2D_MESSAGE" />
    
    
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    
            <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
            <activity android:name="com.onesignal.NotificationOpenedActivity"  android:theme="@android:style/Theme.NoDisplay">
                </activity>
    
    
            <receiver
             android:name="com.onesignal.GcmBroadcastReceiver"
             android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <category android:name="com.google" />
                </intent-filter>
            </receiver>
            <service android:name="com.onesignal.GcmIntentService" />
    
            <activity android:name=".splashscreen" android:label="@string/app_name">
                    <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
    
            <activity android:name=".Main" android:label="@string/app_name" > 
    
            </activity>
    
    
            <activity android:name=".ResultActivity"
               android:label="@string/app_name"
               android:exported="true">
            </activity>
    
    
    
             <receiver
                android:name="com.google.OneSignalBackgroundDataReceiver"
                android:exported="false">
                <intent-filter>
                <action android:name="com.onesignal.BackgroundBroadcast.RECEIVE" />
                </intent-filter>
             </receiver>
    
    
        </application>
    
    </manifest>