Screen Overlay Detected Android - android

I found the below issue of Screen Overlay detected when click permission in Motog3 marshmallow mobile.
i found many solution over internet search everywhere, you can check below:
Remove esfile explorer
https://www.youtube.com/watch?v=QHidevTDrYI
Screen overlay detected blocks Android permissions
https://android.stackexchange.com/questions/148260/screen-overlay-detected-what-is-the-problem
https://forums.androidcentral.com/android-6-0-marshmallow/682802-screen-overlay-detected-what-can-i-do.html
https://www.howtogeek.com/271519/how-to-fix-the-screen-overlay-detected-error-on-android/
https://github.com/MohammadAdib/Roundr/issues/10
Android marshmallow : Galaxy Note 4 Screen Overlay Detected
etc. many more.
If i don't call permission below then no problem.
Therefore if anyone want to give the best solution then please share.
Please before mentioning it duplicate, i want proper solution for it.
Feel free to ask any information or code i'm sharing some code also.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.psm">
<!---->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".SplashScreen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.nippon.registration.Registration"
></activity>
</application>
</manifest>
Permission code in Mainactivity.java
checkAndRequestPermissions(); //called in oncreate() of activity
private boolean checkAndRequestPermissions() {
try {
int permissionWriteEXTERNALSTORAGE = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
int PermissionCamera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA);
List<String> listPermissionsNeeded = new ArrayList<>();
if (permissionWriteEXTERNALSTORAGE != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (PermissionCamera != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(android.Manifest.permission.CAMERA);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 1);
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
Thanks in advance, for perfect solution.

finally i got solution for above problem of Screen Overlay Detected
by removing below code which i was using for testing memory usage in app:
final Runtime runtime = Runtime.getRuntime();
final long usedMemInMB=(runtime.totalMemory() - runtime.freeMemory()) / 1048576L;
final long maxHeapSizeInMB=runtime.maxMemory() / 1048576L;
final long availHeapSizeInMB = maxHeapSizeInMB - usedMemInMB;
Toast.makeText(getApplicationContext(),String.valueOf(usedMemInMB+" "+ maxHeapSizeInMB+" "+ availHeapSizeInMB), Toast.LENGTH_LONG).show();
Thanks for everyone support!

Related

Request permission for Custom Permission

I learned to define my own custom permission with different level (normal, signature, dangerous) a few hours ago. Then I followed the android documentation and this question's answered by Yury to test it in real. First I made the permission level normal and after clicking button from first activity, I can access the second activity. But when I set it dangerous, I failed to access the second activity. I got
Security exception - permission denial everytime. Then I go to 'Permission' section in the app settings and see my custom permission is turned off. I turn it on and then can access the activity.
But my question is how I can request this permission like other dangerous permission defined by android system and show dialog and grant it without going to the permission section in app settings. I know how to access permission with -
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted
}
But the problem is android's default permissions are defined in Manifest.permission.READ_CONTACTS but how I define my custom permission with that.
My code is given below.
PermissionTestServerActivity (First activity):-
public class PermissionTestServerActivity extends Activity {
private static final String TAG = "PermissionTestServerActivity";
/** Called when the activity is first created. */
Button btnTest;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnTest = (Button) findViewById(R.id.btnTest);
btnTest.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "Button pressed!");
Intent in = new Intent();
in.setAction("com.testpackage.permissiontestclient.MyAction");
in.addCategory("android.intent.category.DEFAULT");
startActivity(in);
}
});
}
}
And its manifest :-
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="com.testpackage.mypermission"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".PermissionTestServerActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
PermissionTestClient's manifest (Second activity):-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testpackage.permissiontestclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<permission android:name="com.testpackage.mypermission" android:label="my_permission" android:protectionLevel="dangerous"></permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:permission="com.testpackage.mypermission"
android:name=".PermissionTestClientActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.testpackage.permissiontestclient.MyAction" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

Android: Getting device location during runtime

