I am trying to open Gogole Maps to a specific location with the below code, however the app is crashing with the error "No Activity Found to Handle Intent". Can anyone see what the problem is ?
ImageButton addressbutton = (ImageButton) findViewById(R.id.addressbutton);
addressbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String uri = "geo:0,0?q=MCNAMARA+TERMINAL+ROMULUS+MI+48174";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(uri));
startActivity(i);
}
});
The code works fine. The problem is the device/emulator you are testing the code at.
If you use AVD having Google APIs target (any level since 3), it works as expected. However, if you use AVD having normal Android target (that's a target without maps support), you get the error.
Try adding this:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
before the call to startActivity.
HTH
try this
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse(uri));
instead of
Intent i = new Intent(Intent.ACTION_VIEW);
Related
I have searched and searched and searched for hours on this and can't find a solution that makes any sense for my problem. I am simply trying to open a web page from inside my android application. Should be simple, but I keep getting the No Activity found error and the app crashes. My code is extremely simple for this...
AboutActivity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
Button appsButton = findViewById(R.id.about_button);
appsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(Keys.MARKET_LINK));
intent.setPackage(getPackageName());
startActivity(intent);
}
});
}
in my Keys class...
public static final String MARKET_LINK = "https://play.google.com/store/apps/dev?id=<MY ID>";
Every time I click the "aboutButton" in the app I get the error...
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.VIEW
dat=https://play.google.com/...
Everything I have found online all say the exact same thing... Your url didn't contain the "http://" part so it failed, but you can see my url does contain the "https://" part of the url. It is a complete URL, I can type it into a browser window and the page opens up perfectly. I don't understant how it can not have an activity to handle an Intent.ACTION_VIEW. I have no idea where to go now since everything online says add "http://" to the url and it will work, but it doesn't. Also, I do have the
<uses-permission android:name="android.permission.INTERNET />
in my manifest file. Any help would be appreciated, it is driving me insane. Thank you
You are targeting a specific package with
intent.setPackage(getPackageName());
So the system is looking for an intent filter within your app to handle the intent. If you remove this it will look through other apps on the device and find browsers which should allow you to open them.
This question already has answers here:
Android ACTION_SEND event: "messaging failed to upload attachment"
(2 answers)
Closed 5 years ago.
I am trying to create a Sharing Intent for an Android App to share images to other apps. However, I'm getting this really weird result when implementing this feature.
I have a share button that when I click on the button, it runs the following method:
private void shareIntent() {
Uri currUri = Uri.parse(data.get(pos).getUrl());
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, currUri);
sharingIntent.setType("image/jpg");
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.share_to)));
}
data.get(pos).getUrl() returns the URL of a custom class I made that implements Parcelable, and when printing it out, it returns a directory like the following: "/storage/emulated/0/Pictures/primitive/Primitive-79538313.jpg"
The intent works at first, opening the sharing menu. However, when I click on most applications, it either crashes the application or it gives an error... except with Google Photos, which uploads the photo properly to the gallery.
Firstly, I'm wondering what I'm doing wrong to cause this issue in the other apps. Also, I'd like to know if someone has an explanation as to why only Google Photos allows the sharing feature to work, while many of the other apps I've tested do not.
For reference, here are some examples I've run with the sharing intent. When I try to share the image, it crashes Hangouts. It gives a "failed to load image" error message in Snapchat, "Unable to share file" in Slack and Gmail, "Upload was unsuccessful" in Drive, "Messenger was unable to process the file" in, well, Messenger, and "Couldn't load image" in GroupMe. It doesn't load the image in Facebook but doesn't crash nor give an error.
Thank you for any help or feedback you can provide!
EDIT:
This seemed to work without trying to get around App Permissions:
private void shareIntent() {
File imageFile = new File(data.get(pos).getUrl());
Uri uriToImage = FileProvider.getUriForFile(
this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(DetailActivity.this)
.setStream(uriToImage)
.getIntent();
shareIntent.setData(uriToImage);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Thank you to everyone that responded!
Change your code to this
private void shareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jepg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+data.get(pos).getUrl()));
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Add this code in your activity onCreate()
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Mixare has an application (Open source) that lets you view POIs with your camera. It gives you the possibility to call the app from your application thanks to this :
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("http://ws.geonames.org/findNearbyWikipediaJSON"), "application/mixare-json");
startActivity(i);
The problem is that user must have the app installed in addition to my app, so what I did is that I imported the whole app within mine, with all its resources and stuff.
But I don't know how to call the main activity MainActivity.java, which resides in the package org.mixare.
How can I make an intent to call this activity ? And how do I declare it in the manifest ?
If you have added the code and resources of the app to your own app, then you should declare and call it's activities as they were your own.
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
This being said, it's not a trivial task. You need to merge AndroidManifest and could get into trouble if you don't know what you're doing. For instance, user can have the Mixare app in addition to yours and intent could have same actions etc.
There is an alternative to this. You could check if Mixare app is installed and if not ask user to do so. This could be more "android way of doing things", depending on your use case.
Look at,
http://code.google.com/p/mixare/wiki/DisplayYourOwnData for how to start mixare via Intent.
Alternatively, you can use mixare as your library project and then call its MainActivity class directly from your application as Using an Android library project Activity within another project.
Quoting the same here -
Declaring library components in the manifest file
In the manifest file of the application project, you must add
declarations of all components that the application will use that are
imported from a library project. For example, you must declare any
, , , , and so on, as well as
, , and similar elements.
Declarations should reference the library components by their
fully-qualified package names, where appropriate.
Then you can definitely call,
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
No, it is very hard to do a 2+2=4 kind of addition of manifest files etc.
I see there are two ways to handle this:
Use the external app: Check if the user has external app you want him to have. Else, direct him to the right link. You can get the package name of the publiched app and use it in this function:
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed ;
}
Combining code: This has no direct/correct answer. You need to study the code and integrate with your existing one.
//appPackageName,appClassName can be found in Logcat
ComponentName component = new ComponentName("appPackageName","appClassName");
Intent intent = new Intent();
intent.setComponent(component);
startActivity(intent);
Hi I want to browse to a file explorer and select a pdf or image present in some directory.
I want the code to do the same.
the below code takes me to gallery and help me choose image but I want to move to file explorer then select file and accordingly I want the code in onactivityResult after selecting.
browsePic.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
);
startActivityForResult(i, LOAD_IMAGE_RESULTS);
}
});
I believe you can throw out an open intent for a file chooser using the following.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
try{
startActivityForResult(intent, LOAD_IMAGE_RESULTS);
} catch (ActivityNotFoundException e){
Toast.makeText(YourActivity.this, "There are no file explorer clients installed.", Toast.LENGTH_SHORT).show();
}
The trouble is however, this assumes your user has a file browser open to accepting intents installed on their device, when often no such apps are installed on a device by default.
As in the code above, you may have to throw up a dialog if no Activities exist that can accept this intent, explaining that they need to install a file browser. You could even recommend one that you know works with your application.
I hope this helps.
i think you could do something like this
File strDir = new File("/mnt/"); // where your folder you want to browse inside android
if( strDir.isDirectory()){
//do something
}
i am developing an android app where i want to open the Battery use intent which is present in About device part of settings programatically. I am using the below code for it.
Intent i = new Intent();
i.setAction(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS);
startActivity(i);
The above code opens the About Device intent. But i want to open the Battery use option which is inside the About device part of Settings. Not getting how to do it. Please Help! Thanks!
Intent intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
startActivity(intentBatteryUsage);
Try this..
Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerUsageIntent, 0);
if(resolveInfo != null){
startActivity(powerUsageIntent);
}