I have registered "SMS received event" for the broadcast receiver but when i launch the app and send message to the emulator i do not see onReceive method of broadcast receiver getting triggered.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dev.code">
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="500">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MyReceiver.java
public class MyReceiver extends BroadcastReceiver {
private static final String TAG =
MyReceiver.class.getSimpleName();
#Override
public void onReceive(Context context, Intent intent) {
// Get the SMS message.
Log.v(TAG,"Message Received");
}
I think you need to check permission in code for SDK more or equal to M(Marshmallow) -
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission. RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED) {
// you can receive sms
}
else
{
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission. RECEIVE_SMS}, 411);
}
}
else
{
// you can receive sms
}
}
And on result of user action-
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 411) {
if (grantResults.length == 0 || grantResults == null) {
// show dialog that you need access to go ahead
} else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Your code here permission granted
} else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
// show dialog that you need access to go ahead
}
}
}
The android.permission.RECEIVE_SMS permission is a dangerous permission.
You should use ActivityCompat.requestPermissions to request it.
<permission android:name="android.permission.RECEIVE_SMS"
android:permissionGroup="android.permission-group.UNDEFINED"
android:label="#string/permlab_receiveSms"
android:description="#string/permdesc_receiveSms"
android:permissionFlags="hardRestricted"
android:protectionLevel="dangerous" />
Related
I'm trying to invoke the samsung knox SDK to access the TIMA keystore.
However, the device throws the following exception:
Caused by: java.lang.SecurityException: uid 10207 does not have com.samsung.android.knox.permission.KNOX_TIMA_KEYSTORE.
at android.os.Parcel.createException(Parcel.java:1966)
at android.os.Parcel.readException(Parcel.java:1934)
at android.os.Parcel.readException(Parcel.java:1884)
at com.samsung.android.knox.keystore.ITimaKeystore$Stub$Proxy.enableTimaKeystore(ITimaKeystore.java:253)
at com.samsung.android.knox.keystore.TimaKeystore.enableTimaKeystore(TimaKeystore.java:123)
at com.samsung.knox.example.knoxsdk.MainActivity.enableKeystore(MainActivity.java:163)
at com.samsung.knox.example.knoxsdk.MainActivity.onRequestPermissionsResult(MainActivity.java:157)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7957)
at android.app.Activity.dispatchActivityResult(Activity.java:7779)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4615)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4664)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1960)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7094)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
What do I need to do to make it work?
I am working on a Samsung SM-A705FN and it does have knox on it
Sample code
private void enableTimaKeystore() {
activateLicense();
int checkKeystore = getApplicationContext().checkCallingOrSelfPermission(KNOX_KEYSTORE_PERMISSION);
int checkKeystorePerApp = getApplicationContext().checkCallingOrSelfPermission(KNOX_KEYSTORE_PERMISSION_PER_APP);
if (checkKeystore == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION + " is granted", Toast.LENGTH_LONG).show();
enableKeystore();
} else if (checkKeystorePerApp == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION_PER_APP + " is granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION + " and " + KNOX_KEYSTORE_PERMISSION_PER_APP + " are not granted. You can't use TimaKeystorePerApp ", Toast.LENGTH_LONG).show();
requestPermissions(new String[]{KNOX_KEYSTORE_PERMISSION}, 100);
}
}
private void activateLicense() {
// Instantiate the EnterpriseLicenseManager class to use the activateLicense method
KnoxEnterpriseLicenseManager klmManager = KnoxEnterpriseLicenseManager.getInstance(this.getApplicationContext());
try {
// KPE License Activation TODO Add license key to Constants.java
klmManager.activateLicense(Constants.KPE_LICENSE_KEY);
mUtils.log(getResources().getString(R.string.activate_license_progress));
} catch (Exception e) {
mUtils.processException(e, TAG);
}
}
private void enableKeystore() {
/* get CCM Policy */
TimaKeystore mTimaKeyStorePolicyHandler = EnterpriseKnoxManager.getInstance(this).getTimaKeystorePolicy();
mTimaKeyStorePolicyHandler.enableTimaKeystore(true);
/* To enable TimaKeystore for all the apps on the device (both inside and outside container). */
boolean isEnabled = mTimaKeyStorePolicyHandler.isTimaKeystoreEnabled();
mUtils.log("is keystore enabled: " + isEnabled);
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
enableKeystore();
}
And the manifest file
<?xml version="1.0" encoding="utf-8"?>
<!-- Permissions TODO List permissions used by application -->
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_HW_CONTROL" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_TIMA_KEYSTORE" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_KEYSTORE_PER_APP" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.samsung.knox.example.knoxsdk.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- SampleAdminReceiver TODO Provide receiver for device admin receiver class -->
<receiver
android:name="com.samsung.knox.example.knoxsdk.SampleAdminReceiver"
android:description="#string/enterprise_device_admin_description"
android:label="#string/enterprise_device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!-- Activate License TODO Provide receiver for Knox license activation results -->
<receiver android:name="com.samsung.knox.example.knoxsdk.SampleLicenseReceiver" >
<intent-filter>
<action android:name="com.samsung.android.knox.intent.action.KNOX_LICENSE_STATUS" />
</intent-filter>
</receiver>
</application>
Who would have thought that a public forum was the best place for questions like this. Maybe should listen to some John Lennon. Or a specific beatle
Below code is working fine upto marshmallow but it not working in from 7.0
I create Brocast receiver for to fetch location every 6 sec.
MainActivity.java
private PendingIntent getPendingIntent() {
Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class);
intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES);
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public void requestLocationUpdates(View view) {
try {
mFusedLocationClient.requestLocationUpdates(mLocationRequest, getPendingIntent());
} catch (SecurityException e) {
Utils.setRequestingLocationUpdates(this, false);
Log.e("requestLocationUpdates"," "+e.toString());
e.printStackTrace();
}
}
LocationUpdatesBroadcastReceiver.class
This is my BrocadcastReceiver class
public class LocationUpdatesBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "LUBroadcastReceiver";
static final String ACTION_PROCESS_UPDATES =
"com.google.android.gms.location.sample.locationupdatespendingintent.action" +
".PROCESS_UPDATES";
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
final String action = intent.getAction();
Log.d("showthepackgesss","***** "+action +" \n"+ACTION_PROCESS_UPDATES );
if (ACTION_PROCESS_UPDATES.equals(action)) {
LocationResult result = LocationResult.extractResult(intent);
if (result != null) {
List<Location> locations = result.getLocations();
Utils.setLocationUpdatesResult(context, locations);
Utils.sendNotification(context, Utils.getLocationResultTitle(context, locations));
Log.i(TAG, Utils.getLocationUpdatesResult(context));
}
}
}else {
Toast.makeText(context,"No Intent found checkit",Toast.LENGTH_SHORT).show();
}
}
}
My Manifestfile.xml
Here is my manifestfiles
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cbdc.locationupdates_background">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".LocationUpdatesIntentService"
android:exported="false"></service>
<receiver android:name=".LocationUpdatesBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.example.cbdc.locationupdates_background.LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES" />
</intent-filter>
</receiver>
</application>
</manifest>
if any one know please help me.....Thanks in advance!!!!!!
You need to add support for runtime permissions, introduced in API 23.
I want to ask users to agree with the disclaimer that I have provided in my application, and then if they agreed, next time they are using the app, we just re-show them the disclaimer for a few seconds without asking to click on anything and redirect them to the application. The best way I could have come up with it was, using a custom permission and however I did add permission commands to my manifest I could not figure out how to actually activate the permission in my code:
import java.util.jar.Manifest;
public class Language extends Activity {
Button engBut, fraBut;
// public static int j;
public void click (View view){
// j=1;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
public void fraClick (View view){
// j=2;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
ImageView logo = (ImageView) findViewById(R.id.logo);
ImageView montfortLogo = (ImageView) findViewById(R.id.montfortLogo);
montfortLogo.setImageResource(R.drawable.k);
logo.setImageResource(R.drawable.j);
engBut = (Button) findViewById(R.id.engBut);
engBut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(Language.this);
builder.setCancelable(true);
builder.setTitle("DISCLAIMER");
builder.setMessage(R.string.result_disclaimer);
builder.setNegativeButton("Get me out of here.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
builder.setPositiveButton("I agree.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.setAction("com.techideas4you.pharamacy.MyAction");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
});
builder.show();
}
});
fraBut = (Button) findViewById(R.id.fraBut);
Log.i("Locale", String.valueOf(Locale.getDefault()));
}
}
This was my first page code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.ex"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission android:name="testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"/>
<uses-permission android:name="testDisclaimer"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name">
</activity>
<activity
android:name=".ActivityQuestion"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ActivityResult"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".Language">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.techideas4you.pharamacy.MyAction"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and this is my manifest if anybody could help me out here I really appreciate it.
You have to add android:protectionLevel="dangerous" to the declaration of your permission else it will be granted automatically and users will not be presented with a dialog although you call requestPermission().
<permission android:name="your.package.name.permission.testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"
android:protectionLevel="dangerous"/>
<uses-permission android:name="your.package.name.permission.testDisclaimer"/>
In order to have the runtime show the disclaimer, you have to call
requestPermissions(new String[]{"your.package.name.permission.testDisclaimer"}, 42);
The result (whether user agreed) will be transmitted to you in onRequestPermissionsResult()
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 42 && grantResults != null){
Toast.makeText(this, "Permission " + permissions[0] + (grantResults[0] == PERMISSION_GRANTED ? "" : " NOT ") + " granted! ", Toast.LENGTH_LONG).show();
}
}
Please note that by using the permission system, you also have to cope with the fact that users will NOT be shown the permission-request-disguised-as-disclaimer if they
[...] turned down the permission request in the past and chose the
Don't ask again option in the permission request system dialog [...]
(quoted from documentation).
So maybe simply writing a flag to SharedPreferences will do the job just as well.
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.
This is my code for reference. I have added the run time permission code and system granting the permission but again it gives an error:
Failed due to non declaration of following android.permission.SYSTEM_ALERT_WINDOW permission in Manifest file
public boolean checkDrawOverlayPermission()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
{
return true;
}
if (!Settings.canDrawOverlays(this))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
}
else
{
return true;
}
}
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
if (Settings.canDrawOverlays(this))
{
//startService(new Intent(this, PowerButtonService.class));
//Toast.makeText(this, "permission granted", Toast.LENGTH_SHORT).show();
if(!checkPermission())
{
requestPermission();
}
else
{
//Toast.makeText(this, "Phone State Permission Already Granted", Toast.LENGTH_SHORT).show();
//callBeacon();
}
}
}
}
Manifest File :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adsl.beaconapp">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<!-- Declaration that this app is usable on phones with Bluetooth Low Energy. -->
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
<!-- Declaration permission for using internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<!-- <activity android:name="com.facebook.LoginActivity" /> -->
<activity
android:name="com.beaconstreamsdk.com.MainActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" />
<service
android:name="com.beaconstreamsdk.com.service.BeaconService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.beaconstreamsdk.com.service.FloatingHeadService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.beaconstreamsdk.com.service.ConnectionService"
android:enabled="true"
android:exported="false" />
<activity
android:name="com.beaconstreamsdk.com.SignUpActivity"
android:screenOrientation="portrait" />
<activity android:name=".Main2Activity" />
<activity android:name=".BeaconStreamActivity"></activity>
</application>
</manifest>
onActivityResult :
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
if (Settings.canDrawOverlays(this))
{
//startService(new Intent(this, PowerButtonService.class));
//Toast.makeText(this, "permission granted", Toast.LENGTH_SHORT).show();
if(!checkPermission())
{
requestPermission();
}
else
{
Toast.makeText(this, "Phone State Permission Already Granted", Toast.LENGTH_SHORT).show();
//callBeacon();
}
}
}
}
Please try this way. May be you are facing condition problem,
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M)
{
if (!Settings.canDrawOverlays(this))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
}
else
{
return true;
}
}else{
return true;
}