mar*_*142 8 android android-activity
是否有使用com.google.android.feedback.FeedbackActivity的示例,就像在Google+应用中使用它发送任何反馈一样?
我试着用它开始
Intent intent = new Intent();
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但我只能得到
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.feedback/com.google.android.feedback.FeedbackActivity}: java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
我一直在寻找最好的解决方案.请查看Google"MyTracks"应用程序,该应用程序是开源的,在Google Code上:
看看它们如何处理API级别与API Adapter类之间的兼容性:
基于API => 14(允许反馈):
menu.findItem(R.id.track_list_feedback)
.setVisible(ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable());
Run Code Online (Sandbox Code Playgroud)
如果API低于14,这将删除"发送反馈"按钮.
基于API => 14(发送反馈):
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);
}
}
Run Code Online (Sandbox Code Playgroud)
来自源代码的Snippet,基于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);
}
}
Run Code Online (Sandbox Code Playgroud)
阅读: 如何使用Intent.ACTION_APP_ERROR作为Android中"反馈"框架的手段? 在这里: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);
}
}
Run Code Online (Sandbox Code Playgroud)
结论:将为所有安装了API 10+和应用程序的手机提供应用程序报告,或者可以通过电子邮件发送信息.
1.确保用户已安装该应用程序
if (applicationExist("com.google.android.feedback"))
Run Code Online (Sandbox Code Playgroud)
2.如果用户安装了应用程序,请直接运行反馈应用程序
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");
Run Code Online (Sandbox Code Playgroud)
3.如果用户未安装应用程序,请将反馈发送至电子邮件
@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[] { "burrowsapps@gmail.com" });
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1477 次 |
| 最近记录: |