Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

android - open specific page using firebase api

I am sending push notification to devices using below code.

      var nTitle = "New message from " + $rootScope.clients_firstName;
      var to = "DeviceToken is here";
      var notification = {
        'title': nTitle,
        //'body': 'Click here to more details...',
        'icon': 'firebase-logo.png',
        'click_action': 'openapp'
      };

      var key = 'your key';
      fetch('https://fcm.googleapis.com/fcm/send', {
      'method': 'POST',
        'headers': {
        'Authorization': 'key=' + key,
        'Content-Type': 'application/json'
      },
      'body': JSON.stringify({
        'notification': data,
        'to': to
      })
      }).then(function(response) {
        //console.log("res ", response);
      }).catch(function(error) {
        console.error("err ", error);
     });

push notification sends on device successfully.

But when I click on notification the specific page should be open.

For example 'click_action' : 'openapp/somepage'

Then the 'somepage' should be open when I click on pushnotification.

AndroidManifest.xml

<activity android:name="MainActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">

        <intent-filter>
            <action android:name="openapp" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>

</activity>

My project structure

--platforms
--plugins
--www
  --app
    --about
      --about.html
      --about.ctrl.js
    --product
      --product.html
      --product.ctrl.js
  --css
  --js
  --lib
  index.html

If I click on notification and I want to open product or about page then what I have to do?

What is wrong here? Please tell me the proper solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...