I'm trying to open a link in the browser from service. The problem is that if screen is off then link does not open. Sometimes the browser opens but without any data.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://somelink.com"));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
If the screen is on then this code works very well. Why does not it work then screen is off?
Maybe this helps, but I don't know if it's good enought for services: https://stackoverflow.com/a/2201999/2151532
Related
In fact, I want to be noticed when the program is downloaded without the user having to install their own apps (Install without show permissions activity).
Now I use the following code, and I want to change this code to answer my question.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The following image is displayed after downloading the app from my server and i dont want to show
I'm new to android development, and currently creating an app for remote control to use in a test enviroment.
What I'm trying to do is open an app, in this case netflix, wait for x seconds and then closing the external app and return to my own app. To open netflix I'm using an URL:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.netflix.com/watch/80015343?preventIntent=false"));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(browserIntent);
This then in return opens the media client app installed on the device. So I though I might be able just to close netflix, and then return my own app, so I tried running through the open processes as following:
for(ActivityManager.RunningAppProcessInfo runningProcess : runningProcesses){
System.out.println(runningProcess.processName);
if(runningProcess.processName.equals(NETFLIX_PACKAGE_NAME))
{
android.os.Process.sendSignal(runningProcess.pid, android.os.Process.SIGNAL_KILL);
}
}
Unfortunately this doesn't get the netflix app, but only shows my app. I later found out that is because of android 6.x.
I'm open to all recommendations - how in the world do I close the netflix media client, and then return to my own app?
At the moment I'm simply doing this:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain);
This kinda stops netflix by putting it in the background, but of course I don't end up at my app. And I can't really restart my app, since it's registered with a server. I could, but then I would need to deregister and register again. There must be some kind of smart way :-)
I really hope you guys can help an android-noob here :-)
Best regards,
Ben
Is there any way to open the Android's existing Call Froward settings screen?
I'm pretty sure I can make one myself, but as always, it'll be better to reuse what is already in the phone. If I can.
Intent intent = new Intent(Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This opens the general phone settings, but I can't find the intent identifier to open the actual CF configuration screen.
I'd like my application to launch a specific video from the youtube app and automatically restart (loop) the video after it's finished.
I tried the following:
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/v/" + youtubeID + "&loop=1&autoplay=1"));
startActivity(intent);
It works well in the browser, but will not automatically restart in the youtube app.
Is it possible?
Thanks.
Youtube app won't give you this option, it is possible tho with a well crafted hack,
but will take you ages to develop.
I don't know why you want it but i don't think it's worth the time.
I have a program that I have made for Android 1.6 and up and I have been doing tests to ensure that the program works fine with the new Ice Cream Sandwich (Android 4).
Everything on the app works fine except that when a certain task has been performed by the user it is supposed to automatically launch the android browser. However for some reason it seems to load it up in the background and keeps my app shown which is not what I want it to do.
On every other version of android when I execute the code to launch the browser the browser comes to the top of the screen therefore causing my app to be in the background which is how I wanted it to work.
Below is the code that I have to launch the browser
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(companyURL));
startActivity(intent);
The companyURL is a variable that I am using to parse the url to the browser.
Thanks for any help you can provide.
UPDATE
I have just discovered that if the browser is not currently running (i.e. not been loaded previously) when my app starts the browser it brings it to the front. However, once the browser has been previously loaded, when my app loads it up again, it loads it in the background.
Please try this it is working on ICS for me.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(companyURL));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Typically you don't need the CATEGORY_BROWSABLE category. Try the following instead:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(companyURL));
startActivity(intent);
In fact, the documentation seems to suggest CATEGORY_BROWSABLE is intended to be used in the opposite direction (browser to your app):
Activities that can be safely invoked from a browser must support this category. For example, if the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the BROWSABLE category, so that only activities supporting this category will be considered as possible actions.
http://developer.android.com/reference/android/content/Intent.html#CATEGORY_BROWSABLE
Try adding FLAG_ACTIVITY_BROUGHT_TO_FRONT flag to the intent.
I'm using following code and its working fine with me even when browser is already running in the background.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(intent);