Settings.ACTION_SOUND_SETTINGS is not going back to app - java

I am trying to open Sound settings from my app
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
Sound Settings Activity displays without any issue.
Scenarios After Opening Sound settings page
When I press back button on my device, it is going back to my application.
when I click on back arrow button(top left), it is going to Settings Main Screen.
Issue:
I want to go back to my app when click on back icon also.
startActivityForResult(new Intent(Settings.ACTION_SOUND_SETTINGS), 100);
I have also tried this. but no result.
I am testing this on OnePlus 6 (Android 10 (Q))

Create an intent:
Intent intent = new Intent(Settings.ACTION_SOUND_SETTINGS);
Add these lines to your intent:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
then call startActivity(intent);

Related

android how play video automatically by intent without press start

I want to play video from app by intent.
I set specific component (vlc). it opened by this by I need press play.
Is there a way to start the video automatically??
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://media/external/video/media/249"), "video/mp4");
intent.setPackage("org.videolan.vlc.betav7neon");
startActivity(intent);
I followed the instruction VLC published on its official wiki-page and the video starts playing automatically on my device, without pressing the Play button.
https://wiki.videolan.org/Android_Player_Intents/

Pressing back button on phone has different behaviour to back intent

My app is tabbed, when I start a new activity over the top of the tabs, and press the back button on the phone to return, it returns to the tab I was previously on. When I go back with this intent:
Intent intent = new Intent(EditViewerActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
It doesn't return to the tab I was on before. Is there anyway to get the same behaviour as the back button on the phone in an intent?
Solution was to use finish();.
finish(); will end the current activity, the proper way would be to use NavUtils.navigateUpTo(this, new Intent(this, MyActivity.class)); which can be used after importing import android.support.v4.app.NavUtils;
They will both basically do the same thing in the end.

Android Home Shortcut loses flags after reboot

My Android app defines an activity with an intent filter of android.intent.action.CREATE_SHORTCUT, which lets me show up in the list of shortcuts that the user can add to their home page, when they select "Add Shortcut" from the menu or long-click the home page.
In this activity I have the following code (actually happens in a click event after they pick which shortcut to add):
Intent shortcutIntent = new Intent(this,MyActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.myicon);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "MyAppName");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
finish();
The shortcut works as I would expect, until I reboot the device. I'm actually testing on the emulator, not real device. The shortcut is still there after a reboot, so I know I didn't wipe user data or anything like that, but it acts like it no longer has the FLAG_ACTIVITY_NEW_TASK setting when clicked.
Example steps to recreate (assume my app is an email inbox for clarity):
Create the shortcut
Launch my inbox activity from my main menu acitvity, which uses the NEW_TASK flag.
From the inbox activity, click a message to open the view message activity.
Press HOME key
Click the shortcut -- at this point it brings the entire "task stack" back to the front, with the view message activity on top of the stack, clicking back goes back to the inbox activity, as I would expect
Reboot the device
Repeat steps 2 through 5.. now when I click the shortcut, instead of bringing the view message activity to the front, it brings the task to the front, but then adds a new inbox activity on top of the stack. So pressing BACK once goes back to the view message activity, and back again to the inbox activity.
I also tried setting different properties such as singleTask for my inbox activity in the app manifest, but haven't had any luck. Is this a known issue that flags are not saved with shortcuts?
I think I'll try adding a new stub activity that does nothing but launches the real activity with the NEW_TASK flag and then exits, and have my shortcuts point to that instead. However, seems like a lot of overhead, so hopefully someone has a better answer.

How do I create an android shortcut to an activity?

OK,I'm new at this forum, so don't blame me for putting this in the wrong tags,not putting something in,eg.
I want to learn how to create a shortcut(I did that by Googling) and link it to an activity (In this case, com.android.mms.ui.ComposeMessageActivity)
I tried doing it, but it only showed me a toast saying "Application not installed" and I'm pretty sure it is.
It would be better if you can display a "complete action with another application" dialog.
If I assumed your question correctly, you mean a button or something within an activity that leads to another activity, that being -- "com.android.mms.ui.ComposeMessageActivity"
if your activity that you want to link to is in another application-- then
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.mine", "com.android.mms.ui.ComposeMessageActivity"));
startActivity(intent);
if it is within the same application, then
Intent intent = new Intent(this, ComposeMessageActivity.class);
startActivity(intent);
//optional add this to your manifest to finish the current loading activity so
//as to not keep it in the activity stack
//<activity android:name="yourActivity" android:noHistory="true" ... />
EDIT If you mean a shortcut on a homescreen, then I would create a tiny application that only has one activity which uses the above method to link to a different application. Then I would drag that application to the home screen, and boom. If there's a better way, then please feel free to correct me

Button to start the Gallery on Android

I'm trying to make a button in my App open the built in gallery.
public void onClick(View v) {
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
I'm trying to make a button in my App open the built in browser.
Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.
I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.
However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.

Categories