Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: response from market activity

I am trying to make an app that opens android market page of selected app & lets user download it.I have used below intent to open market.

  Intent intent = new Intent (Intent.ACTION_VIEW);
    intent.setData (Uri.parse ("market://details?id=" + PackageName ));
    intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivityForResult (intent, 13);

but I always get resultcode 0 in onActivityResult.StackTrace says:

I/ActivityManager(   79): Starting activity: Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.apps.unveil flg=0x10000000 cmp=com.an
droid.vending/.AssetInfoActivity }
W/ActivityManager(   79): Activity is launching as a new task, so cancelling activity result.

What I want is that market returns me some response that user downloaded the app or just cancelled.

EDIT: @CommonsWare I am trying to access added package here But cant figure what should be key to get packagename from extras of ACTION_PACKAGE_ADDED

public class ServiceReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    //Do this when the system sends the intent
    Bundle b = intent.getExtras();
    String packagename = b.get(?);   //cant figure what should be key to get packagename //from extras
    }

}
like image 327
100rabh Avatar asked Oct 01 '10 11:10

100rabh


2 Answers

The Android Market is not set up to support startActivityForResult(). Also, bear in mind that the download and installation happen asynchronously (i.e., user clicks Install, and the download occurs in the background, and they finish the install via the Notification).

like image 100
CommonsWare Avatar answered Oct 22 '22 17:10

CommonsWare


@CommonsWare Superb!

Your solution proved helpful & it also landed me to another very useful page http://devdaily.com/java/jwarehouse/android/core/java/com/android/internal/content/PackageMonitor.java.shtml

Below is a code snippet from above link source to get package name of currently installed app from broadcast intent:

 String getPackageName(Intent intent) {
        Uri uri = intent.getData();
        String pkg = uri != null ? uri.getSchemeSpecificPart() : null;
        return pkg;
    }

Thanks Commonsware.

like image 29
100rabh Avatar answered Oct 22 '22 17:10

100rabh