迁移通知问题不起作用

时间:2018-10-14 13:35:14

标签: android android-gradle

我即将将应用程序迁移到Android8。将SDK版本从25更新到26后,没有关于我的应用程序的通知。

我的应用程序是Instagram图像和视频下载应用程序。但是,当用户使用Instagram并从图像或视频复制链接时,系统会发出通知以下载图像。迁移到Android 8时,没有通知会下载图像或视频...

请帮助我!这真的很重要。

这是我的Project Gradle文件:

deplacer()

这是我的App Gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.novoda:bintray-release:0.3.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.google.gms:google-services:3.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        google()
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的BroadcastService

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
    }


    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}



android {
    compileSdkVersion 25
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.instdownload"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 10
        versionName "1.0.9"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'


            lintOptions {
                checkReleaseBuilds false
                // Or, if you prefer, you can continue to check for errors in release builds,
                // but continue the build even when errors are found:
                abortOnError false
            }
        }
    }

}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.1.0'
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.github.devlight.navigationtabstrip:navigationtabstrip:1.0.4'
    compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
    compile 'com.google.android.gms:play-services-ads:15.0.1'
    compile 'com.google.firebase:firebase-ads:15.0.1'
    compile 'com.google.firebase:firebase-core:15.0.2'
    compile 'com.github.paolorotolo:appintro:3.4.0'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'
    compile 'org.jsoup:jsoup:1.10.2'
    compile 'com.google.ads.mediation:mopub:4.20.0.0'
    compile 'io.github.kobakei:ratethisapp:1.2.0'
    compile('com.mikepenz:materialdrawer:5.8.2@aar') {
        transitive = true


    }
    compile('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:answers:1.4.1@aar') {
        transitive = true;
    }
    compile('com.mopub:mopub-sdk:4.20.0@aar') {
        transitive = true
    }

}
apply plugin: 'com.google.gms.google-services'

这里是我的下载服务

package com.instdownload;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

public class Broadcastservice extends Service {

    ClipboardManager clipBoard;
    NotificationCompat.Builder mBuilder;
    NotificationManager mNotificationManager;
    private final BroadcastReceiver close_notification = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
            nMgr.cancel(10245);
        }
    };

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        registerReceiver(close_notification, new IntentFilter("close_notification"));
        clipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipBoard.addPrimaryClipChangedListener(new ClipboardListener());
        return START_STICKY;
    }

    @SuppressLint("NewApi")
    private class ClipboardListener implements ClipboardManager.OnPrimaryClipChangedListener {
        public void onPrimaryClipChanged() {
            Log.i("service", clipBoard.getText().toString());
            final SharedPreferences appstart = getSharedPreferences("appstart", MainActivity.MODE_PRIVATE);
            SharedPreferences.Editor editor1 = appstart.edit();
            editor1.putInt("flag", 1);
            editor1.putString("link", clipBoard.getText().toString());
            editor1.commit();
            updateNotification();

        }
    }


    private void updateNotification() {
        final SharedPreferences appstart = getSharedPreferences("appstart", MainActivity.MODE_PRIVATE);
        if (appstart.getInt("flag", 0) == 1 && appstart.getString("link", "null").contains("instagram")) {
            Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
            notificationIntent.setAction(Intent.ACTION_MAIN);
            notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
            mBuilder = new NotificationCompat.Builder(getApplicationContext());
            Notification notification = mBuilder
                    .setSmallIcon(R.drawable.ic_notify_main)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .setContentTitle(getResources().getString(R.string.app_name))
                    .setWhen(0)
                    .setAutoCancel(true)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setContentIntent(resultPendingIntent)
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setContentText(getResources().getString(R.string.download))
                    .build();

            mNotificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(10245, notification);
        }
    }


    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
        nMgr.cancel(10245);
        super.onDestroy();
    }

}

请帮助我解决问题,我很拼命

0 个答案:

没有答案