Android Starting browser from dialog - android

I've a mapview that displays an itemized overlay, and each onTap event shows a dialog with information about travel agency and three buttons, one of them is supposed to open the agency web site in the browser, but when i click the button i got : no activity found to handle Intent.
here's my code :
protected boolean onTap(int i){
float[] results = new float[1];
Location.distanceBetween(decdegrees(appState.getMyLocation().getLatitudeE6()), decdegrees(appState.getMyLocation().getLongitudeE6()), decdegrees(points.get(i).getPoint().getLatitudeE6()), decdegrees(points.get(i).getPoint().getLongitudeE6()), results);
float distance = results[0]/1000;
DecimalFormat maxDigitsFormatter = new DecimalFormat("#.#");
String infos=points.get(i).getSnippet() + "#" + String.valueOf(maxDigitsFormatter.format(distance));
final String [] AInfos = infos.split("#");
final Dialog ADialog = new Dialog(c);
ADialog.setContentView(R.layout.travelagency);
TextView txtAgence = (TextView)ADialog.findViewById(R.id.txtAgence);
TextView txtAddress = (TextView)ADialog.findViewById(R.id.txtAddress);
TextView txtDistance = (TextView)ADialog.findViewById(R.id.txtDistance);
TextView txtFax = (TextView)ADialog.findViewById(R.id.txtFax);
Button btnCall = (Button)ADialog.findViewById(R.id.btnCall);
Button btnWebSite = (Button)ADialog.findViewById(R.id.btnWebSite);
Button btnCancel = (Button)ADialog.findViewById(R.id.btnCancel);
ADialog.setTitle(AInfos[0]);
btnCall.setText("Appeler : " + AInfos[2]);
txtAgence.setText(AInfos[1]);
txtDistance.setText("Approximativement à : " +AInfos[6] + " Km");
txtAddress.setText("Adresse : " + AInfos[3]);
txtFax.setText("Fax : " + AInfos[4]);
ADialog.show();
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ADialog.dismiss();
}
});
btnWebSite.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(AInfos[5]));
v.getContext().startActivity(myIntent);
}
});
return (true);
}
I found examples here and here but suddently not work for me..
thanks

This will create the proper intent to open a web page in the default browser:
Uri url = Uri.parse("http://www.someUrl.com");
Intent intent = new Intent(Intent.ACTION_VIEW, url);
startActivity(intent);

Most probably your AInfos[5] is not a proper url. Hard-code a url like http://www.google.com and see if it works first. Also print what AInfos[5] contains.

Related

SQL Database in android not updating

I take input in an edittext, that is in a popup window. On dismiss of that popup, the string in edittext should be updated in db at required postion.
Popup Window code:
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popl,(ViewGroup)findViewById(R.id.pop));
final PopupWindow pw = new PopupWindow(layout, 700 * (metrics.widthPixels/1080) , 300 * (metrics.heightPixels/1080) , true);
int coord[]= new int[2];
v.getLocationOnScreen(coord);
pw.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getApplicationContext(), android.R.color.transparent)));
pw.setOutsideTouchable(true);
pw.showAtLocation(v, Gravity.NO_GRAVITY, coord[0] + 50 ,coord[1]+100);
Button del = (Button) layout.findViewById(R.id.del);
Button viewImage = (Button) layout.findViewById(R.id.view);
final EditText notes = (EditText) layout.findViewById(R.id.note);
notes.setText(data[6]);
notedata = data[6];
del.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SQLiteDatabase db = dBcontract.getWritableDatabase();
if ((thisimageuri!=null)&&(thisimageuri.toString().charAt(0)!='a'))
deleteimage(thisimageuri);
Log.d("delete operaiton",String.valueOf(db.delete(eventDBcontract.ListofItem.tableName,eventDBcontract.ListofItem.columnID+" = "+data[4],null)));
recreate(); //add option to delete files as well
}
});
viewImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (thisimageuri!=null)
{
Intent intent = new Intent(getApplicationContext(),showPic.class);
intent.putExtra("photo uri",thisimageuri);
notedata = notes.getText().toString();
pw.dismiss();
startActivity(intent);
}
}
});
pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
notedata = notes.getText().toString();
Log.d("popop window", "onDismiss: " + notedata);
interact.savenote(data[4],notedata);
}
});
} catch (Exception e) {
e.printStackTrace();
}
Method to save in database:
public void savenote(String id , String note)
{
ContentValues values = new ContentValues();
SQLiteDatabase db = dBcontract.getWritableDatabase();
values.put(eventDBcontract.ListofItem.columnnotes,note);
db.update(eventDBcontract.ListofItem.tableName,values,"id=?",new String[]{id});
Log.d("Interact","add note complete " + note);
}
The code works correctly,i.e note is saved correctly in db, when i click on view image but not when I click outside of popup to dismiss it.
Log:
04-14 00:12:24.569 9517-9517/lcukerd.com.stufflist D/popop window: onDismiss: Yu
04-14 00:12:24.569 9517-9517/lcukerd.com.stufflist D/Interact: add note complete Yu
Help me spot the issue. This is eating my brain.
EDIT 1:
data[4] is the id of entry in db to be updated.
data[6] is the old value of "note" as saved in db.

