没有接收器包错误 - Pushbots通知

时间:2016-07-02 21:46:19

标签: android android-fragments push-notification google-cloud-messaging

我正在尝试在Android应用中添加Pushbots Notification。但是这一行在MainActivity.java

中提供了错误Pushbots.sharedInstance().init(this);

该应用有标签布局(片段)

如果应用程序中没有片段

,则相同的代码可以正常工作

logcat的 No receiver for package com.akapoor.kiittimetabletest1

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbarButton = (Button) findViewById(R.id.toolBarButton);

    Pushbots.sharedInstance().init(this);

    //
    if (ContextCompat.checkSelfPermission(MainActivity.this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(MainActivity.this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }

    //
    toolbar = (Toolbar) findViewById(R.id.toolBar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.holiday_list:
                    Intent intent = new Intent(MainActivity.this, HolidayList.class);
                    startActivity(intent);
                    drawerLayout.closeDrawers();
                    break;
            }
            return true;
        }
    });

    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("MONDAY"), "MONDAY");
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("TUESDAY"), "TUESDAY");
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("WEDNESDAY"), "WEDNESDAY");
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("THURSDAY"), "THURSDAY");
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("FRIDAY"), "FRIDAY");
    viewPagerAdapter.addFragments(TimeTableFragment.newInstance("SATURDAY"), "SATURDAY");
    viewPager.setAdapter(viewPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}

清单

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

         

<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="com.akapoor.kiittimetabletest1.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.akapoor.kiittimetabletest1.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="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.akapoor.kiittimetabletest1.MESSAGE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity android:name=".ClassDataProvider">
    </activity>
    <activity android:name=".HolidayList"></activity>
    <activity android:name=".AcademicCalendar"></activity>
</application>

<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.android.c2dm.intent.RECEIVE" />
        <!-- Receives the registration id. -->
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.akapoor.kiittimetabletest1" />
    </intent-filter>
</receiver>
<receiver android:name="com.pushbots.push.DefaultPushHandler" />

<service android:name="com.pushbots.push.GCMIntentService" />
</manifest>

1 个答案:

答案 0 :(得分:0)

您似乎缺少these

<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.android.c2dm.intent.RECEIVE" />
        <!-- Receives the registration id. -->
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.example.sampleapp" />
    </intent-filter> </receiver> 
<receiver android:name="com.pushbots.push.DefaultPushHandler" /> 
<service android:name="com.pushbots.push.GCMIntentService" />