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>
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've made an NFC application who can reads NFC tag. It works well. (With all types)
But since yesterday i'm trying to start automatically my app once a NFC tag is maintained against my device.
So i've updated my Manifest :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
Then, here is my nfc_tech_filter.xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
And surprise, it works only when I hold a NFC Type 2 against my device.
I've try with my appartement key (Mifare Classic) and my bank card (IsoDep), and it doesn't launch my app...
I specify that it works when my app is already started.
Any idea?
EDIT :
This is my Manifest right now :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="#xml/nfc_tech_filter" />
</activity>
Now, when I pass my bank card, it opens the application but doesn't display any result.
Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);
rawMessages variable is NULL after that. Same if I put NfcAdapter.EXTRA_NDEF_MESSAGES
ACTION_TAG_DISCOVERED:
This intent is started if no activities handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intents.
https://developer.android.com/guide/topics/connectivity/nfc/nfc
You get this Intent when no others has captured it, so there is something wrong in your setup.
You can capture it explicitly like:
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
I use the OSMand Navi app. In there I want to click on a point a hit the Share button. Then there is a list of apps I can send the coordinates to.
I want my app being in that list. I read about it and added an <intent-filter> to my AndroidManifest.xml.
<application
<activity
android:name=".MyMainActivity"
android:label="My App" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
But my app is still not on the list. I even tried to reinstall it and restarted my phone.
"Share" is usually implemented via ACTION_SEND, not ACTION_GET_CONTENT.
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.
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