Linking 2 EditText to global variable and button to make a phone call

I'm trying to make an app that makes a call based off two editText calls.
The instances are editText1 and editText2. Once filled out, they click add pin to phone. I am able to get it to go to the phone call but only:
*215*null*null
shows up.
So, my question is what am I doing wrong if I want to store whats typed in edit Text1 to be stored in firstNumber and editText2 to be stored in secondNumber?
Furthermore, how do I get the # character to display?
So, the result of what I want is:
*215*firstNumber*secondNumber#
to be displayed on phone call.
public class Main2Activity extends AppCompatActivity {
EditText firstNumber;
EditText secondNumber;
Button btnAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
firstNumber = (EditText)findViewById(R.id.editText2);
secondNumber = (EditText)findViewById(R.id.editText3);
btnAdd = (Button)findViewById(R.id.button5);
Toast.makeText(Main2Activity.this,
"before the call", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:*215*" + firstNumber + "*" + secondNumber + "#" ));
startActivity(intent);
} catch (Exception e) {
}
}
});
}
}
Now that We have it complete using this method `
public void onClick(View v {
try{
EditText et = (EditText) findViewById(R.id.editText2);
EditText et2 = (EditText) findViewById(R.id.editText5);
String text= et.getEditableText().toString();
String text2 =et2.getEditableText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:*215*" + text + "*" + text2 + "#"));
startActivity(intent);
} catch (Exception e) {
}
}
`What i want done is add the Pawn sign or the hash tag at the end of output. For example
*215*text*text2 followed by the hashtag or pawn sign #
but it totally just tosses it out the window after text2.
so at the moment what i get is *215*text*text2 what i want is *215*text*text2#
Thank you so much. I took a different route and it worked this way. everything else was the same from the question.
thanks again
public void onClick(View v) {
try {
EditText et = (EditText) findViewById(R.id.editText2);
EditText et2 = (EditText) findViewById(R.id.editText5);
String text= et.getEditableText().toString();
String text2 =et2.getEditableText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:*215*" + text + "*" + text2 + "#"));
startActivity(intent);
} catch (Exception e) {
}
}
To get the actual text in EditText, you need to use:
firstNumber.getText().toString();
secondNumber.getText().toString();
EDIT: Use the Uri.encode() method to show the # symbol as well
String phoneNumber = firstNumber.getText().toString() + secondNumber.getText().toString() + "#";
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:"+ Uri.encode(phoneNumber)));
startActivity(callIntent);

Passing data between activities - Android SDK

