java.lang.SecurityException : Permission Denial, cannot get file from URI - java

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>

Related

How to use deep link in android

In my application i want use deep link for open urls with my application.
I write below codes, but when click on URL open this URLs in browser and not open in my app.
My manifest codes :
<activity
android:name=".activity.PostDetailsActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:screenOrientation="sensorPortrait"
android:theme="#style/DetailsActivityTheme" >
<!-- DeepLink -->
<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="www.example.ir"
android:pathPrefix="/*"
android:scheme="http" />
<data
android:host="example.ir"
android:pathPrefix="/*"
android:scheme="http" />
</intent-filter>
</activity>
My java codes:
Intent intent2 = getIntent();
Uri data = intent2.getData();
if (data!=null){
Toast.makeText(mActivity, ""+data, Toast.LENGTH_SHORT).show();
}
My url : http://example.ir/2018/06/24/content_title_url
How can i fix this issue and open into my app?

Trouble with init branch.io

I use branch.io for work with app link. AndroidManifest has intent-filter for Branch URI scheme:
<intent-filter>
<data android:scheme="***" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Also AndroidManifest has intent-filter for App Links:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="***.app.link" />
<data
android:host="***-alternate.app.link"
android:scheme="https"/>
<data
android:host="***.test-app.link"
android:scheme="https"/>
<data
android:host="***-alternate.test-app.link"
android:scheme="https"/>
LaunchMode for AppLinkActivity is singleTask. I init Branch in Application, in onCreate:
Branch.getAutoInstance(this);
After open AppLinkActivity I get instance and I init session:
Branch branch = Branch.getInstance(getApplicationContext());
branch.initSession((referringParams, error) -> {
LogFileUtil.writeLog("Finish init session");
if (error == null) {
//Кое что делаю
} else {
//Кое что делаю
}
}, this.getIntent().getData(), this);
When I open my app across AppLink referringParams isn't empty. And I can get required data.
But when app is open and I click AppLink from other app, that referringParams is empty. I think the problem is init Branch. How I can fix it?
You need to make sure that you override the onNewIntent() method in your AppLinkActivity. This will ensure that the same intent is returned.
Add the following snippet to your AppLinkActivity:
#Override
protected void onNewIntent(Intent intent) {
this.setIntent(intent);
}
Solution - you need to make AppLinkActivity class main. This activity must have one more intent-filter:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

Open .txt attachment from email in Android App

I've defined an intent-filter in my AndroidManifest.xml so that it should show my app as an option to open text files:
<activity
android:name=".Hosts.AddHostActivity"
android:label="#string/title_activity_add_host" >
<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="file" />
<data android:mimeType="text/plain" />
<data android:pathPattern=".*\\.txt" />
<data android:host="*" />
</intent-filter>
</activity>
Then I'm going to handle the opening of the text file like this:
Uri data = getIntent().getData();
if(data != null) {
// Parse text file
}
Although I'm not sure if that's the right way to go about it. Currently my app does not show in the list of apps that can open text files though so I assume something in my intent-filter definition is wrong?
I've updated my intent filter to change the mimeType and add BROWSABLE but still no joy.
<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:mimeType="text/plain" />
</intent-filter>
Turns out mimeType is the best way to go and you don't need the other junk :)

How can I handle file uploading to other apps and sites? Android

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

android intent-filter <data> is not working correctly

I am trying to have my application intercept on a specific URL in browser. following is my code in the Manifest:
<activity
android:name="com.myactivity.RootActivity">
<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" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="subdomian.maindomain.com" />
</intent-filter>
</activity>
it is working fine at the moment, when I open the link http://subdomain.maindomain.com/ , a dialog comes up with my activity listed on it.
but when I add android:path in the intent-filter like below, it stops working, it doesn't even work with simple url without the path.
<activity
android:name="com.myactivity.RootActivity">
<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" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="subdomian.maindomain.com" />
<data android:path="myPath" />
</intent-filter>
</activity>
am I doing something wrong here?
I tested what you said using these links and its working for me
<data android:scheme="http" />
<data android:host="developer.android.com" />
<data android:path="/guide/topics/manifest/data-element.html"/>
And the intent i used is
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://developer.android.com/guide/topics/manifest/data-element.html"));
startActivity(browserIntent);
The android:path must match after the host url that you gave for it to work ?
Can you specify what URL did you use ?
Read this link for help

Categories