2

I am beginner in android. I want to open installed application through my application with the help of google translator. Like user speak "whatsapp" then my app convert it into text. and by text i will open installed application. I have done speech to text coding and installed applications list coding.

Google Speech to text I have stored the value of google translator text into String s1

List ApplicationInfo

 btnopen = (Button) findViewById(R.id.btnopen);
 btnopen.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        String s1=txtText.getText().toString();
                        String s2=applist.get(position).toString();

                          if(s1 == s2){
                              packageManager = context.getPackageManager();
                              ApplicationInfo app = applist.get(position);

                                try {
                                    Intent intent = packageManager
                                    .getLaunchIntentForPackage(app.packageName);

                                    if (null != intent) {
                                        startActivity(intent);
                                    }
                                } catch (ActivityNotFoundException e) {
                                    Toast.makeText(AllAppsActivity.this, e.getMessage(),
                                            Toast.LENGTH_LONG).show();
                                } catch (Exception e) {
                                    Toast.makeText(AllAppsActivity.this, e.getMessage(),
                                            Toast.LENGTH_LONG).show();
                                }
                                }

                            else{
                                    Toast.makeText(getApplicationContext(), txtText.getText().toString()+" is not match", Toast.LENGTH_LONG).show();
                                }       
                    }
                    private PackageManager getPackageManager() {
                        // TODO Auto-generated method stub
                        return null;
                    }
                });

ApplicationAdapter

public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
    private List<ApplicationInfo> appsList = null;
    private Context context;
    private PackageManager packageManager;
        public ApplicationAdapter(Context context, int textViewResourceId,
            List<ApplicationInfo> appsList) {
        super(context, textViewResourceId, appsList);
        this.context = context;
        this.appsList = appsList;
        packageManager = context.getPackageManager();
    }

    @Override
    public int getCount() {
        return ((null != appsList) ? appsList.size() : 0);
    }

    @Override
    public ApplicationInfo getItem(int position) {
        return ((null != appsList) ? appsList.get(position) : null);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (null == view) {
            LayoutInflater layoutInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.snippet_list_row, null);
        }

        ApplicationInfo data = appsList.get(position);
        if (null != data) {
            TextView appName = (TextView) view.findViewById(R.id.app_name);
            TextView packageName = (TextView) view.findViewById(R.id.app_paackage);
            ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);

            appName.setText(data.loadLabel(packageManager));
            packageName.setText(data.packageName);
            iconview.setImageDrawable(data.loadIcon(packageManager));
        }
        return view;
    }
};

ApplicationAdapter and list Applicationinfo give me a list of installed applications.

How can I compare s1 in ListView?

1 Answers1

0
if(s1 == s2)

You are comparingen the references of the string, not the actual value. The code below will compare the actual texts.

if(s1.equals(s2))

I don't know if this is your actual problem, have a hard time deciphering it from the way your question is formulated.

Kezufru
  • 123
  • 10