I have read the previously posted questions and answers for 2 days and I've tried every variation suggested as well as setting my launchMode attribute to "standard" in my manifest.
I'm trying to pass data from my second activity back to my first activity after pressing a button. After I press the button, the first activity is launched but it doesn't go back to my onActivityResult() method. I can't figure out why this is happening.
Here's my code from activity 2:
Button btnAdd = (Button) findViewById(R.id.btnAdd);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Check that message is printed out to LogCat
System.out.println("hello test1 Activity2");
EditText band = (EditText) findViewById(R.id.txtBand);
band.setFilters(new InputFilter[] {
new InputFilter.LengthFilter(9)
});
EditText album = (EditText) findViewById(R.id.txtAlbum);
album.setFilters(new InputFilter[] {
new InputFilter.LengthFilter(9)
});
final Spinner genre = (Spinner) findViewById(R.id.spin_genre);
TextView selection = (TextView)genre.getSelectedView();
CharSequence strBand = band.getText();
CharSequence strAlbum = album.getText();
CharSequence strGenre = selection.getText();
//Check that we got input values
System.out.println("hello test Activity2- " +
strBand + " - " + strAlbum + " - " + strGenre);
//**********Intent Declaration************
Intent i = new Intent(getApplicationContext(), Activity1.class);
i.putExtra("strBand", strBand);
i.putExtra("strAlbum", strAlbum);
i.putExtra("strGenre", strGenre);
startActivityForResult(i, 0);
setResult(RESULT_OK, i);
finish();
}
});
Here's activity 1:
public class Activity1 extends Activity {
/** Called when the activity is first created. */
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button addAlbum = (Button) findViewById(R.id.btnMain);
addAlbum.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent();
i.setClassName("jorge.jorge.jorge",
"jorge.jorge.jorge.Activity2");
startActivity(i);
}
});
}// end of onCreate()
//******************Callback Method****************************
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
//Checks if we got to ActivityResult
System.out.println("hello test 2: We got to Activity1");
if (resultCode == RESULT_OK)
{
Bundle returndata = data.getExtras();
String strAlbum = returndata.getString("strAlbum");
String strBand = returndata.getString("strBand");
String strGenre = returndata.getString("strGenre");
// check to see if we got the variable values from activity2
System.out.println("hello test 2: We got to Activity1 with variables - "
+ strBand + " - " + strAlbum + " - " + strGenre);
//Create table layout to contains views with variable values
TableLayout table = new TableLayout(this);
table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
//creates row with parameters
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
//text views to contain variable values
TextView tv1 = new TextView(this);
tv1.setText(strBand);
row.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setText(strAlbum);
row.addView(tv2);
TextView tv3 = new TextView(this);
tv3.setText(strGenre);
row.addView(tv3);
//adds the table row to the table layout
table.addView(row);
}
}// end onActivityResult()
}
I'm not sure if my activity callbacks are not placed properly in the code or if I'm not firing the intent properly or if I'm not setting up the callback with the right method or what. I know this topics has been discussed but I'm out of ideas. Thanks.
You've just got it backwards. If Activity1 is supposed to startActivity2 and Activity2 is supposed to send the result back to Activity1, you need to do it like this:
in Activity1:
Intent i = new Intent();
i.setClassName("jorge.jorge.jorge", "jorge.jorge.jorge.Activity2");
startActivityForResult(i); // This starts Activity2 and waits for the result
in Activity2:
Intent i = new Intent(getApplicationContext(), Activity1.class);
i.putExtra("strBand", strBand);
i.putExtra("strAlbum", strAlbum);
i.putExtra("strGenre", strGenre);
setResult(RESULT_OK, i);
finish(); // This closes Activity2 and generates the callback to Activity.onActivityResult()

How to Create a Global Level Function with UI capability

