mirror of
https://github.com/adolfintel/OpenPods.git
synced 2026-09-14 14:56:11 -04:00
Android 11 Workaround
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
@@ -51,6 +52,11 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".API30Activity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<receiver
|
||||
android:name=".Starter"
|
||||
android:enabled="true"
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.dosse.airpods;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class API30Activity extends AppCompatActivity {
|
||||
|
||||
private Timer timer;
|
||||
|
||||
@Override
|
||||
protected void onCreate (Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_api30);
|
||||
|
||||
// Allow button clicked, ask for permissions
|
||||
findViewById(R.id.allowBtn).setOnClickListener(view -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
|
||||
// Wait for permissions to be granted.
|
||||
// When they are granted, go to MainActivity.
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (ContextCompat.checkSelfPermission(API30Activity.this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
timer.cancel();
|
||||
startActivity(new Intent(API30Activity.this, MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}, 0, 100);
|
||||
|
||||
}
|
||||
|
||||
// Activity destroyed (or screen rotated). destroy the timer too
|
||||
@Override
|
||||
protected void onDestroy () {
|
||||
super.onDestroy();
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
@@ -62,7 +63,10 @@ public class IntroActivity extends AppCompatActivity {
|
||||
|
||||
if (ok) {
|
||||
timer.cancel();
|
||||
startActivity(new Intent(IntroActivity.this, MainActivity.class));
|
||||
if (Build.VERSION.SDK_INT >= 30)
|
||||
startActivity(new Intent(IntroActivity.this, API30Activity.class));
|
||||
else
|
||||
startActivity(new Intent(IntroActivity.this, MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.bluetooth.BluetoothManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.view.Menu;
|
||||
@@ -46,6 +47,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED)
|
||||
ok = false;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 30) if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_DENIED)
|
||||
ok = false;
|
||||
|
||||
if (ok) {
|
||||
Starter.startPodsService(getApplicationContext());
|
||||
//Warn MIUI users that their rom has known issues
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
@@ -417,6 +418,9 @@ public class PodsService extends Service {
|
||||
public void onCreate () {
|
||||
super.onCreate();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 30)
|
||||
startForeground(101, createNotification());
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
|
||||
intentFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
|
||||
@@ -582,4 +586,21 @@ public class PodsService extends Service {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
// Only for API30+
|
||||
// Strings are hardcodded for now because I'm too lazy
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private Notification createNotification () {
|
||||
|
||||
NotificationManager notManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel notChannel = new NotificationChannel("API30", "Background Notification", NotificationManager.IMPORTANCE_MIN);
|
||||
|
||||
notManager.createNotificationChannel(notChannel);
|
||||
|
||||
Notification.Builder builder = new Notification.Builder(this, "API30")
|
||||
.setSmallIcon(R.drawable.pod_case)
|
||||
.setContentText("Running in the background");
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dosse.airpods;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -22,7 +23,10 @@ public class Starter extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
public static void startPodsService (Context context) {
|
||||
context.startService(new Intent(context, PodsService.class));
|
||||
if (Build.VERSION.SDK_INT >= 30)
|
||||
context.startForegroundService(new Intent(context, PodsService.class));
|
||||
else
|
||||
context.startService(new Intent(context, PodsService.class));
|
||||
}
|
||||
|
||||
public static void restartPodsService (Context context) {
|
||||
@@ -31,7 +35,7 @@ public class Starter extends BroadcastReceiver {
|
||||
Thread.sleep(500);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
context.startService(new Intent(context, PodsService.class));
|
||||
startPodsService(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/padding_default">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/introImg1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="144dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:src="@drawable/icon"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/intro1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/intro1"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/intro2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/intro3" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/allowBtn"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/colorAccent"
|
||||
android:text="@string/settings" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
Reference in New Issue
Block a user