Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request notification permission for API 33 #31

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<queries>
<intent>
Expand Down Expand Up @@ -50,4 +51,4 @@
android:enabled="true" />
</application>

</manifest>
</manifest>
17 changes: 14 additions & 3 deletions app/src/main/java/xtr/keymapper/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package xtr.keymapper.activity;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import xtr.keymapper.editor.EditorService;
import xtr.keymapper.R;
import xtr.keymapper.Server;
import xtr.keymapper.TouchPointer;
import xtr.keymapper.databinding.ActivityMainBinding;
import xtr.keymapper.editor.EditorService;
import xtr.keymapper.fragment.SettingsFragment;
import xtr.keymapper.server.InputService;

Expand Down Expand Up @@ -71,6 +74,7 @@ public void startPointer(){
setButtonActive(binding.controls.startPointer);
binding.controls.startPointer.setText(R.string.stop);
binding.controls.startPointer.setOnClickListener(v -> stopPointer());
requestNotificationPermission();
}
}

Expand Down Expand Up @@ -114,6 +118,13 @@ private void checkOverlayPermission(){
}
}

private void requestNotificationPermission(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (!(checkSelfPermission(POST_NOTIFICATIONS) ==
PERMISSION_GRANTED)) requestPermissions(new String[]{POST_NOTIFICATIONS}, 0);
}
}

@Override
protected void onDestroy() {
if (pointerOverlay != null)
Expand Down Expand Up @@ -191,4 +202,4 @@ public void onServiceConnected(ComponentName className,
public void onServiceDisconnected(ComponentName arg0) {
}
};
}
}