Need Python Code Converted to PHP

Discussion in 'PHP' started by rodneystover, Jan 14, 2011.

  1. #1
    I am fairly new to PHP and not sure how to convert this code to PHP. Any help would greatly be appreciated.


    try{
    // Launch ScanLife
    Intent intent = new Intent();
    intent.setClassName("com.ScanLife", "com.ScanLife.ScanLife");
    Uri uri = Uri.parse("scanlife://sdk/scan");
    intent.setData(uri);
    startActivity(intent);
    }catch(ActivityNotFoundException ex){
    // Launch the Download of ScanLife
    new AlertDialog.Builder(this)
    .setTitle("Install ScanLife?")
    .setMessage("The application requires ScanLife Barcode Scanner. Would you like to install it?")
    .setPositiveButton("Yes", new DialogInterface.OnClickListener(){
    public void onClick(DialogInterface dg, int v){
    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.ScanLife"));
    startActivity(intent);
    }
    })
    .setNegativeButton("No", new DialogInterface.OnClickListener(){
    public void onClick(DialogInterface dg, int v){
    }
    })
    .show();
    }catch(Exception ex){
    }

    Just in case anyone is wondering what this code is for I am writing a web accessible page for a grocery store that can scan a UPC with their android or iphone and it pull info from a mysql database. The above code launches the Scanlife free scanning app and I need it in PHP for the web page to launch the app instead of writing a phone specific app. Thanks again.
     
    rodneystover, Jan 14, 2011 IP
  2. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #2
    You know that php doesn't have to ability to set ask for user input while it is running? I.e. All the user input must be set before running the script.
     
    ssmm987, Jan 14, 2011 IP
  3. rodneystover

    rodneystover Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Basically I am looking for the part of the code toward the end where I can capture the results of the
    intent.setData(uri);
    startActivity(intent);

    and what ends up in the .show();
     
    rodneystover, Jan 14, 2011 IP
  4. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #4
    This is about the only thing translateable to php:

    
    try
    {
    	$intent = new Intent;
    	$intent->setClassName("com.ScanLife", "com.ScanLife.ScanLife"); 
    	$uri="scanlife://sdk/scan";
    	$intent->setData($uri);
    } catch(ActivityNotFoundException $e)
    {
    	//Unable to translate
    }
    
    PHP:
    Although I must admit I don't really know Python that well.
     
    ssmm987, Jan 14, 2011 IP
  5. rodneystover

    rodneystover Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Let me play around with that code today. You're help should push me in the right direction. Thank you.
     
    rodneystover, Jan 14, 2011 IP