Is there a sample of using com.google.android.feedback.FeedbackActivity like it's used in the Google+ App to send any feedback?
I tried to start it with
Intent intent = new Intent();
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
startActivity(intent);
but I only get
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.feedback/com.google.android.feedback.FeedbackActivity}: java.lang.NullPointerException
Through your Pixel phone's Settings > Tips & Support > Send feedback. You can also swipe down from the top of your screen to open Quick Settings, then tap the Android Beta tile.
In the top right, tap your profile picture . Tap Help & feedback. Tap Send feedback. Describe the issue you're experiencing.
Sending your feedback is very easy using Google Feedback. Just click Send feedback or Report a bug, enter a description, highlight and/or black out parts of the page, and click Submit to send your feedback straight to Google.
I have been looking for the best solution for this for a while. Please look at the Google "MyTracks" application which is open source and on Google Code here:
https://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
Look at how they handle compatibility between API levels with their API Adapter classes:
https://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks#mytracks%2Futil
Based on API => 14 (allow feedback):
menu.findItem(R.id.track_list_feedback)
.setVisible(ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable());
This will remove the button "Send Feedback" if API is lower than 14.
https://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/util/GoogleFeedbackUtils.java
Based on API => 14 (send feedback):
public class GoogleFeedbackUtils {
private static final String TAG = GoogleFeedbackUtils.class.getSimpleName();
private GoogleFeedbackUtils() {}
/**
* Binds the Google Feedback service.
*
* @param context the context
*/
public static void bindFeedback(Context context) {
Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
intent.setComponent(new ComponentName("com.google.android.gms", "com.google.android.gms.feedback.LegacyBugReportService"));
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
service.transact(Binder.FIRST_CALL_TRANSACTION, Parcel.obtain(), null, 0);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException", e);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
// Bind to the service after creating it if necessary
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
}
https://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
Snippet from source, Based on API => 14:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.track_list_feedback:
GoogleFeedbackUtils.bindFeedback(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Read here: How to use Intent.ACTION_APP_ERROR as a means for a "feedback" framework in Android? and here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void sendFeedback() {
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication().getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
report.systemApp = false;
ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
crash.exceptionClassName = e.getClass().getSimpleName();
crash.exceptionMessage = e.getMessage();
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
e.printStackTrace(printer);
crash.stackTrace = writer.toString();
StackTraceElement stack = e.getStackTrace()[0];
crash.throwClassName = stack.getClassName();
crash.throwFileName = stack.getFileName();
crash.throwLineNumber = stack.getLineNumber();
crash.throwMethodName = stack.getMethodName();
report.crashInfo = crash;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
startActivity(intent);
}
}
Bottom line: Application report will be made for all phones with API 10+ and application installed or information can be sent through email.
1. Make sure the user has the application installed
if (applicationExist("com.google.android.feedback"))
2. If the user has the application installed, run the Feedback application directly
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
3. If the user does not have application installed, send feedback to Email
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void sendFeedback() {
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication().getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_NONE;
report.systemApp = false;
ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
crash.exceptionClassName = e.getClass().getSimpleName();
crash.exceptionMessage = e.getMessage();
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
e.printStackTrace(printer);
crash.stackTrace = writer.toString();
StackTraceElement stack = e.getStackTrace()[0];
crash.throwClassName = stack.getClassName();
crash.throwFileName = stack.getFileName();
crash.throwLineNumber = stack.getLineNumber();
crash.throwMethodName = stack.getMethodName();
report.crashInfo = crash;
try
{
if (applicationExist("com.google.android.feedback"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
startActivity(intent);
}
else
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
intent.putExtra(Intent.EXTRA_SUBJECT, getApplicationContext().getApplicationInfo().loadLabel(getApplicationContext().getPackageManager()).toString()+"("+getPackageManager().getPackageInfo(getApplicationInfo().packageName, 0).versionName+")"+" Contact Form | Device: "+Build.MANUFACTURER+" "+Build.DEVICE+"("+Build.MODEL+") API: "+Build.VERSION.SDK_INT);
intent.setType("plain/html");
startActivity(intent);
}
} catch (Exception e2) { }
}
}
private boolean applicationExist(String uri)
{
PackageManager pm = this.getPackageManager();
boolean exists = false;
try
{
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
exists = true;
}
catch (Exception e) { }
return exists;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With