FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AndroidTutorialForBeginners/permission.java at master · Progzizo/AndroidTutorialForBeginners · GitHub
Progzizo
/
AndroidTutorialForBeginners
Public
forked from
hussien89aa/AndroidTutorialForBeginners
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
AndroidTutorialForBeginners
/
permission.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (68 loc) · 3.04 KB
Breadcrumbs
AndroidTutorialForBeginners
/
permission.java
Copy path
File metadata and controls
88 lines (68 loc) · 3.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Sms Permiison
/*
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
*/
//access to permsions
void
CheckUserPermsions
(){
if
(
Build
.
VERSION
.
SDK_INT
>=
23
){
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
android
.
Manifest
.
permission
.
ACCESS_FINE_LOCATION
) !=
PackageManager
.
PERMISSION_GRANTED
){
requestPermissions
(
new
String
[]{
android
.
Manifest
.
permission
.
ACCESS_FINE_LOCATION
},
REQUEST_CODE_ASK_PERMISSIONS
);
return
;
}
}
getLastLocation
();
// init the contact list
}
//get acces to location permsion
final
private
int
REQUEST_CODE_ASK_PERMISSIONS
=
123
;
@
Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
) {
switch
(
requestCode
) {
case
REQUEST_CODE_ASK_PERMISSIONS
:
if
(
grantResults
[
0
] ==
PackageManager
.
PERMISSION_GRANTED
) {
getLastLocation
();
// init the contact list
}
else
{
// Permission Denied
Toast
.
makeText
(
this
,
"your message"
,
Toast
.
LENGTH_SHORT
)
.
show
();
}
break
;
default
:
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
}
}
//Get last location
public
void
getLastLocation
(){
LocationManager
locationManager
= (
LocationManager
)
getSystemService
(
LOCATION_SERVICE
);
Location
myLocation
=
locationManager
.
getLastKnownLocation
(
LocationManager
.
GPS_PROVIDER
);
if
(
myLocation
==
null
)
{
myLocation
=
locationManager
.
getLastKnownLocation
(
LocationManager
.
PASSIVE_PROVIDER
);
}
}
//read contact list
public
void
getContactList
(){
ArrayList
<
ListItem
>
list_contact
=
new
ArrayList
<
ListItem
>() ;
Cursor
cursor
=
getContentResolver
().
query
(
ContactsContract
.
CommonDataKinds
.
Phone
.
CONTENT_URI
,
null
,
null
,
null
,
null
);
while
(
cursor
.
moveToNext
()) {
String
name
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
ContactsContract
.
CommonDataKinds
.
Phone
.
DISPLAY_NAME
));
String
phoneNumber
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
ContactsContract
.
CommonDataKinds
.
Phone
.
NUMBER
));
list_contact
.
add
(
new
ListItem
(
name
,
phoneNumber
));
}
}
public
class
ListItem
{
public
String
Title
;
public
String
phoneNumber
;
public
ListItem
(
String
Title
,
String
phoneNumber
)
{
this
.
Title
=
Title
;
this
.
phoneNumber
=
phoneNumber
;
}
}
//ratinal permmison
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
thisActivity
,
android
.
Manifest
.
permission
.
READ_CONTACTS
)) {
}
Back
|
FazBrowse Home
|
New Git URL