Add new contact on Android no activity to handle intent error - android

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"/>

Related

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

Implicit intent from test application

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

Launching an Activity with an Intent

I have the following in my AndroidManifest:
<activity android:name="IntentChild"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.intent.cursor.item/intent_example"
android:host="example.intent"
android:path="intent_example"
android:scheme="content"
/>
</intent-filter>
</activity>
I launch the activity with
Uri uri = new Uri.Builder().scheme("content").authority("example.intent").appendPath("intent_example").build();
Intent intent = new Intent(Intent.ACTION_EDIT, uri);
IntentExample.this.startActivity(intent);
But I get:
E/AndroidRuntime( 865): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content://
example.intent/intent_example }
What am I doing wrong? Also, does Uri.Builder.authority() refer to the same thing as the android:host attribute of the <data> tag in my manifest?
Prompted by the comment by #A--C, I ended up adding a call to Intent.setType() to set the desired MIME type:
Uri uri = new Uri.Builder().scheme("content").authority("example.intent").appendPath("intent_example").build();
Intent intent = new Intent(Intent.ACTION_EDIT, uri);
intent.setType("vnd.intent.cursor.item/intent_example");
IntentExample.this.startActivity(intent);
For simplicity, I also pruned my <intent-filter> to only declare the android:mimeType. I guess, but not entirely certain, that this isn't as important as the previous change.
<activity android:name="IntentChild"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.intent.cursor.item/intent_example"/>
</intent-filter>
</activity>

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>

Activity not found exception when clicking on the image

i am getting following error:
log is:
android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.VIEW
dat=android.resource://com.isummation.customgallery/2130837504 typ=image/* }
my code is as:
intent.setAction(Intent.ACTION_VIEW);
Uri hacked_uri = Uri.parse("android.resource://com.isummation.customgallery/" + R.drawable.a);
intent.setDataAndType(hacked_uri, "image/*");
startActivity(intent);
manifest.xml is as:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
any suggestion?
thanks
Try putting all actions/categories in the same intent filter, as opposed to the two different ones you currently have:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Also make sure you added the intent filter to the correct activity. For an example, check out the Note Pad example.
i can't see setName() in ur code . usually Activity not found means we set a name to intent but no Activity tag in menifest with this name exist . so please check

Categories

Resources