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
Related
On the first boot itself, I want to set the default browser from the three that are already installed on the system. I do not want to give the user the option to select the default browser, I want to set it for him/her.
How do I go about it?
EDIT : The Phone is running ICS.
It is impossible to do. There is no API method which would allow this.
To do it on first boot make one receiver,whenever boot detects on that time call any activity and on activity onCreate method write this
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
This can be done if u develop your own firmware and make it a default app for internet uses.This requires the both firmware and boot permissions from the device to make ur application as the default application.
Any way you can set ur application as always to open the web pages in settings
In my app i want to use galaxy s4 S-translator.So is it possible to use it? And normally can i call another app from my app.I am very new to android.So I don't know it is possible or not.So if possible plz tell me.I think by using intent with giving proper action we can do it.
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("app package name");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
thanx
Yes, by using intents.
For example:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.setClassName("com.example.theotherapp", "com.example.theotherapp.MainActivity");
startActivity(intent);
This is called an explicit intent, because you're explicitly stating which component should respond to it. You can also use implicit intents, in which you specify what kind of component you expect and the OS and/or the user selects the most appropriate one.
If you can choose, implicit intents are preferred.
This might Help You.
I want to open pdf file using installed adobe reader. I tried in the following way to prevent "Complete action using" menu.
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(doc), "application/pdf");
startActivity(intent);
Using the above code i managed to reduce the list size to 2. Is there any way to avoid showing context menu (Complete action using).
Thank you!
Android system automatically displays "complete action using" dialog box when two activities have same intent filter action. Once you select the default action. Android will not display it & complete the task using default action.
I would like to thanks every one who tried to answer this question. After some browsing i found solution for my Question. which is perfectly working for me.
instead of using
intent.setPackage("com.adobe.reader");
I used
intent.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader");
don't forget to start activity in try catch block, it helps when adobe reader not installed on Device. Please check the below snippet.
try {
Intent intent = new Intent();
intent.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader");
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(doc), "application/pdf");
startActivity(intent);
}
catch (ActivityNotFoundException activityNotFoundException) {
activityNotFoundException.printStackTrace();
}
I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.
In my Android application, I use the following code to start the messaging app and fill in a default text for a text message:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"+USERS_PHONE_NUMBER));
intent.putExtra("sms_body", "DUMMY TEXT");
startActivity(intent);
This works in most cases. But unfortunately, on some devices I get the following error message:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=sms:+XXXXXXXXXX (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1510)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
at android.app.Activity.startActivityForResult(Activity.java:3131)
at android.app.Activity.startActivity(Activity.java:3237)
Obviously, the intent that I created cannot be handled.
Is there any mistake in my SMS intent code?
How can I prevent the application from crashing if the intent cannot be handled?
Should I use PackageManager.queryIntentActivities() or is there another way of solving this problem?
Thanks in advance!
I haven't tried this intent specifically, but the simplest way will probably be to add try and catch block
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Display some sort of error message here.
}
Since you can't count on the specific Android device to have the Messaging app (some tablets for example don't have telephony services), you have to be ready.
It is a good practice in general when you're starting external activities, to avoid crashes in your app.
Here is the code that will open the SMS activity pre-populated with the phone number to
which the SMS has to be sent. This works fine on emulator as well as the device.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:" + phoneNumber);
Here is a method I use to safely open activities on Android, and give the user some feedback if the activity is not found.
public static void safeOpenActivityIntent(Context context, Intent activityIntent) {
// Verify that the intent will resolve to an activity
if (activityIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(activityIntent);
} else {
Toast.makeText(context, "app not available", Toast.LENGTH_LONG).show();
}
}
(I think I got it from one of the Google Developers videos on youtube, but now I can't find the video...)