I have used the following code for enabling Bluetooth (as described here) and the same runs in onCreate() of the launcher activity of my app -
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 101);
Now the problem is when this dialog is popped up, then every time i rotate the device, the dialog gets created again again on top of the previously created dialog.
I am preventing my activity from getting recreated by handling it from manifest
android:configChanges="orientation|screenSize|keyboardHidden"
This doesn't occur in all devices
I am getting this on :
LG Nexus 5, Samsung Galaxy Grand
And not on :
Samsung I9500 Galaxy S4
Edit :
Found this Reported Issue but couldn't find the solution
Here is the link
Created another issue Here
It seems this bug was never solved !!
I have tested this on several devices including latest Pixel device and it still exists
And the same has been raised several time on code.google.com/p/android
Reference to raised issues :
Issue 60002: Bluetooth permission request dialog
Issue 219105 On each rotation, dialog for requesting user permission to enable Bluetooth, the request dialog is placed on the top of the stack
Issue 24931: Bluetooth permission request dialog - recreated on screen rotation(orientation change)
In case anyone finds a solution then please do post it here
When we rotated device its configration change method is call in activity.
You just need to add android:configChanges="orientation" in your activity element in AndroidManifest.xml
<activity
android:name=".MainActivty"
android:configChanges="orientation"
android:label="#string/app_name"></activity>
I hope it will help you to solve the problem
Related
I have a problem, when I startActivityForResult to take picure, resultCode is always Activity.RESULT_CANCELED (0) if there is two or more camera apps that can handle that intent (app chooser appears). But if I set one of them as default app and next time it doesn't offer me a chooser, everything works fine, and it takes picture and detects it in a onActivityResult in my fragment that started startActivityForResult().
Same thing happens when I try to open gallery to select picture. If there are two gallery apps, I choose either one of them, picture selection result is always 0.
This is the code I use to start camera app:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, AppConstants.TAKE_PICURE_CAMERA_REQUEST_CODE);
}
I had the same issue, when my activity has launchMode="singleTask", but I change to singleTop and that solve the problem
I just updated my Poco X3 to Android 11 and now I have the same problem... It's probably a bug in MIUI (12.0.8). It works fine on other Android 11 devices.
Changing launchMode does not work. However when I detect a MIUI user I circumvent the chooser and just open the first camera app it finds.
Worst thing is that you can't really detect when this issue occurs. So you can't log when it goes wrong and therefore you can't find out which users are experiencing this issue.
The same issue also occurs when you try to get a photo from a gallery, or when you try to open a photo in a photo app. The latter results in a 'cannot find photo' message.
When Android backgrounds an application it creates a screenshot of the current screen. The screenshot is displayed when you click the Overview button.
Is there a way to prevent this backgrounding screen shot (as if I'd used FLAG_SECURE), but allow the users to take screenshots?
You can configure not to show your activity in recent list. Add following code in manifest :
<activity
.....
android:excludeFromRecents="true"
...../>
Or from java code startActivity with flag:
intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Or,
<activity
.....
android:noHistory="true"
...../>
Try this https://stackoverflow.com/a/49442984/5939067 .
The solution above simply sets the secure flag when your app goes background, and clears it when it resumes(so you can take the screenshot while using the app).
It works perfectly for me. I tested with Samsung Galaxy 9+(Android 9), LG V30(Android 8) and LG G7 ThinQ(Android 8).
I have a WatchFaceService (WatchFace) and every time I run my application it switches to the SimpleFace and then I have to set mine as the watchFace which ends up to be quite frustrating after many restarts.
To notice this does happen with the new Android Studio 2
I read around S.O. how to set the default activity but that does not do the same job as my WatchFaceService is not an activity but a service.
Also via the UI of Android Studio 2 it cannot be selected.
Is there a way to achieve this ? I think it might be difficult because actually it's not running an app, but setting the watch's Watchface at every run.
Any ideas?
The short answer is that this isn't possible. Your watch face is a Service, after all, so there's no way that it can be the default (launch) Activity for your app. They're completely different component classes.
But you can get close.
What you need to do is create a tiny little shell Activity that contains only the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(getPackageName(),
MyWatchFaceService.class.getName()));
startActivity(intent);
finish();
}
...where MyWatchFaceService is the class name of your watch face service (surprise). You'll also need to declare it in your manifest, of course:
<activity android:name=".FaceActivity"
android:enabled="true"
android:exported="true">
</activity>
Finally, configure your Wear module in Android Studio to launch FaceActivity when you run the app. This is under the Run menu, in Edit Configurations.
Having done that, run your app from AS onto the watch, and it'll open the watch face chooser on-device, with your face selected. From there, one tap will start it.
I can't see a way to eliminate that single tap, though.
I'm trying to implement locking the screen with my app.
I've worked my way through google documentation and studied the sample.
When i call this
void getAdmin(){
Intent activateDeviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mPolicy.getPolicyAdmin());
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources().getString(R.string.AdminReceiverDescr));
startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
}
The dialogue doesn't show up (maybe it flashes a little, can't say for sure), it just jumps in my onResult routine and result is "not granted". But my app afterwards shows up in the list in settings/security/device admins and if i enable admin rights manually it locks my screen like a charm.
I've added the permission
uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"
as well as
receiver ... android:permission="android.permission.BIND_DEVICE_ADMIN"
to my manifest.
Does anyone have a clue what i may have missed?
Thx in advance!
Found the problem in my manifest: you have to specify the receiver subclass with a $ sign.
Example:
android:name="com.exampl.PolicyClass$PolicyReceiver"
I have an air for android app that has event listeners for ACTIVATE and DEACTIVATE, inside the activate I tell the screen to stay awake and in the deactivate I tell it to go back to normal like so :
stage.addEventListener(Event.DEACTIVATE, deactivateHandler);
stage.addEventListener(Event.ACTIVATE, activateHandler);
protected function deactivateHandler(event:Event):void{
SFX.disableSound();
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
protected function activateHandler(event:Event):void{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
But the screen will stay awake at all times even when on the android home screen unless you force close the app... any ideas?
Thanks
I had this exact problem. My app was able to keep the screen on by setting systemIdleMode to SystemIdleMode.KEEP_AWAKE, and it would force the screen to stay on. However, when the app tried to set the systemIdleMode back to SystemIdleMode.NORMAL, so the screen could turn off, the screen was still staying on.
What turned out to be the problem in my case is was a missing android permission. I had already added this permission to my app XML file, so that i could use the keep-alive function:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Turns out this is not the only permission you need. I added this permission also:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
And suddenly my app was able to let the screen be turned off again.
You could try using this in your java code:
// Gets one of the views visible on the screen and sets keepScreenOn to true.
// This means the screen will stay on as long as the specified view is visible.
this.findViewById(R.id.viewId).setKeepScreenOn(true);
Or you could put android:keepScreenOn="true" in your layout.