Thursday, November 3, 2011

No applications can perform this action - Check Intent available and force to install

In the article "Send email using Intent.ACTION_SEND", we startActivity with intent of Intent.ACTION_SEND. I assume all Android should have gmail, or Composer, installed. But somebody complain with error of "No applications can perform this action".

We can check if any package installed to handle the intent in advance by calling queryIntentActivities(). If the returned list not ">0" (no aplications installed), open Market to install "market://details?".

Open Market if No applications can perform this action

Such a approach can be applied to other intent.

package com.exercise.AndroidEMail;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidEMail extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

final EditText edittextEmailAddress = (EditText)findViewById(;
final EditText edittextEmailSubject = (EditText)findViewById(;
final EditText edittextEmailText = (EditText)findViewById(;
Button buttonSendEmail_intent = (Button)findViewById(;

//Preset default
edittextEmailText.setText("email body");

buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener(){

public void onClick(View arg0) {
// TODO Auto-generated method stub

String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();

String emailAddressList[] = {emailAddress};

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);

//Check if Intent available
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() >0 ){
startActivity(Intent.createChooser(intent, "Choice App to send email:"));
//Start Market to downoad and install gmail
Uri uri = Uri.parse("market://details?");
Intent it = new Intent(Intent.ACTION_VIEW, uri);


The layout, main.xml, refer to the article "Send email using Intent.ACTION_SEND".

Download the files.

No comments: