Implicit intent from test application - android

I am new for implicit intent part of android.
In my application I have registered the intent like below:
<activity
android:name="ihpc.mocha.fakertt.view.MainActivity"
android:label="#string/app_name"
android:screenOrientation="reverseLandscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data
android:host="mocha"
android:path="/RTT/reset"
android:scheme="content" />
</intent-filter>
</activity>
<activity
android:name="ihpc.mocha.fakertt.view.SessionTimeOutActivity"
android:label="#string/app_name"
android:screenOrientation="reverseLandscape" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="mocha"
android:path="/RTT/sessionTimeOut"
android:scheme="content" />
</intent-filter>
</activity>
Now I want to trigger these intent from some test application but I do not know how to achieve that? I tried googling the same but could not find appropriate solution.Please suggest the way to do it.

your intent filter will catch all the intent with the "android.intent.action.VIEW" key. so if any application send an intent with this your application will receive. To test from another test application try this
intent = new Intent("android.intent.action.VIEW");
// if needed put some extra data
startActivity(intent);

Related

How to show chooser Intent with my own android app on click of WhatsApp location?

If there's a WhatsApp chat which has location shared, when clicked it shows a chooser intent with some set of applications. I want to write an intent filter so that my application will also be listed there.
You can do it by supporting implicit intent to your Activity.
Define intent-filter to Activity to which you want to open after clicking to your Application from options.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="geo"/>
</intent-filter>
</activity>
To know more about Intents and Intent filters go to official website.
https://developer.android.com/guide/components/intents-filters
Add this to your Manifest file (Particular activity):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="geo" />
</intent-filter>

Unable to start activity by using the package name

I am trying to use a library where I have to pass the action and the URI and to open the activity I have to use the package name but the thing is even I change the package name it is not working at all
this is the code that I am trying
Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse(filename));
intent.putExtra("was_get_content_intent", mWasGetContentIntent);
intent.setClassName("neelay.mediaplayer.beatbox.ringdroid", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
startActivityForResult(intent, REQUEST_CODE_EDIT);
and this is my manifest code for setting the activity
<activity
android:name=".ringdroid.RingdroidSelectActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
<activity
android:name=".ringdroid.RingdroidEditActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/edit_intent">
<action android:name="android.intent.action.EDIT" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
The package name is package="neelay.mediaplayer.beatbox"
I know it is easy to open the activity by just calling the names of the activity but in this case i have to pass the action with a uri and this is the only possible way i can see and guide will be helpful .
You said your package name (in the manifest) is "neelay.mediaplayer.beatbox". In that case you need to change this:
intent.setClassName("neelay.mediaplayer.beatbox.ringdroid", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
to this:
intent.setClassName("neelay.mediaplayer.beatbox", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
Since there are a number of ways to set the Component, you can also use any of the following methods:
intent.setClassName(this, "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
or like this:
intent.setClassName(getApplicationContext(), "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity");
or like this:
intent.setComponent(new ComponentName("neelay.mediaplayer.beatbox", "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));
or like this:
intent.setComponent(new ComponentName(this, "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));
or like this:
intent.setComponent(new ComponentName(getApplicationContext(), "neelay.mediaplayer.beatbox.ringdroid.RingdroidEditActivity"));

Add new contact on Android no activity to handle intent error

I am trying to add new contact to android and receive this ActivityNotFoundException: No Activity to handle intent. I am pretty sure that I need to use intent filter to resolve this problem but have no idea how.
Intent addContactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
addContactIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "My Name");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, "123456789");
startActivity(addContactIntent);
Here is my manifest file:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<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:mimeType="application/com.example.android.beam"></data>
</intent-filter>
<intent-filter>
<action android:name="com.android.contacts.action.SHOW_OR_CREATE_CONTACT" />
<data android:scheme="mailto" />
<data android:scheme="tel" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
try changing these to
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
// Just two examples of information you can send to pre-fill out data for the
// user. See android.provider.ContactsContract.Intents.Insert for the complete
// list.
intent.putExtra(ContactsContract.Intents.Insert.NAME, "some Contact Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "some Phone Number");
you will have to add this permission also
<uses-permission android:name="android.permission.READ_CONTACTS"/>

How to make my Android app appear in the share list of another specific app

<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
this is in my manifest file
this will make my app appear on the share list of all apps
but I want my app to appear in the share list of another specific app
and I don't own the other app
Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()
private void onSharedIntent() {
Intent receiverdIntent = getIntent();
String receivedAction = receiverdIntent.getAction();
String receivedType = receiverdIntent.getType();
if (receivedAction.equals(Intent.ACTION_SEND)) {
// check mime type
if (receivedType.startsWith("text/")) {
String receivedText = receiverdIntent
.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
//do your stuff
}
}
else if (receivedType.startsWith("image/")) {
Uri receiveUri = (Uri) receiverdIntent
.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
//do your stuff
fileUri = receiveUri;// save to your own Uri object
Log.e(TAG,receiveUri.toString());
}
}
} else if (receivedAction.equals(Intent.ACTION_MAIN)) {
Log.e(TAG, "onSharedIntent: nothing shared" );
}
}
Add this in Manifest,
<activity
android:name="your-package-name.YourActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
In order to do this, you need to know the Intent that the application is creating and create an IntentFilter that will add your application to the specific list.
Receiving an Implicit Intent on Intents and Filters (Android Developers)
The application probably uses a specific action name that you could hook to.
<intent-filter . . . >
<action android:name="com.example.project.SHOW_CURRENT" />
<action android:name="com.example.project.SHOW_RECENT" />
<action android:name="com.example.project.SHOW_PENDING" />
. . .
</intent-filter>
Or it could be looking for applications accepting a certain type of file.
<intent-filter . . . >
<data android:mimeType="video/mpeg" android:scheme="http" . . . />
<data android:mimeType="audio/mpeg" android:scheme="http" . . . />
. . .
</intent-filter>
The name of the application and what it is sharing would help me give a more specific response.
- Add below code into your Project AndroidManifest.xml file in Specific Activity.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
- Add the following line of code into your project specific Activity.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if ("android.intent.action.SEND".equals(action) && type != null && "text/plain".equals(type)) {
Log.println(Log.ASSERT,"shareablTextExtra",intent.getStringExtra("android.intent.extra.TEXT"));
}
add this to your mainefist file
<activity android:name=".ShareActivity">
<intent-filter
android:label="Share with my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
this link may help you
this worked well for me for getting all web pages, for my app that scans for mp3 files on a web page, and sets alarms from them. It opens up my new url activity, when you share a web page:
Here is what this code results in:
<activity
android:name=".NewUrl"
android:label="#string/title_activity_new_url"
android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity>
Then to receive the link in the app, I got awsome info from this tutorial:
http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878
I want to add something to the above answers. Keep in mind that you should put another intent filter to prevent overriding in case you are using multiple categories in an activity.
For example, the following will prevent your application to be shown on the application list in your device because it doesn't detect it as launcher activity.
Don't do this
<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" />
<!-- DO NOT DO THIS-->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Instead do following
<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>
<!-- USE SEPERATE INTENT FILTER -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Note: Change mimeType according to your use.
Verdict: If you are using more than one category in intent filter use them separately.
I would check to see if there is any API for this app you want to work with.
If so, you can benefit by knowing
a more specific implicit action for your filter
or perhaps add a category other than DEFAULT
If you can find something like these, it would be unlikely to be seen by other apps.
Also make sure to have you Activity NOT labeled with android:exported="false", otherwise it won't show up in other applications' intent choosers (only your own)
E.g. AndroidManifest.xml
<activity
android:name=".ReceiveImageActivity"
android:exported="true"> <!-- here -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Android - Intent Filter?

I am trying to register my Activity so that it can be used by the Activity chooser/picker allowing a user to choose whether or not to select my application/Activity to complete what they are trying to do.
I want to provide the option for the user to be able to select my application when they want to send an SMS message and when they want to place an outgoing call, to try to achieve this I added the following pieces of code within my Activity tags in my manifest:
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
However the Activity chooser never appears and the native apps are used without providing a choice to the user. Can anyone see where I am going wrong?
EDIT:
I have figured out I need to add
<data android:scheme="sms" />
<data android:scheme="smsto" />
for the SMS message but what do I use for the outgoing call?
EDIT 2:
I have tried the following for the outgoing call:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
But again with no luck, has this been blocked from 1.6 on?
Edit 3:
This is what happens when I click Text Mobile:
So i want the same thing when I click Call mobile
I think it should help you
<intent-filter >
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
Tested on Android 2.1
This is because activities and services can not pickup outside intents on their own. You need to use a BroadcastReceiver. To implement this, do the following:
Extend Android's BroadcastReceiver class like so:
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Context context = getApplicationContext();
Intent sendIntent = new Intent();
if ( intent.getAction().equals(Intent.NEW_OUTGOING_CALL) ) {
sendIntent.setClass(context, MyActivity.class);
context.startActivity(sendIntent);
}
else if ( intent.getAction().equals(Intent.SOME_OTHER_INTENT) {
sendIntent.setClass(context, MyService.class);
context.startService(sendIntent);
}
// More else ifs for more intents you want to catch.
}
}
Then you need to declare the receiver in your manifest like this:
<receiver android:name="MyReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
// more intents you want to catch here
</intent-filter>
</receiver>
Only intents declared in the manifest will be caught by your Receiver, so if you want to catch several intents thrown by the system or other programs and want to do the exact same thing when their intents are caught then specify those intents here in the manifest and skip the if/else blocks in the onReceive method.
this worked for me
<activity
android:label="#string/app_name"
android:name=".TestIntentActivity" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
</activity>
You need to add a priority to the intent filter so that Android takes it into account. For example:
<activity android:name="YourActivity">
<intent-filter android:priority="100">
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Categories

Resources