I would like to launch com.google.android.feedback.FeedbackActivity for my application. Like it happens in Hangouts application.
Does anyone knows which extras I need to pass to do so?
So it seems that this is possible, bur report is not visible in Developer console.
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected Intent prepareIcsFeedbackIntent(Activity activity, PackageManager packageManager) {
ApplicationErrorReport localApplicationErrorReport = new ApplicationErrorReport();
localApplicationErrorReport.packageName = activity.getPackageName();
localApplicationErrorReport.type = 11;
localApplicationErrorReport.installerPackageName = packageManager.getInstallerPackageName(
localApplicationErrorReport.packageName);
return getAppErrortIntent().putExtra(Intent.EXTRA_BUG_REPORT, localApplicationErrorReport);
}
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected Intent getAppErrortIntent() {
Intent localIntent = new Intent(Intent.ACTION_APP_ERROR)
.addCategory(Intent.CATEGORY_DEFAULT)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return localIntent;
}
Although it's not exactly the same, you can programmatically invoke a crash-report-dialog:
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_APP_ERROR);
intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
startActivity(intent);
More information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
Just re-create that layout on a .xml file and create a Class that extends FragmentActivity (as the Google Hangouts App seems to do) or create a Class that extends DialogFragment to handle its logic.
Related
I have constants set up for my Flavor names:
public static final String FLAVOR_NAME_PRO = "pro";
public static final String FLAVOR_NAME_FREE = "free";
Inside my Activity's onCreate() I assign the boolean mUsingProFlavor a value:
mUsingProFlavor = BuildConfig.FLAVOR.equals(FLAVOR_NAME_PRO);
In a clickListener created later on I have this:
if (mUsingProFlavor) {
customerId = getCustomerId();
Intent intent = new Intent(MainActivity.this, CustomerProfileActivity.class);
intent.putExtra("customerId", customerId);
startActivity(intent);
} else {
showProOnlyFeatureAlertDialog(MainActivity.this, mAlertDialog);
}
This is the only way for the user to access CustomerProfileActivity, and yet somehow I'm getting crash reports indicating that one of my Free users is crashing inside of CustomerProfileActivity.
Any idea how this could happen?
if (mUsingProFlavor) {
customerId = getCustomerId();
Intent intent = new Intent(MainActivity.this, CustomerProfileActivity.class);
intent.putExtra("customerId", customerId);
startActivity(intent);
} else {
showProOnlyFeatureAlertDialog(MainActivity.this, mAlertDialog);
}
Your -> if(mUsingProFlavor) is the issue here.
Since mUsingProFlavor is a String, you have to modify your if-check. Currently it is acting as boolean.
if (mUsingProFlavor.equals("pro")) {
customerId = getCustomerId();
Intent intent = new Intent(MainActivity.this, CustomerProfileActivity.class);
intent.putExtra("customerId", customerId);
startActivity(intent);
} else {
showProOnlyFeatureAlertDialog(MainActivity.this, mAlertDialog);
}
I'm trying to get device discovery work using AllJoyn on Android. Following the sample apps, I'm able to get callbacks for foundAdvertisedName and able to join the session. But when calling any methods on the proxyBusObject it thorws BusBlocked Exception. BusSignals work correctly though using SignalEmitter.
mBus = new BusAttachment(context.getPackageName(), BusAttachment.RemoteMessage.Receive);
mBus.enableConcurrentCallbacks();
status = mBus.connect();
if (Status.OK != status) {
return;
} else {
busAttachmentState = BusAttachmentState.CONNECTED;
}
mBus.registerBusListener(new BusListener() {
#Override
public void foundAdvertisedName(String name,
short transport,
String namePrefix) {
mBus.enableConcurrentCallbacks();
short contactPort = CONTACT_PORT;
SessionOpts sessionOpts = new SessionOpts();
sessionOpts.traffic = SessionOpts.TRAFFIC_MESSAGES;
sessionOpts.isMultipoint = false;
sessionOpts.proximity = SessionOpts.PROXIMITY_ANY;
sessionOpts.transports = SessionOpts.TRANSPORT_ANY;
Mutable.IntegerValue sessionId = new Mutable.IntegerValue();
Status status = mBus.joinSession(name,
contactPort,
sessionId,
sessionOpts,
new SessionListener());
mProxyObj = mBus.getProxyBusObject("com.my.well.known.name",
"/MyService",
sessionId.value,
new Class[] { SampleInterface.class });
mSampleInterface = mProxyObj.getInterface(SampleInterface.class);
mSampleInterface.Test(); // BusMethod call throws exception every time
});
I've tried calling the busMethod on a separate thread as well but getting the same error. Does anyone know what could be wrong here?
UPDATE: Edited code to add BusAttachment creation snippet.
I have a function to get running services:
public ArrayList<String> getRunningServices() {
ActivityManager activityMg = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> serviceList = activityMg.getRunningServices(100);
ArrayList<String> serviceName = new ArrayList<String>();
for (int i=0; i<serviceList.size(); i++) {
ActivityManager.RunningServiceInfo currentService = serviceList.get(i);
boolean serviceNam = currentService.started;
if (serviceNam == true) {
serviceName.add(currentService.service.getPackageName());
}
}
return serviceName;
}
Now I want to run one of these services if it is stopped.
To run an installed app I have to use intent like this code:
Intent intent = context.getPackageManager().getLaunchIntentForPackage(nameOfPakage);
context.startActivity(intent);
But I want to just run a service of this app or another one.
I have a String name of package of app and i want start its service.
Is it possible?
Hi there below is to start a service from another application.
Intent intent = new Intent();
String pkg = currentService.service.getPackageName();
String cls = currentService.service.getPackageName() + "." + currentService.service.getClassName();
intent.setComponent(new ComponentName(pkg, cls));
startService(intent);
I would like to reuse the Intent.ACTION_BUG_REPORT in my app, as a simple means of getting user feedback.
Google Maps uses it as their "Feedback" option. But I've not been successful in firing the event.
I'm using the following in a onOptionsItemSelected(MenuItem item):
Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
startActivity(intent);
And in my AndroidManifest.xml I've declared the following under my Activity:
<intent-filter>
<action android:name="android.intent.action.BUG_REPORT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
However, nothing seems to happen besides the screen "blink" when I select the option. The App or intent doesn't crash, it doesn't log anything. Tried it both in the Emulator and on an ICS 4.0.4 device.
I'm clealy missing something, but what?
Edit
Intent.ACTION_APP_ERROR (constant android.intent.action.BUG_REPORT) was added in API level 14, http://developer.android.com/reference/android/content/Intent.html#ACTION_APP_ERROR
This was solved with the help from the link in #TomTasche comment above. Use built-in feedback mechanism on Android.
In my AndroidManifest.xml I added the following to the <Activity> where I want to call the Feedback agent from.
<intent-filter>
<action android:name="android.intent.action.APP_ERROR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And I made a simple method called sendFeedback() (code from TomTasche blogpost)
#SuppressWarnings("unused")
#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_APP_ERROR);
intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
startActivity(intent);
}
}
And from my SettingsActivity I call it like:
findPreference(sFeedbackKey).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public final boolean onPreferenceClick(Preference paramAnonymousPreference) {
sendFeedback();
finish();
return true;
}
});
Verified working with Android 2.3.7 and 4.2.2.
When the sendFeedback() method is called, a "Complete action using"-dialog is opened where the user can select from three actions/icons.
The calling app, which returns to the app, and Google Play and the Feedback agent. Selecting either Google Play Storeor Send feedback will open the built-in Android feedback agent as intended.
I haven't investigated further if it's possible to skip the "Complete action using"-step, it's probably possible with the correct parameters passed to the Intent. So far, this does exactly what I wanted for now.
Please don't mix two different intents Intent.ACTION_BUG_REPORT and Intent.ACTION_APP_ERROR. The first one is designed for old error reporting and feedback and it's supported from API v1. The second one is for sending advanced error reports (supports ApplicationErrorReport object where you can store a lot of useful informations) and was added in API v14.
For sending feedback, I am testing bellow code in my new version of APP (it also create a screenshot of the activity). This starts com.google.android.gms.feedback.FeedbackActivity, which is part of Google Play services. But question is where then I'll find the feedbacks?!
protected void sendFeedback(Activity activity) {
activity.bindService(new Intent(Intent.ACTION_BUG_REPORT), new FeedbackServiceConnection(activity.getWindow()), BIND_AUTO_CREATE);
}
protected static class FeedbackServiceConnection implements ServiceConnection {
private static int MAX_WIDTH = 600;
private static int MAX_HEIGHT = 600;
protected final Window mWindow;
public FeedbackServiceConnection(Window window) {
this.mWindow = window;
}
public void onServiceConnected(ComponentName name, IBinder service) {
try {
Parcel parcel = Parcel.obtain();
Bitmap bitmap = getScreenshot();
if (bitmap != null) {
bitmap.writeToParcel(parcel, 0);
}
service.transact(IBinder.FIRST_CALL_TRANSACTION, parcel, null, 0);
parcel.recycle();
} catch (RemoteException e) {
Log.e("ServiceConn", e.getMessage(), e);
}
}
public void onServiceDisconnected(ComponentName name) { }
private Bitmap getScreenshot() {
try {
View rootView = mWindow.getDecorView().getRootView();
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = rootView.getDrawingCache();
if (bitmap != null)
{
double height = bitmap.getHeight();
double width = bitmap.getWidth();
double ratio = Math.min(MAX_WIDTH / width, MAX_HEIGHT / height);
return Bitmap.createScaledBitmap(bitmap, (int)Math.round(width * ratio), (int)Math.round(height * ratio), true);
}
} catch (Exception e) {
Log.e("Screenshoter", "Error getting current screenshot: ", e);
}
return null;
}
}
Do note that the crash report solution (as in here) is not available on pre-ICS versions of Android.
A shorter, simpler version of the solution of "kaderud" (here) :
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void sendFeedback()
{
final Intent intent=new Intent(Intent.ACTION_APP_ERROR);
final ApplicationErrorReport report=new ApplicationErrorReport();
report.packageName=report.processName=getApplication().getPackageName();
report.time=System.currentTimeMillis();
report.type=ApplicationErrorReport.TYPE_NONE;
intent.putExtra(Intent.EXTRA_BUG_REPORT,report);
final PackageManager pm=getPackageManager();
final List<ResolveInfo> resolveInfos=pm.queryIntentActivities(intent,0);
if(resolveInfos!=null&&!resolveInfos.isEmpty())
{
for(final ResolveInfo resolveInfo : resolveInfos)
{
final String packageName=resolveInfo.activityInfo.packageName;
// prefer google play app for sending the feedback:
if("com.android.vending".equals(packageName))
{
// intent.setPackage(packageName);
intent.setClassName(packageName,resolveInfo.activityInfo.name);
break;
}
}
startActivity(intent);
}
else
{
// handle the case of not being able to send feedback
}
}
Starting with API level 14 you can try to use the ACTION_APP_ERROR intent but the app needs to be available on Google Play store for this to work.
Intent intent = new Intent(Intent.ACTION_APP_ERROR);
startActivity(intent);
//must be available on play store
I want to implement a search in my Android application.
In this page, first I am displaying a user list and then performing a search on the user list. Both are in the same activity. In the following manner, I am getting intent and some values from the previous page. When I display the user list, all the values are coming. But while performing search, spaceId gets lost and becomes null. I need this value.
Intent intent = this.getIntent();
Bundle receiveBundle = intent.getExtras();
spaceId = receiveBundle.getString("spaceId");
What should I do to get this value?
Edit:
String spaceId;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = this.getIntent();
Bundle receiveBundle = intent.getExtras();
spaceId = receiveBundle.getString("spaceId");
String URLTicketList = String.format(getString(R.string.URLTicketList, spaceId));
RestClient client = new RestClient(URLTicketList,
this.getApplicationContext());
try {
client.Execute(RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
TabSettings ts = new TabSettings();
ts.setSelTab(0);
String response = client.getResponse();
tickets = parseTicketList(response);
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
searchResult=getMatchingStrings(tickets,query);
this.ticket_adapter = new TicketAdapter(this,
R.layout.ticket_details_row,searchResult);
setListAdapter(this.ticket_adapter);
}
else {
this.ticket_adapter = new TicketAdapter(this,
R.layout.ticket_details_row, tickets);
setListAdapter(this.ticket_adapter);
}
}
getMatchingstrings()
ArrayList<Ticket> getMatchingStrings(ArrayList<Ticket> list, String regex1) {
ArrayList <Ticket> listClone = new ArrayList<Ticket>();
for (Ticket string : list) {
if(string.getAssignedTo().equals(regex1)){
listClone.add(string);
}
}
return listClone;
}
Try it
getIntent().getExtras().getString("spaceId");
You said your activity is recreating. So you are not getting the value of spaceID after recreation. Then do this thing as below.
public String PREFS_NAME = "Shared_Pref";
Bundle receiveBundle = this.getIntent().getExtras();
String spaceId_value = receiveBundle.getString("spaceId");
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if(spaceId_value == null) {
spaceId_value = settings.getString("spaceId", "");
}
else {
SharedPreferences.Editor editor = settings.edit();
editor.putString("spaceId", spaceId_value);
}
I hope this will help you out.
edit :
I am editing your code.
Which part i have edited, i have mentioned that part as edited. Carefully see what i have changed and do that thing in your code. Then let me know.
String spaceId;
public String PREFS_NAME = "Shared_Pref"; //edited part
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//editing start
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
Bundle receiveBundle = this.getIntent().getExtras();
if(receiveBundle != null) {
spaceId = receiveBundle.getString("spaceId");
if(spaceId == null) {
spaceId = settings.getString("spaceId", "");
}
else {
SharedPreferences.Editor editor = settings.edit();
editor.putString("spaceId", spaceId);
}
}
//editing end
String URLTicketList = String.format(getString(R.string.URLTicketList, spaceId));
RestClient client = new RestClient(URLTicketList,
this.getApplicationContext());
try {
client.Execute(RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
TabSettings ts = new TabSettings();
ts.setSelTab(0);
String response = client.getResponse();
tickets = parseTicketList(response);
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
searchResult=getMatchingStrings(tickets,query);
this.ticket_adapter = new TicketAdapter(this,
R.layout.ticket_details_row,searchResult);
setListAdapter(this.ticket_adapter);
}
else {
this.ticket_adapter = new TicketAdapter(this,
R.layout.ticket_details_row, tickets);
setListAdapter(this.ticket_adapter);
}
}
When you are firstly loading your list in activity,you have to save that spaceId in some SharedPreference variable for further use.And while reloading activity with search result,you can find that Id from SharedPreference variable previously saved.
Be sure,you overwrite that variable as and when you firstly load list in your activity to meet your needs cleanly.
Also you have to get spaceId from intent like:
int spaceId=0;
if(getIntent().hasExtra())
spaceId=getIntent().getStringExtra("spaceId");
Doing this wont give you excpetion when you reload the same activity with no extras to your intent.
Or,you will have to pass this spaceId along with intent you are using to reload the same activity for showing search result.
Hope,you get the point!
If u relaunching the same activity while performing search,u will lost that value. If u r doing so,while relaunching also pass that spaceId to the relaunching activity also using intent.putextra() method
as in your question and comments i guess you are getting problem if your activity is recreated
add following code in manifest file under your activity tag
android:configChanges="keyboardHidden|orientation"
your activity will not be created again
and then use the value of spaceID where you need