How can i call an intent, to start the Downloads application, that is native in the Android OS.
I have searched a lot for this , and this is as close as I got:
Intent i = new Intent();
ComponentName comp = new ComponentName("com.sec.android.providers.downloads","com.sec.android.providers.downloads.DownloadActivity");
i.setComponent(comp);
i.setAction("android.intent.action.VIEW");
self.startActivity(i);
I have also tried:
Intent i = new Intent();
PackageManager manager = getActivity().getPackageManager();
i = manager.getLaunchIntentForPackage("com.sec.android.providers.downloads");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
but it gives me a JavaNullPointerException at: i.addCategory(Intent.CATEGORY_LAUNCHER);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
Uri uri= Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
i.setData(uri);
startActivity(i);
Related
Its working properly in every API level, but not working properly on Lolipop(api 21)
Code is here:
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://www.google.com/"));
internetIntent.setComponent(new ComponentName(
"com.android.browser",
"com.android.browser.BrowserActivity"));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(internetIntent);
Check this code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://www.google.com/"));
startActivity(intent);
Yes, it wont work in Lollipop, or may not work on any brand Manufactured(Sony,Samsung) phones, because you are trying to open an application with package name com.android.browser
internetIntent.setComponent(new ComponentName(
"com.android.browser",
"com.android.browser.BrowserActivity"));
In Lollipop default browser is chrome, which has package name something else. And there is no application with package com.android.browser in Lollipop.
Same thing can happen to any other Sony/Samsung phones.
What you can do is either call for a Application Chooser Dialog or find the default browser application, and open it
1) Code for Application chooser:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
startActivity(intent);
2) Code to Find default app and launch it:
ComponentName cn=null;
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));
ResolveInfo resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.activityInfo.packageName.equals("android")) {
List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo info : resolveInfos) {
if (!info.activityInfo.packageName.equals("android")) {
cn = new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
}
}
if(cn==null)
cn = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
} else {
cn = new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
}
if(cn!=null){
Intent openIntent = new Intent();
openIntent.setComponent(cn);
openIntent.setData(Uri.parse("http://www.google.com/"));
startActivity(openIntent);
}
I need to find all applications (among installed ones) that can open SMS. I have already found Gallery applications through the following method:
PackageManager pm = getPackageManager();
Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setType("image/*");
allApps = pm.queryIntentActivities(newIntent, PackageManager.MATCH_DEFAULT_ONLY);
It gives me the list of all apps that can open images. Is there any similar way by which I can find all apps that can open SMS Messages?
You need to set set type as vnd.android-dir/mms-sms
Try this code :
Uri uri = Uri.parse("smsto:123456789");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "SMS text");
OR
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", "SMS text");
intent.putExtra("address", "123456789");
intent.setType("vnd.android-dir/mms-sms");
Hop it will help you :)
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
Try this?
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.putExtra(Intent.EXTRA_TEXT,"Your Text");
sendIntent.setData(Uri.parse("sms:"));
startActivity(sendIntent);
I want to create an image share intent with the same options that appear in the Google's Androidify app:
I tested with Intent.ACTION_SEND and with Intent.ACTION_ATTACH_DATA, and have obtained the same results but separately, and I want them to appear together, for this I tried using Intent.EXTRA_INITIAL_INTENTS:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
Intent attachIntent = new Intent(Intent.ACTION_ATTACH_DATA);
sendIntent.setDataAndType(getTempImageUri(), "image/jpg");
attachIntent.setDataAndType(getTempImageUri(), "image/jpg");
Intent chooserIntent = Intent.createChooser(
attachIntent, getString(R.string.share) + ":");
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS, new Intent[] { sendIntent });
startActivity(chooserIntent);
But the second Intent results appears as Android System:
Obviously, the method used by the Androidify app is a mix of Intent.ACTION_SEND and Intent.ACTION_ATTACH_DATA. Anyone know how to do it?
Thanks for the help!
Finally I found how to do it, thanks to this answer:
https://stackoverflow.com/a/11038348/710274
This is my final code, I'm sure someone will find it useful:
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
Intent attachIntent = new Intent(Intent.ACTION_ATTACH_DATA);
sendIntent.setDataAndType(getTempImageUri(), "image/jpeg");
attachIntent.setDataAndType(getTempImageUri(), "image/jpeg");
Intent openInChooser = Intent.createChooser(sendIntent, "Share with:");
List<ResolveInfo> resInfo = pm.queryIntentActivities(attachIntent, 0);
Intent[] extraIntents = new Intent[resInfo.size()];
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(getTempImageUri(), "image/jpeg");
extraIntents[i] = new Intent(intent);
}
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);
I want to open a PPT-file with my app. How can I check if there is an app that can display these files installed on the device and how can I launch it?
Try something like this. Havent tried but might work
final Uri uri = Uri.fromFile(file);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
if(list.size() > 0)
startActivity(context, intent);
File file = new File("path_to_the_file.ppt");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.ms-powerpoint");
startActivity(intent);
try with this
Is there a way run an intent from packageinfo? I've been searching and I don't find it.
I tried like that
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(new ComponentName(p.applicationInfo.packageName,p.applicationInfo.name));
startActivity(i);
but it doesn't work because p.applicationInfo.name is always null.
The following code worked for me using SDK 8.18
Assuming that "p" is your PackageInfo
ApplicationInfo appInfo = p.applicationInfo;
String packageName = appInfo.packageName;
startIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if(startIntent != null){
startActivity(startIntent);
}
Try use folowing code:
Intent i = getPackageManager().p.applicationInfo.packageName(p.applicationInfo.packageName);
startActivity(i);
before start activity you may setup any flags (i.setFlags()), if you need.