Callback from chooser - android

I just started implementing a share functionality but was wondering if its possible to tell how my content was shared (facebook/twitter/text/etc) without writing my own implementation of chooser. My initial guess was to use startActivityForResult when launching the chooser but haven't managed to figure out which requestcode to use.
public void share(String subject,String text) {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, getString(R.string.share)));
}
Any help would be greatly appreciated! :)

My initial guess was to use startActivityForResult when launching the chooser but haven't managed to figure out which requestcode to use.
That will not work reliably. ~99% of activities are not set up to work with startActivityForResult.
I just started implementing a share functionality but was wondering if its possible to tell how my content was shared (facebook/twitter/text/etc) without writing my own implementation of chooser
Sorry, you will need to write your own chooser for this.

Related

Android share text always ask for application

I use this code to share text from my application:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, GetTxt());
intent.setType("text/plain");
startActivityForResult(intent, REQUEST_SEND_MSG);
and it appear the activity where I can choose the application on which I want to share.
I noticed if I click on "Always open with..." I can't change it.
So how do I force the user to always select for application?
On api 29 "PackageManager.clearPackagePreferredActivities" is deprecated so what can I use?
You can try with an intent chooser like this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, GetTxt());
intent.setType("text/plain");
startActivityForResult(intent, REQUEST_SEND_MSG);
Intent openInChooser = Intent.createChooser(intent, "Share");
startActivityForResult(openInChooser, REQUEST_SEND_MSG);
It's generic, so you can share your text with what you want
Your app cannot clear the preferred activities from other apps that are set by the user as default activities. Up until API 28 you could use clearPackagePreferredActivities to unset the default activities if they belonged to your app, but now with API 29 this is deprecated.
This method was deprecated in API level 29.
This function no longer does anything. It is the platform's responsibility to assign preferred activities and this cannot be modified directly. To determine the activities resolved by the platform, use resolveActivity(Intent, int) or queryIntentActivities(Intent, int).
Instead, it's suggested your app queries for role availability with Role Manager.
To configure an app to be responsible for a particular role and to check current role holders, see RoleManager.
That said, there is also this answer with a hack method of achieving that, but I have no clue if it still works or not. Also, I imagine if it works, it would only work the first time.

Taking audio uri from intent

I'm stuck, and I can't manage to find a solution to it :/
What I'm doing is an app of sounds effects with sounds preloaded and choosen by the user, so I have default buttons with default sounds and the possibility of adding (as many as you want) buttons with sounds choosen by you.
So here's my part of code of the add-button:
public void add (View v){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
startActivity(Intent.createChooser(intent, "Select music"));
}
The output should be an uri and I need to get that (I'll use it to take the path of the file choosen by the user), but I don't know how.
Oh, I understood :)
For those who are trying to find a solution to that as me:
You don't have to use startActivity() but startActivityForResult() and then use the getData() method on the intent parameter of the onActivityResult() callback.
Here's the guide:
https://developer.android.com/training/basics/intents/result.html

Start Wikipedia via Intent

I tried to start the Wikipedia App via Intent but I always get an InvocationTargetException, because the Activity can't be found. I can detect that Wikipedia is installed, but I can't start it. I know that I can also use the Intent Filter and call the Wikipedia URL, but then the user can decide between app and browser (both works different with the search param, which is not very useful) and I want to decide it for the user.
I tried it with following code:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "searchString");
intent.setType("text/plain");
intent.setPackage("org.wikipedia");
Can somebody tell me, what I am doing wrong there or is it just not possible to start the wikipedia app? :-/
Finally I come to a solution after I was looking in the wikipedia code on github (https://github.com/wikimedia/apps-android-wikipedia). The app listens only for View Intents, which means that following code works:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(searchUri);
intent.setPackage("org.wikipedia");
The problem here is, that only URI's for existing articles were handled and no search operation can be used. After watching a little bit more in the code, I found a PageActivity which also listens for ACTION_SEARCH Intents. This would work, when in the AndroidManifest.xml this Intent Filter would be also available.

(Android) ShareActivity crops space from the title

I try to implement a share functionality in my app. But it seems impossible to make a nice title in the activity if I have a scrollable list in there.
Here is a picture that you know what I mean:
my shareActivity
and this is how it should look like:
google chromes shareActivity
The language is not the problem.
This is the way I try it:
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(intent, "share"));
Did anyone has this kind of problem too and can help me?

How do we find the information for launching other app?

I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.

Categories

Resources