I'm trying to make the gallery app share images to my app, the problem is that I don't know how to get the image data sent to me by the gallery. I assumed that I may found the data in the method .getData() but it returns null
this is my intent-filter
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.VIEW"/>
<data android:mimeType="image/*"/>
<category android:name="android.intent.category.default"/>
</intent-filter>
and here is my code in MainActivity
Intent data = getIntent(); //get the intent that starts this activity, in this case: gallery intent
if(data != null){
Uri uri = data.getData();
//set the image view: the problem is: uri is always null
imageView.setImageURI(uri);
}
if the method getData() is not what I want, then how can I get the image that meant to be shared with my app?
So, I think my answer is a little bit late, but anyhow, here it is:
You have already set the intent-filter in the AndroidManifest.xml correct like this:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
As on this Website stated, you get the URI with this command:
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
//set content of ImageView to the specific Uri
imageView.setImageURI(imageUri);
Dokumentation about the Intent class can be found here.
Related
I need to get some parameters that are coming from an external campaign, where when a user clicks on an external banner on browser my app needs to open,
currently it is happening as expected, my app is opening perfectly... but I need to get all the parameters that came with it.
My XML manifest ->
<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="external"
android:host="deeplink"
/>
</intent-filter>
URL I'm accessing when I click on the banner -> external://deeplink/?utm_source=abc&utm_medium=abc&utm_campaign=abc
code that I'm using in the deeplink receiver class ->
Intent appLinkIntent = getIntent();
Uri appLinkData = appLinkIntent.getData();
Log.d("taguison", "URI --->" + appLinkData);
Log.d("taguison", "utm_source--->" + appLinkData.getQueryParameter("utm_source"));
Log.d("taguison", "utm_media --->" + appLinkData.getQueryParameter("utm_media"));
Log.d("taguison", "utm_campaign --->" + appLinkData.getQueryParameter("utm_campaign"));
return ->logcat return image
what do i need to do to be able to access the remaining parameters that gave null
utm_media and utm_campaign ?
I want to associate files of particular extension (say, any file with the extension .xyz) with my app. This means, when user taps SaveFile1.xyz in File explorer (or other places, like gmail, drive etc.), my app should launch and the Uri of the file will be passed in an intent to my activity.
While this is the expected behavior, I don't know how to associate custom files. I have read and understood how intent matching works and the possible values in data tag, but it didn't work. I have checked some stackoverflow answers (Ex, this and this), but they use file scheme and pathPatterns.
We cannot use the pathPattern because we get a content uri (Uri with scheme=content), which is the abstracted path and will not have any extensions.
The mime type setting can be used only for the predefined values (like image/png can associate all png images with the app).
I could set the mime type as "*/*", but I don't want my app to accept every file (and then reject it in onCreate or something).
Has anyone solved this problem? Any help will be greatly appreciated.
I have the following in the activity tag of the manifest file.
<activity
android:name=".MainActivity"
android:exported="true">
<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:mimeType="application/pdf"/>
<data android:mimeType="image/png"/>-->
<!--<data android:scheme="content" android:mimeType="*/*"/>-->
</intent-filter>
</activity>
Edit1:
I set the mime type as "*/*" and added the following line in Activity.onCreate to see the type in the intent (and set it in the manifest file) ...
Intent dataIntent = getIntent();
Log.i(TAG, "dataIntent.getType() = " + dataIntent.getType());
.... but got the following as output.
dataIntent.getType() =
Its not even null.
I am new in android development, I want to build a music player but the problem in front of me is how do i make my app open from gallery.
For example,
if we want to open any music file then we select it, the the android mobile ask which player do we want to use.
so how can I add my app in that option.
please help.
If you want your app to be in the list for opening an audio file, you need to tell the system your app can open those files. You can do that by adding something like the following to your activity tag in your AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
<data android:mimeType="application/itunes"/>
</intent-filter>
Intent filters are part of the core principles in Android development. You should try to get some knowledge on these basic topics before getting started.
It helps you
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Actually you can open activity not app at self just simply add action intent filter in mainfest like this
<activity class=".foo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="com.me.love" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
other app code :
Intent intent = new Intent("com.me.love");
startActivity(intent);
however if you want to tell android system that your activity can handle some actions like share or send data you just have to add "send" action to your activity in mainfest like so :
<activity class=".boo" android:label="#string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
so now when ever user click share button android system will check all activitys that have action string "android.intent.action.SEND" then give the user list of activitys that have send action and if you did added same action as boo activity dose to your activity then it will be one of chooses in the list.
In IOS I have 2 apps (App A and App B) that will be performing different objective but at 1 point, App A will call App B using uri scheme to perform a function where App A does not have.
I wanted to implement this function to Android and currently have developed a demo for initiating call to App B. Now I am working on App B that will be receiving the uri scheme from the demo app.
Problem:
After App B return to the demo app using uri scheme I close the demo app.
When I go back to home page and open the multitask to reopen App B(or open App B through the icon), the page it reopen is the function that is used for demo app but what I wanted is the login page of App B.
This is a part of the Manifest for the intent-filter
<activity
android:name="com.apps.MasterActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="x-callback-url"
android:scheme="myapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
This is where I call back to the demo app
Intent sendIntent = new Intent(Intent.ACTION_VIEW, responseUri);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(sendIntent);
Try adding this to your activity tag in AndroidManifest.xml
android:clearTaskOnLaunch="true"
Apparently I kinda found a solution that can force the app to show the login page after going back to the demo app. By putting this code in the activity.java file.
#SuppressWarnings("deprecation")
#Override
public void onDestroy()
{
super.onDestroy();
System.runFinalizersOnExit(true);
System.exit(0);
}
I know its a deprecated function that I'm using but will try to solve it when there's something wrong in the future or when I found a better solution for it.
Edit:
Found a better solution that does not need to use the deprecated function which I have forgotten to set it to false.
I have a flag that is set to true when the app is connected through Uri Scheme which i just have to set it to false and it will be fixed. This is the change location that I made
Intent sendIntent = new Intent(Intent.ACTION_VIEW, responseUri);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(sendIntent);
Util.isUriScheme = false;
I want to know if it is possible to read the value of android:scheme from the Android-manifest-file (example below) programmatically.
<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="zxtest" />
</intent-filter>
You should be able to get this information from the PackageManager:
PackageManager pm = getPackageManager();
ActivityInfo activityInfo = pm.getActivityInfo(component,
PackageManager.GET_INTENT_FILTERS);
Unfortunately, however, you can't :-( This call SHOULD return the intent filters (according to the documentation), but it seems that the Android developers haven't gotten around to actually implementing it yet :-(
See Unable to get intent filters from a package
I'm assuming you mean that the intent has been called and you're trying to find the scheme from your activity's code?
In your activity's onCreate method, you can do the following:
Intent intent = getIntent();
Uri data = intent.getData();
String scheme = data.getScheme(); // "zxtest"