I am following the Android by Udacity course, but by pressing the refresh button to retrieve the json that error appears in my logcat, what could be happening, putting this permission in manifest.xml not resolved ....I'm using Galaxy S3 device.
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as > user -2 but is calling from user 0;this requires >android.permission.INTERACT_ACROSS_USERS_FULL
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
FetchWeatherTask tempoTask = new FetchWeatherTask();
tempoTask.execute("87047100");
return true;
}
return super.onOptionsItemSelected(item);
}
try adding this in your manifest file:
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
hope it helps
Related
I've spend a day on this issue, and I'm stumped. I've read through numerous similar questions, and tried all the suggestions, but nothing worked for me.
I have an app, with a preference screen where the user can turn on Bluetooth. The preference screen sends an intent to the MainActivity, which then checks security permissions and if needed requests permission.
I am building against version SDK version 32.
In Manifest I have:
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
In MainActivity I check if permission is already granted:
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (Objects.equals(intent.getAction(), CustomIntent.CHECK_BLUETOOTH_SECURITY_PERMISSION)) {
int check = ContextCompat.checkSelfPermission( thisActivity, Manifest.permission.BLUETOOTH_CONNECT );
if ( check == PackageManager.PERMISSION_DENIED )
getPermission( Manifest.permission.BLUETOOTH_CONNECT, RequestCodes.BT_SECURITY_REQUEST.ordinal() );
}
and if not, I request permission.
When requesting permission, I have tried the old way with:
public void getPermission( String permission, int requestCode ) {
if ( shouldShowRequestPermissionRationale( permission ) ) {
// TODO: display a dialog to explain the reason for needing the permission
Toast.makeText( this, "Need to put together an explanation for the permission", Toast.LENGTH_LONG ).show();
} else {
requestPermissions( new String[]{ permission }, requestCode );
}
}
I have tried both with CompactActivity.requestPermissions and with just requestPermissions as above.
and I have also tried with the new way. In onCreate I have:
activityResultLauncher = registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
#Override
public void onActivityResult(Map<String, Boolean> result) {
Log.e("ActivityResultLauncher", ""+result.toString() );
Boolean areAllGranted = true;
for ( Boolean b : result.values() ) {
areAllGranted = areAllGranted && b;
}
if ( areAllGranted )
Log.e( "ActivityResultLauncher","It worked");
else
Log.e( "ActivityResultLauncher", "wah wah wah");
}
});
and in getPermission() i then call
activityResultLauncher.launch(new String[]{
Manifest.permission.BLUETOOTH_CONNECT
});
But no matter what I do, the user dialog asking the user to grant permission never show, and the onPermissionRequestResult just immediately return with False, i.e. Denied.
I don't see any error messages in the LogCat (outside of the log entries I put there myself). I've also tried to step through the Android libraries to see i can see any exception thrown, but all looks fine there as well.
UPDATE
Just as I posted this, I tried to clear the emulator device.
After that, the first time I ran the code, the app crashed, hard.
I was able to catch this in logCat
Attempting to launch an unregistered ActivityResultLauncher with >contract
androidx.activity.result.contract.ActivityResultContracts$RequestMultiplePermissions
and input [Ljava.lang.String. You must ensure the
ActivityResultLauncher is registered before calling launch().
I do register the activityResultLauncher in onCreate. So I'm not clear on why it doesn't know it's registered.
It's also weird that this error only happens first time I run the app after clearing device files.
Then I launched the app again, (without changing anything in my code) and this time it worked. The dialog was displayed, and I could grant permissions.
Anyone know what in the world is going on?
How can we perform a call to any number when application is in the background using volume key (number set by own self-using application)?
When I press up the volume key 3 times, I want the app to call my Dad's number even if the app is in background.
Using following code you can achieve it -
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);
Also, don't forget to add the permission for the same in Manifest file -
uses-permission android:name="android.permission.CALL_PHONE" />
And lastly you need to check for the volume up button event to trigger the call -
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
down = false;
} else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
up = false;
}
return true;
}
Based on the condition you can achieve the same. Thanks :)
I'm having issues with my prototype application. It works fine between two emulators on my PC, but when I install it on my phone it won't send text messages or even care to ask for the permission (if that is the issue).
Furthermore, I'm recieving the same error no matter what I do, on app start, each time I press a button and on every new intent start:
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
I've been looking at a lot of similar issues, and I did add
uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>
to my manifest, but nothing seems to work for me.
The real odd thing to me is that the error occurs on application start, because nothing interesting really seems like nothing interesting is happening at that point:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Go to contact list
public void onClick(View view) {
Intent i = new Intent(this,AddContact.class);
startActivity(i);
}
public void onGPS(View view) {
Intent j = new Intent(this,GPSActivity.class);
startActivity(j);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Any ideas ?
The issue is seemingly with Samsung Galaxy S3. The link: Permission Denial: this requires android.permission.INTERACT_ACROSS_USERS_FULL
Provided by Sumighosh Chaurvil explains the problem; And that there's really not much to do about it.
I installed the application on another phone, and it works with no problems whatsoever!
Hi I´m new to Android and Eclipse. I have just following the tutorial from developer.android.com. Right now I´m in adding ActionBar
Right now I´m at this part
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I have received an error for openSearch() and openSettings(). It said that The method openSettings() is undefined for the type DisplayMessageActivity. What shoud I do now?
Thanks
openSearch() and openSettings() are methods that the author of the tutorial created in order to perform other operations. Search well into the code, there must be somewhere the declaration of those methods, if the author made them visible.
They should look something like this:
public void openSearch() {
//Do something here.
}
public void openSettings() {
//Do something here.
}
Replacing the //Do something here with the code implementation present in the tutorial.
Im up to the same section as you, they haven't provided the methods but you have to implement them as stated above.
However I found code to open up the device settings using this code in the switch;
case R.id.action_settings:
startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
return true;
define them.
You're basing your code on an incomplete snippet. That snippet makes no expectation of what it means to search or create settings in your app... that's your job to implement. This snippet is only concerned about showing you how to establish the action bar, not the whole application.
The methods openSearch() and openSettings() should be defined. Use the following code. It'd help..
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch(id){
case R.id.action_search :
startActivity(new Intent(Settings.ACTION_SEARCH_SETTINGS));
return true;
case R.id.action_settings :
startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
return true;
default :
return super.onOptionsItemSelected(item);
}
}
Maybe you should code those methods?
private void openSearch(){
//your code here
}
private void openSettings(){
//your code here
}
Those two methods are just examples how selecting an option can start an action. The implementation was not provided because it was irrelevant to the example. Note that it is not a tutorial, but a single and un-compile-able example of how to add behavior to an options item.
I am trying to implement the single sign on using GMail. Trying using this link https://developers.google.com/accounts/docs/MobileApps sample code. I was unable to get YOUR_AUTHENTICATION_ENDPOINT token key.
Here is my main.activity where I am using YOUR_AUTHENTICATION_ENDPOINT.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflating the menu resource.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Start the WebViewActivity to handle the authentication.
case R.id.login:
Intent intent = new Intent(this, WebViewActivity.class);
intent.setData(Uri.parse(YOUR_AUTHENTICATION_ENDPOINT));
startActivityForResult(intent, 0);
return true;
// Exit.
case R.id.exit:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
app is while running I am getting this error :
04-02 15:09:12.271: E/Web Console(924): SyntaxError: Parse error at https://mail.google.com/mail/x/cc6i6zigt73b-/?pli=1&f=1&shva=1:1
For a google app-engine hosted account, the login URI is:
https://myapp.appspot.com/_ah/login?continue=REDIRECT
Where, myapp is your app's name and REDIRECT should be set to the domain where you will fetch further authenticated resources from. The cookies will be set accordingly by the authentication mechanism. https://myapp.appspot.com is what I use as the REDIRECT.
EDIT
I'm sorry, but I have misread your question. You wish to authenticate using the web-based authentication. I gave you the endpoint for authenticating with the google account on one's phone. For the web-based login URLs, you can use users.create_login_url() and users.create_logout_url(). More info here: https://developers.google.com/appengine/docs/python/users/loginurls