2

私のAndroid Appプッシュ通知に問題があります。 プッシュ通知が空白で、アプリ名のみが表示されています。メッセージフィールドは空です。Android Firebaseプッシュ通知空白(テキストなし)

image http://www.angelweb.in/snapshot.png

のAndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="in.myappname.apk" > 
     <!-- GCM connects to Google Services. --> 
     <uses-permission android:name="android.permission.INTERNET" /> 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
     <!-- GCM requires a Google account. --> 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
     <uses-permission android:name="android.permission.WAKE_LOCK" /> 
     <permission android:name="in.myappname.apk.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
     <uses-permission android:name="in.myappname.apk.permission.C2D_MESSAGE" /> 
     <!-- This app has permission to register and receive dataf message. --> 
     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
     <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 
      <activity 
       android:name=".MainActivity" 
       android:label="@string/app_name" > 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
       <intent-filter> 
        <action android:name="in.myappname.apk.MESSAGE" /> 
        <category android:name="android.intent.category.DEFAULT" /> 
       </intent-filter> 
      </activity> 
      <receiver 
       android:name="com.pushbots.google.gcm.GCMBroadcastReceiver" 
       android:permission="com.google.android.c2dm.permission.SEND" > 
       <intent-filter> 
        <!-- Receives the actual messages. --> 
        <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
        <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
        <!-- Receives the registration id. --> 
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
        <category android:name="in.myappname.apk" /> 
       </intent-filter> 
      </receiver> 
      <receiver android:name="com.pushbots.push.DefaultPushHandler" /> 
      <service android:name="com.pushbots.push.GCMIntentService" /> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 

     </application> 
    </manifest> 

MainActivity.java

package in.myappname.apk; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import com.pushbots.push.Pushbots; 

public class MainActivity extends Activity { 

    private WebView mWebView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Pushbots.sharedInstance().init(this); 

     mWebView = (WebView) findViewById(R.id.activity_main_webview); 

     // Force links and redirects to open in the WebView instead of in a browser 
     mWebView.setWebViewClient(new WebViewClient()); 

     // Enable Javascript 
     WebSettings webSettings = mWebView.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 

     // Use remote resource 
     mWebView.loadUrl("http://myappurl.in"); 

     // Stop local links and redirects from opening in browser instead of WebView 
     mWebView.setWebViewClient(new MyAppWebViewClient()); 

     // Use local resource 
     // mWebView.loadUrl("file:///android_asset/www/index.html"); 
    } 

    // Prevent the back-button from closing the app 
    @Override 
    public void onBackPressed() { 
     if(mWebView.canGoBack()) { 
      mWebView.goBack(); 
     } else { 
      new AlertDialog.Builder(this) 
        .setIcon(android.R.drawable.ic_dialog_alert) 
        .setTitle("Alert") 
        .setMessage("Are you sure you want exit?") 
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() 
        { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          finish(); 
         } 

        }) 
        .setNegativeButton("No", null) 
        .show(); 
     } 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

MyAppWebViewClient.java

package in.myappnam.apk; 

import android.content.Intent; 
import android.net.Uri; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MyAppWebViewClient extends WebViewClient { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if (Uri.parse(url).getHost().endsWith("myappname.in")) { 
      return false; 
     } 

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     view.getContext().startActivity(intent); 
     return true; 
    } 
} 

レイアウト - > activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="in.myappname.apk.MainActivity"> 

     <WebView 
      android:id="@+id/activity_main_webview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </RelativeLayout> 

値 - > pushbots.xml

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
     <!-- Pushbots Application ID --> 
     <string name="pb_appid">xxxxxxxxxMypushbotskey</string> 
     <!-- Project Number in Google console --> 
     <string name="pb_senderid">xxxxxxxxxxMysenderid</string> 
     <!-- Pushbots Log Level log Tag "PB2" --> 
     <string name="pb_logLevel">DEBUG</string> 
    </resources> 

値 - >のstrings.xml

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 

     <string name="app_name">My App Name</string> 
     <string name="hello_world">My Alternative tag</string> 
     <string name="action_settings">Settings</string> 

    </resources> 

答えて

0

変更

<service android:name="com.pushbots.push.GCMIntentService" /> 
     <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 

<service android:name="com.pushbots.push.GCMIntentService" > 
     <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
</service> 

と投稿してくださいよu GCMBroadcastReceiverクラス

+0

GCMBroadcastReceiverクラスの追加方法を教えてください。どのファイルを追加するのですか?私はまだ初心者です –

+0

Firebase Cloud Messagingを試してみてください。これにはさらに多くの機能が含まれており、GCMよりはるかに簡単です。[こちら](https://firebase.google.com/docs/cloud-messaging/#how_does_it_work)と[this](https://firebase.google .com/docs/android/setup) –

+0

ドキュメントに従ってください。 –

関連する問題