i have develope a programm for android to get rdp connections.
My problem is:
When i use ES File Explorer, i can open the rdp-file with "open with and choose RD Client" and it works perfectly, the app will show the login credentials.
In my program there is a button, when i click them it will open the RD Client app and it show a message: The rdp-file is not valid...
here is the code-fragment:
File file = new File("/sdcard1/SRV01.RDP");
Uri data = Uri.fromFile(file);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(data, "application/*");
startActivity(i);
and my alternative:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.microsoft.rdc.android");
Uri data = Uri.parse("file://" + file);
LaunchIntent.setData(data);
LaunchIntent.setType("rdp");
startActivity( LaunchIntent );
I didn't find the failure. I hope there is anyone who can help me.
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/test.rdp");
Uri data = Uri.fromFile(file);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(data, "application/rdp");
startActivity(i);
Related
i'm trying to send (install) my mcpack file using this code but is is not working, minecraft support this type of extenstion to install mods (.mcpack, .mcaddon, .mcworld, .mctemplate, .modpkg how we can define mimetypes for these extensions)
please go through this image i need exactly like this https://imgur.com/14rIBvN
try {
//File path = new File(getFilesDir(), "dl");
File file = new File(path);
PackageManager manager = this.getPackageManager();
// Get URI and MIME type of file
Intent share = new Intent(Intent.ACTION_SEND);
//share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
share.setPackage("com.mojang.minecraftpe");//package name of the app
startActivity(Intent.createChooser(share, "Select Minecraft to install"));
} catch (Exception e) {
Log.i(TAG, "App not found.. "+e.getMessage());
}
i did it!)
File file = new File(this.getExternalFilesDir(null), "1.mcpack");
Uri photoURI = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
// set the content type and data of the intent
intent.setDataAndType(photoURI, "application/octet-stream");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// start the intent as a new activity
startActivity(intent);
Open with minecraft and it will open and it will day download started and if it works it will say, If it does not work it will say, Minecraft onlu supports .mcpack, .mcworld, .mctemplate on pocket edition
I'm trying to play video files stored in android internal memory through intent. Files exist there but when i try to play them through intent, it give me the error "Media file not supported" or "can't play video" depending on device. I couldn't find where i'm wrong. here is my code
File mydir = activity.getDir("Videos", Context.MODE_PRIVATE);
File fileWithinMyDir = new File(mydir, filename);
String videoResource = fileWithinMyDir.getPath();
Uri intentUri = Uri.parse(videoResource);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(intentUri, "video/mp4");
startActivity(intent);
I don't know where i'm wrong and what should i do. any help would be much appreciated. Thank you :)
Thank you so much friends for participation, your efforts are very much appreciated. I'v found the solution of my problem. There is need to set file read true before playing it.
fileWithinMyDir.setReadable(true, false);
Now here is complete code of intent to play mp4 video from internal storage of android.
File mydir = activity.getDir("Videos", Context.MODE_PRIVATE);
File fileWithinMyDir = new File(mydir, headingsList.get(mPosition));
fileWithinMyDir.setReadable(true, false);
String videoResource = fileWithinMyDir.getPath();
Uri intentUri = Uri.fromFile(new File(videoResource));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(intentUri, "video/mp4");
startActivity(intent);
This code works for me:
Uri fileUri = Uri.fromFile(new File(String file_path));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, URLConnection.guessContentTypeFromName(fileUri.toString()));
startActivity(intent);
i new to android application developemnt. I am trying to open the pdf file stored in sd card.I used this code snippet but this opens the viewer in the device but not the file given in the path. Any help appreciated.
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("Environment.getExternalStorageDirectory().getPath()+/sample.pdf"));
intent.setType("application/pdf");
intent.setPackage("com.adobe.reader"); selects the adobe reader directly
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent,0);
if (activities.size() >= 0)
{
startActivity(intent);
} else {
Toast.makeText(this, "No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
you can read pdf file from sdcard by giving the path and try the following.
File pdfFile = new File(path);
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(uractivity.this, resource.getString(R.string.noapplicationpdf), Toast.LENGTH_LONG).show();
}
}
You can try something like
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(filename);
intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
startActivity(intent);
or
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
startActivity(intent);
How come every time i try to open a pdf file in my SDCARD using the following code, it doesn't actually open the pdf file itself, but goes into the menu of adobe reader? Is there anything wrong with my code?
Intent intent = new Intent();
File pdfFile = new File("/sdcard/sample.pdf");
Uri path = Uri.fromFile(pdfFile);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(path);
intent.setType("application/pdf");
intent.setPackage("com.adobe.reader");
startActivity(intent);
No, there's nothing wrong. You've set the type to pdf and specified the package as adobe.reader. What that does is fire off an intent to launch the pdf in adobe reader. There's no way to display a pdf directly in your app without using a library (or writing code yourself) to render PDFs and display them.
Note that if you only set the type and not the package, the system will find whatever app is available to display PDFs
EDIT
You can try something like
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File( filename );
intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
startActivity(intent);
or
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
startActivity(intent);
Here I am giving my pdf file name. You give your file name.
private static String FILE = Environment.getExternalStorageDirectory().getPath()+"/TestPDF.pdf";
File file = new File(FILE);
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
I am trying to create program that simply opens file on sdcard. I tried opening mp3, mp4, and apk - the code bellow always crashes unexpectedly.
String _path = "file:///sdcard/1.apk";
Uri outputFileUri = Uri.parse(_path);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Market links also crashes. But when I set _path="http://google.com" - browser opens normally. How can I make this code work?
If you're trying to install the apk, you need to use the following:
String fileName = Environment.getExternalStorageDirectory() + "/1.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
If you're trying to launch the app (after installing), then:
Intent intent = new Intent();
intent.setClassName("com.pkg.addr", "com.pkg.addr.MainActivity");
startActivity(intent);
If you're trying to launch a player to play the mp3 file:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("file:///sdcard/1.mp3");
intent.setDataAndType(data,"audio/mp3");
startActivity(intent);
Hope that helps.