I have a function to find an employee's id number from my sqlite database. The function allows the user to look up by id or name (first and/or last); therefore it creates several dialog boxes and finds the data through an If Else Then tree. Here's the code for those who like that sort of thing:
public String getEmployeeID() {
final CharSequence[] items = {"By ID", "By Name", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(LibraryScreen.this);
builder.setTitle("Find Employee");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(items[item].equals("Cancel")) {
dialog.cancel();
empid = "";
} else if(items[item].equals("By ID")) {
dialog.cancel();
final Dialog dialog2 = new Dialog(LibraryScreen.this);
dialog2.setContentView(R.layout.peopledialog);
dialog2.setTitle("Employee ID");
dialog2.setCancelable(true);
//Set Visibility of the Rows
TableRow tblrow1 = (TableRow) dialog2.findViewById(R.id.trGeneral);
tblrow1.setVisibility(0);
//Set Captions for Rows
TextView txtvw1 = (TextView) dialog2.findViewById(R.id.tvGeneral);
txtvw1.setText("Employee ID");
//Set Up Edit Text Boxes
EditText edttxt1 = (EditText) dialog2.findViewById(R.id.txtGeneral);
//Set Input Type
edttxt1.setRawInputType(0x00000002);//numbers
edttxt1.setText("");
//set max lines
edttxt1.setMaxLines(1);
//Set MaxLength
int maxLength;
maxLength = 15;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
edttxt1.setFilters(FilterArray);
Button button = (Button) dialog2.findViewById(R.id.btnTxtDiaSav);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EditText emplid = (EditText) dialog2.findViewById(R.id.txtGeneral);
String newemp = "";
db.open();
Cursor c = db.getEmployee(emplid.getText().toString());
if(c.moveToFirst()) {
empid = c.getString(c.getColumnIndex("employeeid"));
} else {
Toast.makeText(LibraryScreen.this, "No ID Match", Toast.LENGTH_LONG).show();
empid = "";
}
c.close();
db.close();
dialog2.dismiss();
}
});
Button buttonCan = (Button) dialog2.findViewById(R.id.btnTxtDiaCan);
buttonCan.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog2.dismiss();
empid = "";
}
});
dialog2.show();
} else if(items[item].equals("By Name")) {
dialog.cancel();
final Dialog dialog1 = new Dialog(LibraryScreen.this);
dialog1.setContentView(R.layout.peopledialog);
dialog1.setTitle("Employee's Name");
dialog1.setCancelable(true);
//Set Visibility of the Rows
TableRow tblrow1 = (TableRow) dialog1.findViewById(R.id.trGeneral);
tblrow1.setVisibility(0);
//Set Captions for Rows
TextView txtvw1 = (TextView) dialog1.findViewById(R.id.tvGeneral);
txtvw1.setText("Employee Name");
//Set Up Edit Text Boxes
EditText edttxt1 = (EditText) dialog1.findViewById(R.id.txtGeneral);
//Set Input Type
edttxt1.setRawInputType(0x00002001);//cap words
edttxt1.setText("");
//set max lines
edttxt1.setMaxLines(1);
//Set MaxLength
int maxLength;
maxLength = 50;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
edttxt1.setFilters(FilterArray);
Button button = (Button) dialog1.findViewById(R.id.btnTxtDiaSav);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EditText emplid = (EditText) dialog1.findViewById(R.id.txtGeneral);
String firstname = emplid.getText().toString();
String lastname = "";
String matchlist = "";
String temptext = "";
int matchcount = 0;
if(firstname.lastIndexOf(" ") <= 0) {
lastname = firstname;
firstname = "X";
} else {
lastname = firstname.substring(firstname.lastIndexOf(" ") + 1);
firstname = firstname.substring(0, firstname.lastIndexOf(" "));
}
db.open();
Cursor c1, c2;
String titletext = "";
if(firstname.length() > 0) {
c1 = db.getEmployeeByName(lastname, firstname);
if(c1.getCount() == 0) {
c1 = db.getRowByFieldTextOrdered("employees", "lastname", lastname, "lastname, firstname");
if(c1.getCount() == 0) {
Toast.makeText(LibraryScreen.this, "No matching Employees.", Toast.LENGTH_LONG).show();
empid = "";
}
}
if(c1.getCount() > 0) {
do {
c2 = db.getRowByField("orgcodes", "manager", c1.getString(c1.getColumnIndex("employeeid")));
if(c2.moveToFirst()) {
if(c2.getString(c2.getColumnIndex("orgcode")).substring(9, 10).equals("0")) {
if(c2.getString(c2.getColumnIndex("orgcode")).substring(7, 8).equals("0")) {
if(c2.getString(c2.getColumnIndex("orgcode")).substring(5, 6).equals("0")) {
if(c2.getString(c2.getColumnIndex("orgcode")).substring(4, 5).equals("0")) {
if(c2.getString(c2.getColumnIndex("orgcode")).substring(3, 4).equals("0")) {
titletext = "Top Brass";
} else {
titletext = "Senior VP";
}
} else {
titletext = "VP";
}
} else {
titletext = "Director";
}
} else {
titletext = "Senior Manager";
}
} else {
titletext = "Manager";
}
} else {
titletext = "Employee";
}
matchcount++;
matchlist = matchlist + c1.getString(c1.getColumnIndex("employeeid")) + ": " + c1.getString(c1.getColumnIndex("firstname")) + " " + c1.getString(c1.getColumnIndex("lastname")) + ": " + titletext + "|";
} while(c1.moveToNext());
}
} else {
empid = "";
}
if(matchcount == 0) {
db.close();
Toast.makeText(LibraryScreen.this, "No matching Employees.", Toast.LENGTH_LONG).show();
empid = "";
} else {
final CharSequence[] items = new CharSequence[matchcount + 1];
items[0] = "(Cancel)";
for(int i = 1; i <= matchcount; i++) {
items[i] = matchlist.substring(0, matchlist.indexOf("|"));
matchlist = matchlist.substring(matchlist.indexOf("|") + 1);
}
db.close();
AlertDialog.Builder builder1 = new AlertDialog.Builder(LibraryScreen.this);
builder1.setTitle("Select Employee");
builder1.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(items[item].equals("(Cancel)")) {
dialog.cancel();
empid = "";
} else {
String wasted = items[item].toString();
empid = wasted.substring(0, wasted.indexOf(":"));
dialog.cancel();
}
}
});
AlertDialog alert1 = builder1.create();
alert1.show();
}
dialog1.dismiss();
}
});
Button buttonCan = (Button) dialog1.findViewById(R.id.btnTxtDiaCan);
buttonCan.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog1.dismiss();
empid = "";
}
});
dialog1.show();
}
}
});
AlertDialog alert = builder.create();
alert.show();
return empid;
}
I use the employee id for a variety of functions through multiple activities in my program. Up to now, I've simply pasted the code under each listener that needs the id, but that is such a waste of space IMHO.
My question:
Is there a way to put this function somewhere that can be called from many different activities?
If so:
How do I do that?
How do I set the context for the dialog boxes for multiple activities?
How do I get the employee id back to the function that needs it?
I'm sure this has been asked before, but I haven't been able to find it online: actually, I'm not even sure how to word the query right. My attempts have come up woefully short.
A little late to the party - but recorded for posterity:
Read up on the Application class:
Base class for those who need to maintain global application state.
You can provide your own implementation by specifying its name in your
AndroidManifest.xml's tag, which will cause that class
to be instantiated for you when the process for your
application/package is created.
Basically, this would give you the ability to obtain a single object that represents your running application (think of it as a singleton that returns an instance of your running app).
You first start off by creating a class that extends Application base class and defining any common code that is used throughout your application
import android.app.Application;
public class MyApplication extends Application {
public void myGlobalBusinessLogic() {
//
}
}
Then tell your application to use the MyApplication class instead of the default Application class via the <application> node in your app manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:name="MyApplication">
Finally, when you need to get to your common function just do something like:
MyApplication application = (MyApplication) getApplication();
application.myGlobalBusinessLogic();
If you need to get the context from any part of your application, you can simple return it by calling getApplicationContext() (defined in the base Application class) via a getter method within your custom application class.

