Reputation: 1
I am trying to simply launch a third part app when when the ok button is selected. I have the following code but it's not coming together. I'm a novice at this and can't quite figure it out.
public class Abc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_ANDRIOS = "market://search?q=pname:com.3rdparty.app";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getpft);
setTitle("Install 3rd party app?");
((Button) findViewById(R.id.Ok)).setOnClickListener(new Openabc());
((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}
public class Openabc implements OnClickListener {
public void onClick(View v) {
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.LAUNCHER");
i.setPackage("com.3rdparty.app");
startActivity(i);
}}
public class FindZxingOnclickListener implements OnClickListener {
public void onClick(View v) {
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_ANDRIOS));
startActivity(marketLaunch);
}}
}
Upvotes: 0
Views: 277
Reputation: 3757
In short, you're not building the intent correctly.
Here is an example of launching another activity via an intent. The thing to pay special attention to is the way that they build the intent.
I can't really help without knowing the specifics of the intent you're trying to hit, but here is the meat of the link:
Intent intent = new Intent("com.3rdpartydev.abcapp.GO");
intent.setPackage("com.3rdpartydev.abcapp");
startActivity(intent);
that'll tell Android to look for something that knows how to handle com.3rdpartydev.abcapp.GO requests, and if it can find it, launch it.
I'd suggest re-reading this for more information
Upvotes: 2
Reputation: 1513
I haven't done Android for a while, but looking through the documentation quickly, I'm thinking this is the problem:
Your class isn't actually going to do anything, because it doesn't make use (via inheritance or composition) of any Android classes. Once you create the Intent
, you're calling an empty method, so nothing is going to happen. The easiest way to make this work is to delete the definition for private void startActivity(Intent i)
, and move the other stuff to your Activity
class. Have that class implement OnClickListener
if you need it, and then call the built in startActivity
method.
Upvotes: 1