I am working on a simple android file manager. The problem I am facing is getting my app to upload files to another app or site when someone wants to send files and such. I tried reading through the developer docs, but they were a bit confusing. How can I set up my MainActivity(If that is a good place to put this) to handle this and allow the uploading of files? Here is what I have in my manifest...
<activity android:name="com.myapp.MainActivity" android:label="#string/app_name"
android:configChanges="keyboardHidden|screenSize|orientation">
<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.GET_CONTENT"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:scheme="folder"/>
<data android:scheme="directory"/>
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
You don't need anything in your manifest file. Use Android's share intent to share content with other applications on the device. Here is the documentation: http://developer.android.com/training/sharing/send.html
The Example:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
Related
I'm trying to make an app that opens files in PDF format. I got stuck because when I click on a file and select my app to open them with, the URI I get through the Intent cannot be converted to an InputStream. Below is my code:
Uri uri = getIntent().getData();
try {
pdfView.fromStream(getContentResolver().openInputStream(uri))
.load();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
The URI I get when debugging looks like this:
content://com.mi.android.globalFileexplorer.myprovider/external_files/Download/3E-Summatif-C%CC%A7%C4%B1km%C4%B1s%CC%A7-Birles%CC%A7tirilmis%CC%A7.pdf
and I get this error:
Permission Denial: opening provider com.android.fileexplorer.provider.FileExplorerFileProvider from ProcessRecord{897bfb1 6648:com.example.pdfviewer/u0a585} (pid=6648, uid=10585) that is not exported from UID 10151
The compile SDK version is 29.
Thank you in advance!
EDIT:
The intent-filter of the redirected activity looks like the following:
<activity android:exported="true"
android:name=".PdfActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="content"
android:mimeType="application/pdf"
android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.pdf "
android:host="*"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
I have searched google every where to find a solution for 'Android App does not open through schema (default/chrome browsers)'. But I could not find a proper solution.
Below code set I added to Android Manifest.xml to link schema with browser.
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="com.qa-soft.team" />
android:pathPrefix="/"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.qa-soft.team" />
</intent-filter>
but when I access ( com.qa-soft.team://OPENPDF-INDEX.pdf ) through default/chrome browser, it will be redirected to google search.
Anyhow when I access through firefox browser, it is working fine. (load the app activity)
what is the real issue for this and how can I overcome it?
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>
I want to implement such functionality in my simple Android app: when user visits a certain link (www.example.org let's say) in the web browser - Android OS should open my Android application if it is installed.
I tried to play with intent-filters like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.org"
android:pathPattern="/.*"
android:scheme="http" />
<data
android:host="www.example.org"
android:pathPattern="/.*"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But it's not working at all in google chrome mobile browser. In firefox, when I visit that link I get such Android icon on the right side of the search bar:
When I press that icon - my app opens. But still it is not what exactly I want to achieve.
Any idea why my code above doesn't work? I tried many variations of intent-filter declarations which I found on internet but nothing seem to work. I have nexus 5 device with Android 6 installed.
I have found a solution to my problem. Whole internet is full of old examples.
Since chrome version 25, google made slight changes in app deep linking functionality. More info: https://developer.chrome.com/multidevice/android/intents
So my working code looks like this:
Intent filter in Android side:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="launcher"
android:path="/"
android:scheme="test" />
</intent-filter>
Web page html:
Launch app
Try it like this, removing the path pattern:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
More info:
Launch custom android application from android browser
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.org"
android:scheme="http" />
</intent-filter>
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