如何使用"发送留言反馈",FeedbackActivity,在Android中?如何使用、反馈、留言、Android

2023-09-12 04:57:13 作者:猫腻仙女抱

有没有使用的 com.google.android.feedback.FeedbackActivity 喜欢它的使用Google+应用发送任何反馈的样本?

我试图用

启动

 意向意图=新的意图();
intent.setClassName(com.google.android.feedback,com.google.android.feedback.FeedbackActivity);
startActivity(意向);
 

但我只得到

 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.google.android.feedback/com.google.android.feedback.FeedbackActivity}:显示java.lang.NullPointerException
 

解决方案

解决方案为所有API

我增加了我所有的研究和相关的帖子

我一直在寻找这样做的最好的解决方案了一会儿。请看看谷歌MyTracks应用程序,它是开源的,并在谷歌code在这里:

https://$c$c.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java

看他们如何处理与他们的API适配器类API级别之间的兼容性:

https://$c$c.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks#mytracks%2Futil

处理菜单:

基于API => 14(允许反馈):

  menu.findItem(R.id.track_list_feedback)
    .setVisible(ApiAdapterFactory.getApiAdapter()isGoogleFeedbackAvailable());
 
微信 8.0.30 正式版发布,新功能太香了

这将删除按钮发送反馈,如果API低于14以下。

发送反馈

https://$c$c.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/util/GoogleFeedbackUtils.java

基于API => 14(发送反馈):

 公共类GoogleFeedbackUtils {

  私有静态最后字符串变量= GoogleFeedbackUtils.class.getSimpleName();

  私人GoogleFeedbackUtils(){}

  / **
   *绑定谷歌反馈服务。
   *
   *参数上下文语境
   * /
  公共静态无效bindFeedback(上下文的背景下){
    意向意图=新的意图(Intent.ACTION_BUG_REPORT);
    intent.setComponent(新单元名(com.google.android.gms,com.google.android.gms.feedback.LegacyBugReportService));
    ServiceConnection serviceConnection =新ServiceConnection(){
        @覆盖
      公共无效onServiceConnected(组件名名称,服务的IBinder){
        尝试 {
          service.transact(Binder.FIRST_CALL_TRANSACTION,Parcel.obtain(),空,0);
        }赶上(RemoteException的E){
          Log.e(TAG的RemoteException,E);
        }
      }

        @覆盖
      公共无效onServiceDisconnected(组件名名){}
    };
    如果有必要创建后//绑定到服务
    context.bindService(意向,serviceConnection,Context.BIND_AUTO_CREATE);
  }
}
 

$ C $下菜单:

https://$c$c.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java

片段从源代码,基于API => 14

  @覆盖
  公共布尔onOptionsItemSelected(菜单项项){
    意向意图;
    开关(item.getItemId()){
      案例R.id.track_list_feedback:
        GoogleFeedbackUtils.bindFeedback(本);
        返回true;
      默认:
        返回super.onOptionsItemSelected(项目);
    }
  }
 

解决方案API 10 +:

在这里阅读: How使用Intent.ACTION_APP_ERROR作为一个&QUOT的手段;反馈"框架的Andr​​oid? 和这里: http://blog.tomtasche.at/2012 /10/use-built-in-feedback-mechanism-on.html

  @TargetApi(Build.VERSION_ codeS.ICE_CREAM_SANDWICH)
私人无效sendFeedback(){
    尝试 {
        INT I = 3/0;
    }赶上(例外五){
    ApplicationErrorReport报告=新ApplicationErrorReport();
    report.packageName = report.processName = getApplication()getPackageName()。
    report.time = System.currentTimeMillis的();
    report.type = ApplicationErrorReport.TYPE_CRASH;
    report.systemApp = FALSE;

    ApplicationErrorReport.CrashInfo崩溃=新ApplicationErrorReport.CrashInfo();
    crash.exceptionClassName = e.getClass()getSimpleName()。
    crash.exceptionMessage = e.getMessage();

    StringWriter的作家=新的StringWriter();
    PrintWriter的打印机=的新PrintWriter(作家);
    e.printStackTrace(打印机);

    crash.stackTrace = writer.toString();

    的StackTraceElement堆栈= e.getStackTrace()[0];
    crash.throwClassName = stack.getClassName();
    crash.throwFileName = stack.getFileName();
    crash.throwLineNumber = stack.getLineNumber();
    crash.throwMethodName = stack.getMethodName();

    report.crashInfo =碰撞;

    意向意图=新的意图(Intent.ACTION_VIEW);
    intent.setClassName(com.google.android.feedback,com.google.android.feedback.FeedbackActivity);
    intent.putExtra(Intent.EXTRA_BUG_REPORT,报告);
    startActivity(意向);
    }
}
 

解决方案为所有的API

底线:应用报告将与API的所有手机10+和已安装的应用程序或信息可通过电子邮件发送

1。确保用户已经安装了应用程序

 如果(applicationExist(com.google.android.feedback))
 

2。如果用户安装的应用程序,直接运行应用程序的反馈

  intent.setClassName(com.google.android.feedback,com.google.android.feedback.FeedbackActivity);
 

3。如果用户没有安装的应用程序,将反馈发送到电子邮件

  @TargetApi(Build.VERSION_ codeS.ICE_CREAM_SANDWICH)
私人无效sendFeedback(){
    尝试 {
        INT I = 3/0;
    }赶上(例外五){
        ApplicationErrorReport报告=新ApplicationErrorReport();
        report.packageName = report.processName = getApplication()getPackageName()。
        report.time = System.currentTimeMillis的();
        report.type = ApplicationErrorReport.TYPE_NONE;
        report.systemApp = FALSE;

        ApplicationErrorReport.CrashInfo崩溃=新ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass()getSimpleName()。
        crash.exceptionMessage = e.getMessage();

        StringWriter的作家=新的StringWriter();
        PrintWriter的打印机=的新PrintWriter(作家);
        e.printStackTrace(打印机);

        crash.stackTrace = writer.toString();

        的StackTraceElement堆栈= e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo =碰撞;

        尝试
        {
            如果(applicationExist(com.google.android.feedback))
            {
                意向意图=新的意图(Intent.ACTION_VIEW);
                intent.setClassName(com.google.android.feedback,com.google.android.feedback.FeedbackActivity);
                intent.putExtra(Intent.EXTRA_BUG_REPORT,报告);
                startActivity(意向);
            }
            其他
            {
                意向意图=新的意图(Intent.ACTION_SEND);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Intent.EXTRA_EMAIL,新的String [] {burrowsapps@gmail.com});
                intent.putExtra(Intent.EXTRA_SUBJECT, getApplicationContext().getApplicationInfo().loadLabel(getApplicationContext().getPackageManager()).toString()+"("+getPackageManager().getPackageInfo(getApplicationInfo().packageName, 0).versionName +)+联系我们|设备:+ Build.MANUFACTURER ++ Build.DEVICE +(+ Build.MODEL +)API:+ Build.VERSION.SDK_INT);
                intent.setType(普通/ HTML);
                startActivity(意向);
            }
        }赶上(例外E2){}
    }
}

私人布尔applicationExist(字符串URI)
{
    PackageManager下午= this.getPackageManager();
    布尔存在= FALSE;
    尝试
    {
        pm.getPackageInfo(URI,PackageManager.GET_ACTIVITIES);
        存在= TRUE;
    }
    赶上(例外五){}

    返回的存在;
}
 

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

解决方案

Solution for all APIs

I have added all my research and related posts

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

Handling Menus:

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.

Sending Feedback:

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);
  }
}

Code for menu:

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);
    }
  }

Solution for API 10+:

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);
    }
}

Solution for All APIs

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[] { "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;
}