I've been learning Java for some time now to develop Android-apps. At this point, I want my website to redirect to my app. This should be possible using an Intent-filter for my website-url. I have used the stackoverflow.com homepage as example.
I use this code in a MainActivity section in the Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.example.webitent" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
So far, nothing interesting. This is literally a blank activity in a new project with the intent-filter added. I have target-sdk 21 and minimal sdk 16. However, whatever I try, it doesn't fire when I go to stackoverflow.com, neither directly nor through a href.
What is going on, or what am I doing wrong?
When you visit stackoverflow.com in your browser, the intent is not fired. An intent is fired only if the app explicitly does that. This is the case if the app (your browser) is not supposed to open your url scheme. For example mailto is opened in your Mail-App. So you have to create your own URL-scheme like this
<intent-filter>
<data android:scheme="myweb" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then a link to myweb://stackoverflow.com would open your app.
Related
I'm following the Android Codelabs, specifically I'm working on this Codelab with implicit intents.
The Codelab has the following method:
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
The problem is that the intent.resolveActivity(getPackageManager()) returns null, but if I omit this and just call the startActivity(intent), it works fine and opens the Uri in Google Chrome.
I'm wondering why intent.resolveActivity(getPackageManager()) returns null, even thought the Uri can be opened in Google Chrome?
The Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.implicitintents">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In this case the URL that we want to open comes from EditText field, so we can't use an intent-filter with android:host as described here.
In case you haven't solve the problem yet.
I don't know if you are using API level 30, but if you are you should check this new Package visibility restrictions. Package Visibility has changed and apps are no longer able to access the Package Manager directly. You need to add a element in your AndroidManifest file. In your case you would need something like this.
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
I had the same problem. I solved it by adding a request to use the browser in the manifest. Now my manifest file looks like this. Try reading this article.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.quakereport">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".EarthquakeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
A lot of problem for me:
Use queries into Android Manifest
<queries>
<!-- WebView -->
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<!-- Camera -->
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
<!-- Gallery -->
<intent>
<action android:name="android.intent.action.GET_CONTENT" />
</intent>
Remove
File sd_directory = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
return File.createTempFile(new_name, ".jpg", sd_directory);
and use
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
return new File(storageDir, imageFileName + ".jpg");
I'm new to Android app development so please be patient with me. I'm writing an app that gets the GPS location from Google Play services and then broadcasts the data over Bluetooth. I have a LocationActivity that gets the location, and an AdvertiseActivity that broadcasts the data.
My problem is that I'm having a hard time understanding the file structure in android apps, so I suspect my lack of understanding is why I'm getting the error.
Here is a snippet of LocationActivity where the error is:
#Override
public void onLocationReceived(Location location) {
Intent i = new Intent(LocationActivity.this, AdvertiseActivity.class) //problem is here
.putExtra("latitude", location.getLatitude());
startActivity(i);
}
Why can't the compiler find AdvertiseActivity.class? Is something wrong with my manifest below?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="com.android.app.LocationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.android.app.AdvertiseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Please help. Thanks!
You are using two activities as MAIN .From manifest, Remove:
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DEFAULT" />
From AdvertiseActivity's activity tag. Hope this helps.
Remove these lines from manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And keep only this line.
<activity android:name="com.android.app.AdvertiseActivity"/>
An Application can have only one android.intent.action.MAIN in Startup Activity. In your LocationActivity you already defined so remove intent-filter from AdvertiseActivity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
so its like
<activity android:name="com.android.app.AdvertiseActivity"/>
The user of my app can create a custom list with parent and child items. I store these informations in a xml file. I would like to give the user the
opportunity to share this file (Email etc.). If the other user clicks on this file I would like to open the app and show the data in my list!
What Ive done so far:
The user can create a xml-file and save it in his storage.
The problem now: How to open the app when clicked on the file? Do I have to create my own file extension that has the xml data inside?
EDIT:
<activity
android:name=".activities.TrainingSimpleShowActivity"
android:label="#string/title_activity_training_simple_show"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\\.xml"
android:mimeType="*/*" />
</intent-filter>
</activity>
No, you just have to set an intent filter for your app.
For example:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xml" android:mimeType="*/*" />
</intent-filter>
So when a user clicks to open on XML file your app can be proposed to open this file from the Android system.
Then you have to get the Intent in your app and handle the data.
Intent intent = getIntent();
Uri data = intent.getData();
Maybe you can write a guideline to write this XMl file for you users, and when your app get the date from the intent you can search a particular tag or attribute.
Hope this help you.
UPDATE
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dojester13.experimentintent">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xml" android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
</manifest>
So I have very weird problem with android app that I developed that I really do not understand how to address.
Description of the problem: When I run the app in my emulator(and many other emulators) the app works perfectly, but when I list it on Google Play and some user download the app, it automatically crashes. so I just wonder if my androidmainfest is properly written.
*the program written in esclipse, java, android.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app"
android:versionCode="6"
android:versionName="1.5" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.SurfaceExampleView"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.example.start" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.RulesGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.rules" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.PolicyGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.policy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.RevenueGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.revenue" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.ShopGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.shop" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
You have posted only your manifest and not the logs. My guesses based on that is the problem may be within your package declaration, rest everything seems fine.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app".....
The package should be unique and its like what we call package in java world. You have declared it as com.app whereas your app is using com.example.... package. Also com.app maybe used by other app.The package name defines your application's identity.
Once you publish your application, you cannot change the package name. As the package name defines your application's identity, so if you change it, then it is considered to be a different application and users of the previous version cannot update to the new version. So you may have to upload another app with different package name.
Try getting logs(use crashlytics) for your crash and we can look into it for the root cause.
I am at my wits end with this. I am trying to have the user click on a link in a text message and the phone direct them to my app. However it autommatically goes to browser. Please help!
My android manifest looks like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main activity -->
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="www.myapp.com"/>
</intent-filter>
</activity>
Looking at every forum I am doing this correctly yet it still does not work. Please help!
You need to use a broadcast receiver, it is the receiver that has to be configured on the intents you're listening on, when such an intent takes place your receiver should bring to foreground an activity or do whatever else you need to.
Something like this may help you achieve what your trying to do :
https://stackoverflow.com/a/525086/1542720