Android: market reaction

I am trying to create an application that opens the Android market page of the selected application and allows the user to download it. I used the intention below to open the 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 the market returns me some answer that the user uploaded or simply canceled.

EDIT: @CommonsWare I'm trying to access the added package here. But I can’t understand what should be the key to get the package from the additional ACTION_PACKAGE_ADDED actions

 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 } } 
+4
source share
2 answers

Android Market is not configured to support startActivityForResult() . Also keep in mind that the download and installation occur asynchronously (i.e., the user clicks Install, and the download occurs in the background and they complete the installation using Notification ).

+6
source

@CommonsWare Superb!

Your solution turned out to be useful, and it also landed me on another very useful page http://devdaily.com/java/jwarehouse/android/core/java/com/android/internal/content/PackageMonitor.java.shtml

The following is a snippet of code from the source link to get the package name of the currently installed application from the broadcast:

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

Thanks Commonsware.

+3
source

All Articles