Я собираюсь перенести мое приложение на Android 8. После обновления версии SDK с 25 на 26 больше не было уведомлений о моем приложении.
Мое приложение - это приложение для загрузки изображений и видео из Instagram,Но когда пользователь заходит в Instagram и копирует ссылку с изображения или видео, появляется уведомление о загрузке изображения.С переходом на Android 8 не приходит уведомление о загрузке изображения или видео ...
Пожалуйста, помогите мне!Это действительно важно.
Вот мой файл проекта 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
}
А вот мой файл приложения Gradle:
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'
Вот мой BroadcastService
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();
}
}
А вот мой Сервис загрузки
package com.instdownload;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
public class DownloadService extends Service {
File VideoDirectory, file;
String appname, video_fname;
NotificationManager mNotificationManager;
HashMap<Integer, NotificationCompat.Builder> notificationHashMap = new HashMap<>();
URLConnection conection;
InputStream input;
OutputStream output;
int lenghtOfFile;
Boolean Iscancelled = false;
DownloadFileFromURL download;
public static final String A3 = "679f46b";
private final BroadcastReceiver cancel_download = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (download.getStatus() == AsyncTask.Status.RUNNING) {
download.cancel(true);
}
File file = new File(Environment.getExternalStorageDirectory(), AllStaticData.RootDirectory + "/" + AllStaticData.VideoDirectory + "/");
Iscancelled = true;
finishedDownload(3333);
Toast.makeText(getApplicationContext(), "Download cancelled!", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
Log.i("Unable", "" + e);
Toast.makeText(getApplicationContext(), "Unable to stop download!", Toast.LENGTH_LONG).show();
}
}
};
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
}
private String getpreferences(String key) {
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("pref", 0);
return sharedPreferences.getString(key, "0");
}
private void SavePreferences(String key, String value) {
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("pref", 0);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
appname = getResources().getString(R.string.app_name);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
registerReceiver(cancel_download, new IntentFilter("cancel_download"));
try {
video_fname = intent.getStringExtra("video_fname");
download = new DownloadFileFromURL();
download.execute(intent.getStringExtra("url"), video_fname);
SavePreferences("video_fname", intent.getStringExtra("video_fname"));
SavePreferences("url", intent.getStringExtra("url"));
SavePreferences("thumb", intent.getStringExtra("thumb"));
} catch (NullPointerException e) {
Log.i("", "" + e);
video_fname = getpreferences("video_fname");
download = new DownloadFileFromURL();
download.execute(getpreferences("url"), video_fname);
}
return START_STICKY;
}
private class DownloadFileFromURL extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
setNotification(video_fname, "Downloading video...", 3333);
}
@Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
conection = url.openConnection();
conection.connect();
lenghtOfFile = conection.getContentLength();
input = new BufferedInputStream(url.openStream(), 8192);
VideoDirectory = new File(Environment.getExternalStorageDirectory(), AllStaticData.RootDirectory + "/" + AllStaticData.VideoDirectory + "/");
if (!VideoDirectory.exists()) {
VideoDirectory.mkdirs();
}
file = new File(VideoDirectory, video_fname);
output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.i("progress", "" + progress[0]);
Intent broadcast1 = new Intent("update_progress");
broadcast1.putExtra("progress", Integer.parseInt(progress[0]));
broadcast1.putExtra("path", file.getAbsolutePath());
broadcast1.putExtra("thumb", getpreferences("thumb"));
broadcast1.putExtra("strdata", getpreferences("url"));
sendBroadcast(broadcast1);
}
@Override
protected void onPostExecute(String file_url) {
if (!Iscancelled) {
Intent broadcast1 = new Intent("update_progress");
broadcast1.putExtra("progress", (int) 100);
broadcast1.putExtra("path", file.getAbsolutePath());
sendBroadcast(broadcast1);
finishedDownload(3333);
}
}
}
private void setNotification(String title, String content, int notifyId) {
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);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext());
Notification notification = mBuilder
.setContentTitle(title)
.setContentText(content)
.setContentIntent(resultPendingIntent)
.setSmallIcon(android.R.drawable.stat_sys_download)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
mNotificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(9997, notification);
notificationHashMap.put(notifyId, mBuilder);
}
private void finishedDownload(int notifyId) {
try {
notificationHashMap.get(notifyId).setContentText("Finished");
notificationHashMap.get(notifyId).setSmallIcon(android.R.drawable.stat_sys_download_done);
mNotificationManager.notify(notifyId, notificationHashMap.get(notifyId).build());
mNotificationManager.cancel(notifyId);
unregisterReceiver(cancel_download);
} catch (Exception e) {
Log.i("", "" + e);
}
Intent iii = new Intent(getApplicationContext(), DownloadService.class);
stopService(iii);
}
@Override
public void onDestroy() {
mNotificationManager.cancel(9997);
super.onDestroy();
}
}
ПОЖАЛУЙСТА, ПОМОГИТЕ МНЕ УСТАНОВИТЬ ПРОБЛЕМУ, я в отчаянии