First of all i am sorry of my language:)
I have Application to showing available pdf files, which is downloading from server. Next I want to call available Application to show Pdf. When App to show Pdf is closed, i want to delete file from external storage.
Code of call another App:
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
java.util.List<ResolveInfo> list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
You have no way to reliably know "when App to show Pdf is closed", so you cannot delete the file this way.
You are welcome to give the user an option within your app to delete the file when the user knows that it is no longer needed.
Related
I am creating an Android Application in Delphi, and I need a Button, which deletes the default Share App, if one is set.
E.g
I share a File via Gmail, and press 'Always'
The next time, this is the default app.
Is it possible to delete this in Code? Or can i open the App-Infos where it is possible to reset this option?
clearPackagePreferredActivities() in PackageManager will clear the defaults of a particular app, whichever's package name you pass.
(https://stackoverflow.com/a/13072877/6517492)
You can open the application settings screen programmatically. Java code:
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
intent.setData(uri);
context.startActivity(intent);
(from https://stackoverflow.com/a/35456817/6517492)
I have an Android app that can open another app I have using:
Intent intent = new Intent();
PackageManager manager = getPackageManager();
intent = manager.getLaunchIntentForPackage("myOtherAppPackageName");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
Which works perfectly, the only thing is the app force closes when I don't have the other app installed, which makes perfect sense. My question is how do I get my app to open the Play Store to the specific app for someone to download if they do not already have the other app? I would assume do the exact same thing except I don't have the package name for the Play Store.
if you have the package name you can just do this
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + "packagename"));
startActivity(marketIntent);
that will launch the play store on the page for that application
If you know package lets use this example code:
public void offerApp(Activity activity) {
Log.d("Launching Market");
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=<PACKAGE>"));
activity.startActivity(i);
}
I'm trying to open market app from my app using:
Intent i = new Intent("Intent.ACTION_VIEW");
i.setData(Uri.parse("market://details?id=com.compamy.app"));
startActivity(i);
But I have No Activity Found Error. I am using real device and I have market installed.
So my question is: What can be done here?Thanks.
The only problem here is what zapl pointed out in the comments ("" around the action). The documentation (http://developer.android.com/guide/publishing/publishing.html) clearly states how to use this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
official documantation link:
http://developer.android.com/guide/publishing/publishing.html#marketintent
Opening the app details page from your Android app
To open the Google Play details page from your application, create an intent with the ACTION_VIEW action and include a data URI in this format:
market://details?id=
For example, here's how you can create an intent and open an application's details page in Google Play:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
Try this:
Uri uri = Uri.parse("market://details?id=com.compamy.app");
Intent i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
Assuming I know that the Gallery has an album with a certain name X, what intent or broadcast can I make to open Album X with the Gallery app?
There are plenty of examples showing how to select a picture from the Gallery, but I don't see any describing how to accomplish the above.
Thanks.
try this
Intent intent = new Intent();
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Main.this.startActivity(intent);
program will browser all application are support with image file
but user can set default program
If you prepared the Gallery which is called X, yes you can do it.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.Xapp");
if (launchIntent != null) {
launchIntent.setData("PHOTO ID OR ANYTHING ELSE");
startActivity(launchIntent);
}
After then you can set data in intent. And X app parses intent data and you can open it.
Otherwise, you can't this action. You only call the app, If the application does not provide API support for send data with intent.
I have an application that open an external application to read PDF files. here is the code to open the external app.
if(file!=null){
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0 && file.isFile()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
}else{
Toast.makeText(this, "problem loading file", Toast.LENGTH_LONG).show();
}
}
The problem is when I come back from my pdf application (adobe reader or any pdf reader app), in the first click of my back button I get a black screen and in second I can reach my activity? How could I possibly solve this problem?
I think this is probably the normal Activity lifecycle at work.
Once your Activity goes into the background, it is deemed no longer critical by the OS and its process may be killed in order to reclaim memory or resources for a foreground Activity. The black screen you see when pressing the back button is the window background of your application's theme which appears while your Activity is recreated and its state is restored.
This is normal behavior. Ensure that your Activity saves and restores its state efficently by implementing the appropriate lifecycle methods to reduce the time it takes to re-create.
See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle