No Activity found to handle Intent with http in the url - java

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.

Related

Android open external IMDB application from my app

I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.

Where to put welcome activity code

I searched a lot but i did not find my answer. I have developed an android application where on the very first lunch user will be shown a welcome screen made of viewpager. The problem is i don't know which place is the best to put the welcome activity code in my application.
The simplest way it could be that in the main activity at the very fist line even before super.onCreate(), inside onCreate method where i try to get the shared preference value and then evaluate whether it is fist lunch. If it is, then i start the welcome activity as shown below
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean welcome = sharedPreferences.getBoolean(getString(R.string.key_welcome), true);
if (welcome) {
// go and start welcoming activity
Intent intent = new Intent(this, WelcomeSlideActivity.class);
startActivity(intent);
}
super.onCreate();
}
}
But i found another approach to deal with it. It is Application class. Since Application class is the first one, which runs even before any other codes in my application. So i thought, i would be nice to do it there as shown below
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean welcome = sharedPreferences.getBoolean(getString(R.string.key_welcome), true);
if (welcome) {
// go and start welcoming activity
Intent intent = new Intent(this, WelcomeSlideActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
So i am in dilemma, which one would be the best option to choose. And i am even not sure if i am doing it in the right way since there is no such documentation in android developer website or anywhere.
Have a look at how to create splash screens the correct way. https://www.bignerdranch.com/blog/splash-screens-the-right-way/
As for using the Application class - this is primarily used for Application-wide configuration for maintaining a global application state. Hence starting an activity from here does not make much sense as it's purpose has changed into becoming an entry point into the application rather than providing state for the app as a whole.
Furthermore, why not make the WelcomeSlideActivity the first 'launcher' activity? Then in there, you can create the logic of whether to launch the next activity without history or whether to show the current view.
Ideally, you should create a splash screen activity, which determines whether to show the WelcomeSlideActivity Or the MainActivity. The advantage of this is that while he app determines which Activity to launch, the user is presented with a splash screen that informs the user that the app has started

Android Studio startActvity requires permission

I'm attempting to make a simple click action which calls a certain number, I'm on the last stage of the code and I cannot see what I'm doing wrong. Currently its the startActivity action which seems to be presenting the error but I don't know why I have watched multiple tutorials and I can see any difference. When above startActivity it informs me that a call permission is required?
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_home);
//On load the program automatically hides the taskbar.
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Button b = (Button) this.findViewById(R.id.BTNCall);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent PhoneCall = new Intent(Intent.ACTION_CALL);
PhoneCall.setData(Uri.parse("tel:123"));
startActivity(PhoneCall);
}
});
}
I have also added a permission into the android manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
You should set your target SDK version to lvl 22 or under, because for lvl 23 you need to ask user at run time for permission, look there for a better explanation.
Since you are doing it from a OnClickListener, the "this" pointer references to the clickListener class you are implementing, you need to get the reference to your activity just use:
MyActivityClassName.this.startActivity() //Dont know your class name
That should get rid of the red highlight.
If you are still getting a crash we will need the logcat output to solve it.
Hope this helps.

Opening Googlemaps App to a Specific Location

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

Android: How NOT to save instance state?

My app has login, once the access is granted, it creates a new html file to the sdcard, the output or the appearance of that html file depends on the account of the logger.
After writing, the app goes to the next activity
Intent nextActivity = new Intent(MyMainAct.this, AppView.class);
startActivity(nextActivity);
the AppView class is the next activity in which the UI is a webview. It views the html created on login.
When I click "login as different user" button, I go back to the Main Activity which is MyMainAct. I use the following code:
Intent nextActivity = new Intent(AppView.this, MyMainAct.class);
startActivity(nextActivity);
When I logged in again (as different user), I expected a different UI since the html created is different. But it did not happen. The same html of the first logger is presented by the webview.
I looked into the html code created by the second logger, it is different from the first. but the webview presents the html of the first logger.
Is it about instance state? That's what I think, that's why I don't want to save instance state (bundle).
EDIT:
How do I ignore savedInstanceState of my App?
my MainActivity:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
my AppView Activity:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Make sure that when user chooses the "login as different user" option, activity showing the HTML is finished (i.e. call the finish method on it). If you then ignore the savedInstanceState parameter in its onCreate event (which you likely do, I presume), the next time this activity is started it will be totally new instance of it.
Try this and see if it works.
Intent nextActivity = new Intent(AppView.this, MyMainAct.class);
startActivity(nextActivity);
finish();

Categories