Use application to rate it on market [duplicate]

This question already has answers here:
"Rate This App"-link in Google Play store app on the phone
(21 answers)
Closed 2 years ago.
I am currently developing an application in Android Where I want to give some functionality to user to rate the current application.
Their will be a button on it's click it will ask ask whether user want to rate the application or not? If yes will will go to market application on device to rate application
(Market should show this application.) or it will open browser which will load market & showing this application.
Any one used this kind of functionality before. Please provide some help.
Thank You.
I always use a method like this one:
private void launchMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.couldnt_launch_market, Toast.LENGTH_LONG).show();
}
}
public class AppRater {
private final static String APP_TITLE = "App Name";// App Name
private final static String APP_PNAME = "com.example.name";// Package Name
private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches
public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) { return ; }
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(mContext, editor);
}
}
editor.commit();
}
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
final Dialog dialog = new Dialog(mContext);
dialog.setTitle("Rate " + APP_TITLE);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText("Rate " + APP_TITLE);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText("Remind me later");
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
}}
Now Integrate class to your activity like this ->
AppRater.app_launched(this);
Here is simple solution for :
final String appPackageName = "com.name.app";
private void launchMyMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, " unable to find source market app! try again", Toast.LENGTH_LONG).show();
}
}
The answers here won't take you directly to playstore if you have multiple market apps on your phone. Instead it will show a picker dialog.
To open playstore directly, use this:
private fun rateUs() {
val uri = Uri.parse("https://play.google.com/store/apps/details?id=" + activity?.packageName.toString() + "")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}

Categories

Resources