Opening PPT-Files - android

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

Related

How Click button to Open browser?

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);
}

Open PDF-File in Android not working

I try to open a pdf file from my apps directory through a pdf viewer on the device.
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p;
try {
p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;
} catch (NameNotFoundException e) {
Log.w("Error", "Error Package not found ", e);
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s + "\\Document.pdf"));
intent.setType("application/pdf");
PackageManager pm = getPackageManager();
Intent crC = Intent.createChooser(intent, "Open File"); startActivity(crC);
On the test device is an pdf viewer installed. Nevertheless I'm told that no existing app is able to open that file. Am I doing something wrong?
If anybody is still interested, here is my solution:
I simply changed the code from this:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s + "\\Document.pdf"));
intent.setType("application/pdf");
to this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(s + "\\Document.pdf"), "application/pdf");
And suddenly it worked. :)
What is the following code supposed to do?
PackageManager pm = getPackageManager();
Intent crC = Intent.createChooser(intent, "Open File"); startActivity(crC);
I assume you looked at a few tutorials and got a mixture of everything in here. Instead of those two lines, just try
startActivity(intent);
Does that not work?

Android - Image share intent like Androidify app

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);

Intent to System's "Downloads" application

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);

how to get a list of installed video players programmatically?

I know its similar to this question How to get a list of installed media players, but I am not able to get a list of installed players. Can someone help me on this?
Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI,"1"); intent.setData(uri);
playerList = packageManager.queryIntentActivities(intent, 0);
Intent resolveIntent = new Intent(Intent.ACTION_VIEW);
resolveIntent.setDataAndType(Uri.parse("file://"), MIMEType);
List<ResolveInfo> pkgAppsList = mContext.getPackageManager().queryIntentActivities(resolveIntent, PackageManager.MATCH_DEFAULT_ONLY| PackageManager.GET_RESOLVED_FILTER);

Categories

Resources