My code to open url in browser is
private void openBrowserUrl(String url) {
Intent i = new Intent(Intent.ACTION_VIEW);
System.out.println("============Url==================" + url);
i.setData(Uri.parse(url));
startActivity(i);
unlock(UNLOCK_TO_HOME);
}
Above is working fine when there is no pattern lock.
But When I tried to open browser after pattern lock, url value remain blank.
I have custom lock screen in my application.. When phone is locked, after that, I tried to unlock the phone at that time custom lock screen is opened by my application. and in that I have written this code. I got url value and it successfully passes to browser.
But, I tried with above process with patter lock(default lock system of android)
then the flow is
custom lock screen-->open url code(got the url value)-->default pattern lock-->browser without url value.
In above flow, when pattern lock is there, browser unable to get url which I have passed.
This problem occurs on api > 21. There been some changes in the KEYGUARD, and after you unlock the screen there is some kind of a delay or something that makes the intent not to react,buy using the flags it should delay the intent and make it work
the code here should solve the problem.
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("your url"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(i);
Related
I'm looking for a way to open a browser at a specific link automatically at a give time / daily.
Maybe there is some kind of script, add-on for bowser but I still haven't find one.
Does anyone know a good solution?
I suggest you to use an AalarmManager here is an example
And then here is the code you should execute
String urlString = "your_url";
Intent intent = new
Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
context.startActivity(intent);
}
catch (ActivityNotFoundException ex) {
context.startActivity(intent);
}
Seems to me this is a combination of three things, setting the alarm, firing the intent and making sure the intent has the data to open a specific uri in the browser.
start activity from an alarm
open a uri
So, there are apps that can create shortcuts on the home screen.
My question is, How can my app opens/runs/starts a certain shortcut?
if I have 2 browser shortcuts, each of them loads a different url ... how can I choose between them? how to choose to open the 1st or the second one?
To open a URL/website you do the following:
String url = "http://www.example.com";
Intent mIntent = new Intent(Intent.ACTION_VIEW);
mIntent.setData(Uri.parse(url));
startActivity(mIntent);
Here's the documentation of Intent.ACTION_VIEW.
Hello I am lauching the browser from my application using an intent such as:
String url = "XXXX";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
but when I press back on the browser i want to go back to the my application, instead of going to the options of the browser. how can i control this behaviour?
You can't as the back button implementation is now under control of Browser Application.
Implement a WebView in your application and handle Back Key Pressed is the only option.
Try:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
A task (from the activity that started it to the next task activity) defines an atomic group of activities that the user can move to. Tasks can be moved to the foreground and background; all of the activities inside of a particular task always remain in the same order. You can find more about it here: http://developer.android.com/guide/components/tasks-and-back-stack.html
I use the following code to open an URL in browser:
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
startActivity(intent);
But if the page behind the url was already opened in browser, running the above code doesn't refresh the page. How could I force page refreshing?
Looking for an answer as well... this seems to work for me:
Uri url = Uri.parse(website+"?time="+(new Date().getTime()));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(url);
activity.startActivity(i);
because the new get parameter forces a reload.
to my knowledge you cannot force it to refresh from the Android side (unless you're showing it in your own WebView) You'd have to set the page itself to auto refresh, that would presumably ensure whatever is being shown is likely to be up to date.
I created an app to simply open a web browser and go to a specific website. However, after it's run for the first time, if I go to another app and run the app again, I will get nothing except the black screen. I knew I can find the page from web browser, however I wonder if there is a way to bring the content back when I launch the app and the user could get back to work from where he/she stopped.
here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** setup the url and start a browser with
* the hotmial.com and return to the user
* */
String url = "http://www.hotmail.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
Thanks guys
Take a look at the activity lifecycle. You may want to move your intent to OnStart() for when the application comes back to the foreground after being stopped.
The activity may still exist when you run your app a second time; perhaps onCreate is not called.
After you throw the Intent to run the browser, shut down the activity so that onCreate happens every time.
If your application is here only to give a link to a website, this is much overhead in my opinion. Android users can make a shortcut to any website they want on the desktop, the shortcut icon being shown with the site's favicon in its corner.
Try this if you want to open the browser OUTSIDE your app. I know it seems like a simple(and trivial) edit, but I've never had issues setting it up this way.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** setup the url and start a browser with
* the hotmial.com and return to the user
* */
String url = "http://www.hotmail.com";
Uri uri = Uri.parse(url);
Intent i= new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
}
Why don't you use the android.webkit.WebView which will allow you to directly browse web pages in your app. Here the web content will remain persistent as long as the application is running. On the chance that your application stops you could save the url using WebView.getURL() which would allow you to continue from where you left of the next time you start your app. If this is what you want to do let me know and I will post some sample code.