Wednesday, November 27, 2013

[android-developers] How to call from Android Native Dialers, ignore other dialers

       

Target: Call from native dialer only , bypass all dialers.

This is my method to call from Native Dialer , this method bypass the chooser dialog as I experienced.

Intent i = CallUtils.callfromDefaultDialer(ctxt,dat[1]);
ctxt.startActivity(i);


public static Intent callfromDefaultDialer(Context ctxt, String no) {
       
        Intent i = new Intent();
        i.setAction(Intent.ACTION_CALL);
        i.setData(Uri.parse("tel:" + no));
        PackageManager pm = ctxt.getPackageManager();
        List<ResolveInfo> list = pm.queryIntentActivities(i, 0);
        for (ResolveInfo info : list) {
            String pkgnam = info.activityInfo.packageName;
            if (pkgnam.toLowerCase().equals("com.android.phone")) {
                i.setClassName(pkgnam, info.activityInfo.name);
                return i;
            }
        }
       
       return i;
    }


But some time it gives me option to choose . It gives me two dialog two choose, you can see the images in attachment.But second dialog (chooser_win.png) I bypass using above code. but when when i get the first dialog(call_win.png) then the second dialog(chooser_win.png) auto come up(you can say its root of chooser dialog).


But using below code I bypass the first dialog (call_win.png). But not second dialog(chooser_win.png)

public static Intent callfromDefaultDialer(Context ctxt, String no) {
       
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
       
        Intent i = new Intent();
        i.setAction(Intent.ACTION_CALL);
        //i.addCategory(Intent.ACTION_DEFAULT);
        i.setData(Uri.parse("tel:" + no));
        PackageManager pm = ctxt.getPackageManager();
        List<ResolveInfo> list = pm.queryIntentActivities(i, 0);
        for (ResolveInfo info : list) {
            String pkgnam = info.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(Intent.ACTION_CALL);
            if (pkgnam.toLowerCase().equals("com.android.phone")) {
                targetedShareIntent.setData(Uri.parse("tel:" + no));
                targetedShareIntent.setClassName(pkgnam, info.activityInfo.name);
                targetedShareIntents.add(targetedShareIntent);
                //return targetedShareIntent;
                //i.setClassName(pkgnam, info.activityInfo.name);
                //return i;
            }
        }
       
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to Call");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
        
        return chooserIntent;
    }

I tried this code to get Intent.EXTRA_INITIAL_INTENTS . but not got success. its giving always blank parcelable list.

Intent intent = CallUtils.callfromDefaultDialer(ctxt,dat[1]);
Parcelable[] pa = intent.getParcelableArrayExtra(.);
        Intent[] initialIntents = null;
        if (pa != null) {
            initialIntents = new Intent[pa.length];
            for (int i=0; i<pa.lengthi++) {
                if (!(pa[iinstanceof Intent)) {
                    Log.w("ChooseActivity""Initial intent #" + i
                            + " not an Intent: " + pa[i]);
                }
                initialIntents[i] = (Intent)pa[i];
            }
        }

Reference of this Link: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.4_r1/com/android/internal/app/ChooserActivity.java



--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate