I am trying to use a code snipit from here:
http://www.androidsnippets.com/prompt-engaged-users-to-rate-your-app-in-the-android-market-appirater
When the code is put into my app I have this:
package com.example.beerportfoliopro;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AppRater {
private final static String APP_TITLE = "YOUR-APP-NAME";
private final static String APP_PNAME = "YOUR-PACKAGE-NAME";
private final static int DAYS_UNTIL_PROMPT = 3;
private final static int LAUNCHES_UNTIL_PROMPT = 7;
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 View.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 View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new View.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();
}
}
// see http://androidsnippets.com/prompt-engaged-users-to-rate-your-app-in-the-android-market-appirater
I imported all the libraries needed but am getting a few errors at this piece of code:
// 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);
}
}
The error is at > and at the )) on this line:
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000))
the first error says:
Cannot resolve symbol 'gt'
and the second error is:
';'expected unexpected token
Not sure what is wrong since it was taken straight from the snipit.
Replace > with >
> got encoded for display on a webpage as > but didn't get unencoded when you copied the code.
Related
I have ask a question before about change method OnClick to method lifecycle
But I think the problem was solving.
But in this new question is same with before but different.
Now i have ask how add alertdialog to my source code. I have 3 aletdialog will show when the noise until 70 dB , 80 dB and 100 dB.
Here's MY CODE
package com.andronoise;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.text.DecimalFormat;
public class MainActivity extends Activity implements InputListener{
InputSuara micInput;
TextView mdBTextView;
TextView mdBFractionTextView;
LevelBar mBarLevel;
double mGain = 2500.0 / Math.pow(10.0, 90.0 / 20.0);
double mRmsSmoothed;
double mAlpha = 0.9;
public double dB;
private int mSampleRate;
private int mAudioSource;
private volatile boolean mDrawing;
private volatile int mDrawingCollided;
private static final String TAG = "MainActivity";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
micInput = new InputSuara(this);
setContentView(R.layout.activity_main);
mBarLevel = (LevelBar)findViewById(R.id.bar_level_drawable_view);
mdBTextView = (TextView)findViewById(R.id.dBTextView);
mdBFractionTextView = (TextView)findViewById(R.id.dBFractionTextView);
final ToggleButton onOffButton=(ToggleButton)findViewById(
R.id.on_off_toggle_button);
ToggleButton.OnClickListener tbListener =
new ToggleButton.OnClickListener() {
#Override
public void onClick(View v) {
if (onOffButton.isChecked()) {
readPreferences();
micInput.setSampleRate(mSampleRate);
micInput.setAudioSource(mAudioSource);
micInput.start();
} else {
micInput.stop();
}
}
};
onOffButton.setOnClickListener(tbListener);
}
private void readPreferences() {
SharedPreferences preferences = getSharedPreferences("LevelMeter",
MODE_PRIVATE);
mSampleRate = preferences.getInt("SampleRate", 8000);
mAudioSource = preferences.getInt("AudioSource",
MediaRecorder.AudioSource.VOICE_RECOGNITION);
}
public void Alert () {
if (dB >= 70 || dB <80) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 70 dB, kebisingan dalam tingkat rendah")
.setPositiveButton("Close",null).show();
}
else if (dB >=80 || dB <100) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 80 dB, kebisingan dalam tingkat sedang Waspada !")
.setPositiveButton("Close",null).show();
}
else if ( dB >= 100) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 100 dB, berbahaya jika lebih dari 1 menit!!! Segera menghindar")
.setPositiveButton("Close",null).show();
};
}
public void processAudioFrame(short[] audioFrame) {
if (!mDrawing) {
mDrawing = true;
double rms = 0;
for (int i = 0; i < audioFrame.length; i++) {
rms += audioFrame[i]*audioFrame[i];
}
rms = Math.sqrt(rms/audioFrame.length);
mRmsSmoothed = mRmsSmoothed * mAlpha + (1 - mAlpha) * rms;
final double rmsdB = 20.0 * Math.log10(mGain * mRmsSmoothed);
dB = 20 + rmsdB;
mBarLevel.post(new Runnable() {
#Override
public void run() {
mBarLevel.setLevel(( 10 + rmsdB) / 90);
DecimalFormat df = new DecimalFormat("##");
mdBTextView.setText(df.format(dB));
int one_decimal = (int) (Math.round(Math.abs(rmsdB * 10))) % 10;
mdBFractionTextView.setText(Integer.toString(one_decimal));
mDrawing = false;
}
});
} else {
mDrawingCollided++;
Log.v(TAG, "Level bar update collision, i.e. update took longer " +
"than 20ms. Collision count" + Double.toString(mDrawingCollided));
}
}
}
You have an error in yours if conditions
if (dB >= 70 || dB <80){
//do something
}
else if (dB >=80 || dB <100){
//do something
}
e.g db=95 the app will go to the first if
the correct code is:
if (dB >= 70 && dB <80){
//do something
} else if (dB >=80 && dB <100){
//do something
}else{
//do something
}
so
package com.andronoise;
import android.content.DialogInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.text.DecimalFormat;
public class MainActivity extends Activity implements InputListener{
InputSuara micInput;
TextView mdBTextView;
TextView mdBFractionTextView;
LevelBar mBarLevel;
double mGain = 2500.0 / Math.pow(10.0, 90.0 / 20.0);
double mRmsSmoothed;
double mAlpha = 0.9;
public double dB;
private int mSampleRate;
private int mAudioSource;
private volatile boolean mDrawing;
private volatile int mDrawingCollided;
private static final String TAG = "MainActivity";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
micInput = new InputSuara(this);
setContentView(R.layout.activity_main);
mBarLevel = (LevelBar)findViewById(R.id.bar_level_drawable_view);
mdBTextView = (TextView)findViewById(R.id.dBTextView);
mdBFractionTextView = (TextView)findViewById(R.id.dBFractionTextView);
final ToggleButton onOffButton=(ToggleButton)findViewById(
R.id.on_off_toggle_button);
ToggleButton.OnClickListener tbListener =
new ToggleButton.OnClickListener() {
#Override
public void onClick(View v) {
if (onOffButton.isChecked()) {
readPreferences();
micInput.setSampleRate(mSampleRate);
micInput.setAudioSource(mAudioSource);
micInput.start();
} else {
micInput.stop();
}
}
};
onOffButton.setOnClickListener(tbListener);
}
private void readPreferences() {
SharedPreferences preferences = getSharedPreferences("LevelMeter",
MODE_PRIVATE);
mSampleRate = preferences.getInt("SampleRate", 8000);
mAudioSource = preferences.getInt("AudioSource",
MediaRecorder.AudioSource.VOICE_RECOGNITION);
}
public void Alert () {
if (dB >= 70 && dB <80) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 70 dB, kebisingan dalam tingkat rendah")
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
}
else if (dB >=80 && dB <100) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 80 dB, kebisingan dalam tingkat sedang Waspada !")
.setPositiveButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
}
else if ( dB >= 100) {
AlertDialog.Builder build = new
AlertDialog.Builder(MainActivity.this);
build.setTitle("Alert!!!").setIcon(R.drawable.ic_launcher).setMessage("Level 100 dB, berbahaya jika lebih dari 1 menit!!! Segera menghindar")
.setPositiveButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
};
}
public void processAudioFrame(short[] audioFrame) {
if (!mDrawing) {
mDrawing = true;
double rms = 0;
for (int i = 0; i < audioFrame.length; i++) {
rms += audioFrame[i]*audioFrame[i];
}
rms = Math.sqrt(rms/audioFrame.length);
mRmsSmoothed = mRmsSmoothed * mAlpha + (1 - mAlpha) * rms;
final double rmsdB = 20.0 * Math.log10(mGain * mRmsSmoothed);
dB = 20 + rmsdB;
mBarLevel.post(new Runnable() {
#Override
public void run() {
mBarLevel.setLevel(( 10 + rmsdB) / 90);
DecimalFormat df = new DecimalFormat("##");
mdBTextView.setText(df.format(dB));
Alert();
int one_decimal = (int) (Math.round(Math.abs(rmsdB * 10))) % 10;
mdBFractionTextView.setText(Integer.toString(one_decimal));
mDrawing = false;
}
});
} else {
mDrawingCollided++;
Log.v(TAG, "Level bar update collision, i.e. update took longer " +
"than 20ms. Collision count" + Double.toString(mDrawingCollided));
}
}
}
i am trying the code to show users to rate my app
however once the user has rated the app it should not show again
how can that be done
moreover can we track if users have rated our app, is there any google api for this feature , can analytics be helpfull for tracking ratings of an app
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();
}
}
You need to use Shared Preferences Shared Preferences
whenever user rate your app you set the boolean variable to true and makes the check before showing the rate app dialog if the user has already rated it or not if your boolean variable is false you can ask the user to rate the app, otherwise user has already rated your app,Shared Preferences are app level variables that stores the data even you close the app they only get destroyed when you remove the app from your device or clear the data under the Applications in Android.
moreover can we track if users have rated our app, is there any google
api for this feature , can analytics be helpfull for tracking ratings
of an app
=> There isn't such official API available yet!
And SharedPreference is not gonna be helpful as there isn't any such API available, using which you would be able to track whether user has rated already!
I am using the below class to rate my app. But the every time I do this, it says "Requested item not found". but the link < play.google.com/store/apps/details?id=com.xxx.xxx > works perfectly in the browser. Why is it not working here?
One more thing I noticed that if I change the package name to the same of some other app, it works. Is there any chance that something might have been missed while uploading the previous version?
public class apprater {
private final static String APP_TITLE = "abcd";
private final static String APP_PNAME = "com.xxx.xxx";
private final static int DAYS_UNTIL_PROMPT = 3;
private final static int LAUNCHES_UNTIL_PROMPT = 7;
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)));
System.out.println("eeeeeeeeeeeee: "+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();
}
}
This what I am using now:
public void onClick(View v) {
final String appName = APP_PNAME;
try
{
mContext.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.xxx.xxx")));
}
catch (android.content.ActivityNotFoundException anfe)
{
mContext.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://play.google.com/store/apps/details?id=com.xxx.xxx")));
}
// mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
Try this one
final String appName = getPackageName();
try
{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id="+ appName)));
}
catch (android.content.ActivityNotFoundException anfe)
{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://play.google.com/store/apps/details?id="+ appName)));
}
Nearly everything works in a program I've been working on. As I make changes in the UI, everything is set correctly. For reasons I can't figure out, when I hit the enter button of my main UI the app force closes with an exception. From the log...
java.lang.IllegalStateException: Could not find a method enterMood(View) in the activity class com.loch.meaptracker.MainActivity for onClick handler on view class android.widget.Button with id 'enterButtonID'
Here's the program code. Eclipse doesn't flag anything for either errors or warnings. I'm at a bit of a loss and pretty burnt out looking at this. Any help would be greatly appreciated.
package com.loch.meaptracker;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TimePicker;
public class MainActivity extends Activity implements OnSeekBarChangeListener {
private SeekBar happyBar, energyBar, anxietyBar, painBar;
private EditText noteField;
private DatePicker dPick;
private TimePicker tPick;
#SuppressWarnings("unused")
private Button enterButton;
private int happyValue = 4, energyValue = 4, anxietyValue = 4,
painValue = 4;
private static final String TAG = "heapApp";
private String Mood = "Blah";
final Context context = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// bars
happyBar = (SeekBar) findViewById(R.id.happinessBarID);
happyBar.setOnSeekBarChangeListener(this);
energyBar = (SeekBar) findViewById(R.id.energyBarID);
energyBar.setOnSeekBarChangeListener(this);
anxietyBar = (SeekBar) findViewById(R.id.anxietyBarID);
anxietyBar.setOnSeekBarChangeListener(this);
painBar = (SeekBar) findViewById(R.id.painBarID);
painBar.setOnSeekBarChangeListener(this);
// end bars
dPick = (DatePicker) findViewById(R.id.datePicker1);
tPick = (TimePicker) findViewById(R.id.timePicker1);
noteField = (EditText) findViewById(R.id.noteTextFieldID);
enterButton = (Button) findViewById(R.id.enterButtonID);
} catch (Exception onCreateException) {
Log.e(TAG, "Exception received", onCreateException);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
// Bar listener methods
#Override
public void onProgressChanged(SeekBar arg0, int barValue, boolean hFromUser) {
try {
switch (arg0.getId()) {
case R.id.happinessBarID:
happyValue = barValue + 1;
break;
case R.id.energyBarID:
energyValue = barValue + 1;
break;
case R.id.anxietyBarID:
anxietyValue = barValue + 1;
break;
case R.id.painBarID:
painValue = barValue + 1;
break;
}
String debugBarValue = "Happy is " + happyValue + ", Energy is "
+ energyValue + ", Anxiety is " + anxietyValue
+ ", Pain is " + painValue + ".";
System.out.println(debugBarValue);
} catch (Exception BarValueException) {
Log.e(TAG, "Exception received", BarValueException);
}
}
#Override
public void onStartTrackingTouch(SeekBar happyBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar happyBar) {
// TODO Auto-generated method stub
}
// end Bar listener methods
// Enter Button listener Method
public void dialogPop(View v) {
try {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set Title
alertDialogBuilder.setTitle("title");
// set dialog message
alertDialogBuilder.setMessage("You entered: " + getMood())
.setCancelable(false).setPositiveButton("Okay",
// When Okay button clicked the write mood string to file
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
try {
// This is the string that should be
// written to file
String data = getMood();
// This is the file that should be
// written to
File heapFile = new File("heapFile.csv");
// if file doesn't exists, then create
// it
if (!heapFile.exists()) {
heapFile.createNewFile();
}
// true = append file
FileWriter heapFileWritter = new FileWriter(
heapFile.getName(), true);
BufferedWriter heapBufferWritter = new BufferedWriter(
heapFileWritter);
heapBufferWritter.write(data);
heapBufferWritter.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
})
// If they press either the cancel button or the back button
// on their device (Same thing) then close the dialog and
// give the user a chance to change what they've entered
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int id) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
} catch (Exception buttonListenerException) {
Log.e(TAG, "Exception received", buttonListenerException);
}
return;
}
public String getMood() {
try {
int month = dPick.getMonth();
int day = dPick.getDayOfMonth();
int year = dPick.getYear();
int minute = tPick.getCurrentMinute();
String moodAntePost = "AM";
boolean hourType = tPick.is24HourView();
int moodHour = tPick.getCurrentHour();
if (hourType == false && moodHour > 12) {
moodHour = (moodHour - 12);
moodAntePost = "PM";
} else if (hourType == false && moodHour <= 0) {
moodHour = 12;
} else {
}
String noteText = noteField.getText().toString();
Mood = "Happiness," + happyValue + ",Energy," + energyValue
+ ",Anxiety," + anxietyValue + ",Pain," + painValue
+ ",Date," + month + "/" + day + "/" + year + ",Time,"
+ moodHour + ":" + minute + "," + moodAntePost + ",Note,"
+ noteText;
System.out.println(Mood);
} catch (Exception getMoodException) {
Log.e(TAG, "Exception received", getMoodException);
}
return Mood;
}
}
Please check the XML code . i think there in tag of your XML there is one attribute you have added android:onClick="enterMood".... try removing it and running it
use
android:onClick="dialogPop" instead
Your click handler is not in the right format. It needs to include a view parameter for the XML click handler to work properly.
public void getMood(View view){
}
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)
}