get location

This commit is contained in:
Page Asgardius 2022-10-28 14:40:30 -07:00
parent 55219b55ef
commit 09a570db4a
3 changed files with 50 additions and 0 deletions

View file

@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="asgardius.page.r3forumtest">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application

View file

@ -1,18 +1,30 @@
package asgardius.page.r3forumtest;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.READ_PHONE_NUMBERS;
import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_SMS;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
@ -42,11 +54,23 @@ public class MainScreen extends AppCompatActivity {
Button logout, notification, edit, delete;
LinearLayout adminactions;
Uri crashsound;
TextView textView;
TelephonyManager telephonyManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
textView = findViewById(R.id.location);
telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, READ_SMS) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{READ_SMS, READ_PHONE_NUMBERS, READ_PHONE_STATE,ACCESS_FINE_LOCATION}, 100);
} else {
textView.setText(""+telephonyManager.getCellLocation());
}
username = getIntent().getStringExtra("username");
id = (TextView) findViewById(R.id.username);
email = (TextView) findViewById(R.id.email);
@ -244,4 +268,21 @@ public class MainScreen extends AppCompatActivity {
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
}
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 100:
if (ActivityCompat.checkSelfPermission(this, READ_SMS) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return;
} else {
textView.setText(""+telephonyManager.getCellLocation());
}
}
}
}

View file

@ -103,5 +103,12 @@
tools:ignore="MissingConstraints" />
</LinearLayout>
<TextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="25sp" />
</LinearLayout>