I'm developing an app where I want to get the lat,lng of the user's device.I found that I need Access_Fine_Location permission as well as Access_Coarse_Location, I know that I should ask for them during runtime as well as including them in my AndroidManifest.xml, but the app only asks me for the permission ACCESS_COARSE_LOCATION, and ignores asking about ACCESS_FINE_LOCATION.
Here's my code
private boolean checkAndRequestPermissions(){
int permissionReadContacts = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
int locationPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
int locationPermission2 =ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
List<String> listPermissionsNeeded = new ArrayList<String>();
if (locationPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (locationPermission2 != PackageManager.PERMISSION_GRANTED) {
Log.i("addingPerm","addingPerm");
listPermissionsNeeded.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if (permissionReadContacts != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.READ_CONTACTS);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}
and here's the callback:
#Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
String TAG = "sonder.SplashActivity";
Log.d(TAG, "Permission callback called-------");
switch (requestCode) {
case REQUEST_ID_MULTIPLE_PERMISSIONS: {
Map<String, Integer> perms = new HashMap<String, Integer>();
// Initialize the map with both permissions
perms.put(Manifest.permission.ACCESS_COARSE_LOCATION, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.READ_CONTACTS, PackageManager.PERMISSION_GRANTED);
// Fill with actual results from user
if (grantResults.length > 0) {
for (int i = 0; i < permissions.length; i++)
perms.put(permissions[i], grantResults[i]);
// Check for both permissions
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
UserData.setLocation(LocListener.getLat() + "," + LocListener.getLon());
Log.i("aaaaaaaaaa", "aaaaaaaaaa");
Log.i("" + LocListener.getLat(), "" + LocListener.getLon());
if (perms.get(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Log.i("Ahmed", "Ahmed");
Log.d("Permissions", "location services permission granted");
FacebookSdk.sdkInitialize(getApplicationContext());
Thread myThread = new Thread() {
#Override
public void run() {
try {
Log.i("May", "May");
sleep(300);
Intent intent = new Intent(getApplicationContext(), setup_activity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
} else {
//If permissions are denied
Log.d(TAG, "Location permission not granted ask again");
Intent intent = new Intent(getApplicationContext(), setup_activity.class);
startActivity(intent);
finish();
}
}
}
}
}
}
And here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permissions.NETWORK_ACCESS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permissions.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permissions.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.location.gps"
android:required="true"/>
<uses-feature android:name="android.hardware.location.network"
android:required="true"/>
<uses-feature
android:name="android.hardware.location"
android:required="true" />
<application
android:name=".utils.orientation_adj"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:roundIcon="#drawable/icon"
android:theme="#style/AppTheme"
android:largeHeap="true">
<activity
android:name=".home.splashscreen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".home.main_activity"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity android:name=".drawer.drawer_preferences"></activity>
<activity
android:name=".setup.edit_profile_tags"
android:theme="#style/DialogNoTitle"></activity>
<activity
android:name=".setup.setup_activity"
android:theme="#style/AppTheme">
</activity>
<activity android:name=".setup.backend_test"></activity>
<activity
android:name=".drawer.drawer_view_profile"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".drawer.drawer_settings"
android:theme="#style/Switch"></activity>
<activity android:name=".drawer.drawer_help"></activity>
<activity android:name=".setup.not_available_in_your_country"
android:theme="#style/AppTheme.NoActionBar">
<!--Add intent filter here-->
</activity>
<activity android:name=".setup.readiness"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity android:name=".setup.locationPermission"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<service
android:name=".utils.GenericAccountService"
android:exported="false">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="43a4edcd41e180a4beca5aae4040115cfc1b52fe" />
</application>
Three of your <uses-permission> elements have incorrect permission names. There are no Android SDK permissions that begin with android.permissions (note the s on the end). So, for example, you need to change android.permissions.ACCESS_FINE_LOCATION to android.permission.ACCESS_FINE_LOCATION. You cannot request a runtime permission if the <uses-permission> element is missing or invalid.

Android security exception for permission listed in manifest file

The user of the app I am developing is required to share the location during the registration process. Clicking the "Locate me" button should get the GPS coordinates ( or whatever is provided, I don't know yet ).
When the button is clicked, I get this error message:
java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
Which, from what I understand, has to do with listing the permission in the manifest file. But the permission is there.
The threads with similar issues I found suggest uninstalling the app from the device I am testing it on, cleaning and rebuilding the project. I did all that, but the problem persists. I must be missing something else, possibly very obvious. Any ideas?
Thanks!
This is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest package = "com.iskillu.iskillu"
xmlns:android = "http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup = "true"
android:icon = "#mipmap/ic_launcher"
android:label = "#string/app_name"
android:supportsRtl = "true"
android:theme = "#style/AppTheme">
<activity
android:name = ".MainActivity"
android:label = "#string/app_name"
android:theme = "#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name = "com.google.android.gms.version"
android:value = "#integer/google_play_services_version" />
<activity
android:name = ".JoinActivity"
android:label = "#string/title_activity_join"
android:theme = "#style/AppTheme.NoActionBar">
</activity>
<activity
android:name = ".LoginActivity"
android:label = "#string/title_activity_login"
android:theme = "#style/AppTheme.NoActionBar">
</activity>
<activity android:name = ".RegistrationSuccessfulActivity">
<intent-filter>
<action android:name = "android.intent.action.VIEW" />
<category android:name = "android.intent.category.DEFAULT" />
<category android:name = "android.intent.category.BROWSABLE" />
<data android:scheme = "http" />
<data android:scheme = "https" />
<data android:host = "www.iskillu.com" />
<data android:host = "iskillu.com" />
</intent-filter>
</activity>
<activity android:name = ".presentation.PresentationActivity">
</activity>
</application>
</manifest>
This is the method which throws the exception when executed:
public void getGpsLocation ( View view )
{
LocationManager locationManager = ( LocationManager ) this.getSystemService( Context.LOCATION_SERVICE );
boolean isProviderEnabled = locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER);
if ( ! locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER) )
{
Toast.makeText ( this.getApplicationContext (), R.string.enable_gps, Toast.LENGTH_LONG ).show () ;
}
else
{
try {
Location myLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (myLocation != null)
{
Log.d("TAG", "Not null");
}
else
{
Log.d("TAG", "NULL");
}
}
catch (SecurityException se) {
Log.d("TAG", "SE CAUGHT");
se.printStackTrace();
}
}
}
Starting from Android M you will need to request the permission at run time Requesting Permissions at Run Time

Run Android app in different devices

I run my application in two different Android devices. The first is an Arnova 9 G2 Tablet and the second a Sony Xperia P. In the Arnova tablet my application executed successfully, but in the Sony Xperia P phone, the LogCat displays me the following error:
/data/data/com.example.androidjnetpcaptest/interfaces: open failed:
EACCES (Permission denied) FATAL EXCEPTION: main
java.lang.NullPointerException at
com.example.androidjnetpcaptest.InterfacesFragment.onCreateView(InterfacesFragment.java:35)
My manifest XML file is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidjnetpcaptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.pemission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.Default" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".InformationsActivity"
android:theme="#android:style/Theme.Holo"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.Default" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And the InterfacesFragment class is:
public class InterfacesFragment extends Fragment
{
private Scanner inputStream = null;
private TextView interfacesTextView = null;
#Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
{
try
{
inputStream = new Scanner( new FileInputStream( "/data/data/com.example.androidjnetpcaptest/interfaces" ) );
}
catch ( FileNotFoundException e )
{
Log.e( "InterfacesFragment_ERROR: ", e.getMessage() );
}
String lines = "";
while ( inputStream.hasNextLine() )
{
lines = lines + inputStream.nextLine() + "\n";
}
inputStream.close();
final ProgressDialog ringProgressDialog = ProgressDialog.show( getActivity(), "Please wait ...", "Finding interfaces ...", true );
ringProgressDialog.setCancelable( true );
new Thread(new Runnable()
{
#Override
public void run()
{
try
{
Thread.sleep( 4000 );
}
catch ( Exception e )
{
}
ringProgressDialog.dismiss();
}
}).start();
View rootView = inflater.inflate(R.layout.interfaces, container, false);
interfacesTextView = ( TextView ) rootView.findViewById( R.id.interfacesTextView );
interfacesTextView.setText( lines );
interfacesTextView.setMovementMethod( new ScrollingMovementMethod() );
return rootView;
}
}
The trouble is the use of the absolute path /data/data/com.example. androidjnetpcaptest/interfaces. You should not assume this is the data location for the app. Apps can be moved to external storage and since ICS the system supports multiple users (people) where the app gets different storage per user. Instead, use Context.getFilesDir() to get the app-private location where files can be created and stored.
You do not need any special permissions to read/write this space.

Selecting & Calling numbers

I have a few numbers in an activity which I would like to be-able to make selectable, like a hyperlink. When the number is pressed it should call the number. I have checked the Android API but wasn't successful.
Anyone have any ideas?
Code for the button from the comment below is:
DialButton=(Button)findViewById( R.id.dialbutton );
DialButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
if(number!=null){
try {
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number.getText())));
} catch (Exception e) {
e.printStackTrace();
}
}//if
}
});
So what gives? Also in the "AndroidManifest.xml" file I specified the permissions like this:
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Is this wrong? Is the permission in the wrong place?
<TextView
android:text="+1........"
android:autoLink="phone" />
http://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink
Also, don't forget to add a corresponding permission to manifest file
<uses-permission android:name="android.permission.CALL_PHONE" />

Categories

Resources