|
1 | 1 | package com.matter.tv.server;
|
2 | 2 |
|
| 3 | +import android.content.Intent; |
| 4 | +import android.net.Uri; |
3 | 5 | import android.os.Bundle;
|
| 6 | +import android.provider.Settings; |
| 7 | +import androidx.appcompat.app.AlertDialog; |
4 | 8 | import androidx.appcompat.app.AppCompatActivity;
|
5 | 9 | import androidx.fragment.app.Fragment;
|
6 | 10 | import com.google.android.material.bottomnavigation.BottomNavigationView;
|
7 | 11 | import com.matter.tv.server.fragments.ContentAppFragment;
|
8 | 12 | import com.matter.tv.server.fragments.QrCodeFragment;
|
9 | 13 | import com.matter.tv.server.fragments.TerminalFragment;
|
10 |
| -import com.matter.tv.server.service.MatterServant; |
11 | 14 | import java.util.LinkedHashMap;
|
12 | 15 |
|
13 | 16 | public class MainActivity extends AppCompatActivity {
|
@@ -41,16 +44,32 @@ protected void onCreate(Bundle savedInstanceState) {
|
41 | 44 | super.onCreate(savedInstanceState);
|
42 | 45 | setContentView(R.layout.activity_main);
|
43 | 46 |
|
44 |
| - // MainActivity is needed to launch dialog prompt |
45 |
| - // in UserPrompter |
46 |
| - MatterServant.get().setActivity(this); |
47 |
| - |
48 | 47 | BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
|
49 | 48 | bottomNavigationView.setOnItemSelectedListener(navListener);
|
50 | 49 |
|
51 | 50 | getSupportFragmentManager()
|
52 | 51 | .beginTransaction()
|
53 | 52 | .replace(R.id.fragment_container_view, new QrCodeFragment())
|
54 | 53 | .commit();
|
| 54 | + checkOverlayPermission(); |
| 55 | + } |
| 56 | + |
| 57 | + private void checkOverlayPermission() { |
| 58 | + if (!Settings.canDrawOverlays(this)) { |
| 59 | + AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 60 | + builder |
| 61 | + .setMessage("Allow permission to display over other apps") |
| 62 | + .setTitle("Request overlay permission") |
| 63 | + .setPositiveButton( |
| 64 | + "Ok", |
| 65 | + (dialog, which) -> { |
| 66 | + dialog.dismiss(); |
| 67 | + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); |
| 68 | + intent.setData(Uri.parse("package:" + getPackageName())); |
| 69 | + startActivity(intent); |
| 70 | + }) |
| 71 | + .create() |
| 72 | + .show(); |
| 73 | + } |
55 | 74 | }
|
56 | 75 | }
|
0 commit comments