I love this quick select dialog that pops up when you enable bluetooth. But it doesn't always show. I'd like to display this dialog programmatically.
The closest I can get is with:
Intent bluetoothPicker = new Intent("android.bluetooth.devicepicker.action.LAUNCH");
bluetoothPicker.putExtra("android.bluetooth.devicepicker.extra.FILTER_TYPE", 1);
bluetoothPicker.putExtra("android.bluetooth.devicepicker.extra.NEED_AUTH", false);
bluetoothPicker.putExtra("android.bluetooth.devicepicker.extra.LAUNCH_PACKAGE", "com.cake.x0a.WoBo");
However, there are some slight differences, as you can see . But the biggest problem is, when you select a device, the dialog closes without attempting to connect to the device. With error:
E/WindowManager: android.view.WindowLeaked: Activity
com.android.settings.bluetooth.BluetoothScanDialog has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{428851c0
V.E..... R......D 0,0-640,855} that was originally added here
at android.view.ViewRootImpl.(ViewRootImpl.java:467)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:267)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:289)
at com.android.settings.bluetooth.BluetoothScanDialog.initialize(BluetoothScanDialog.java:86)
at com.android.settings.bluetooth.BluetoothScanDialog.onPostCreate(BluetoothScanDialog.java:103)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1156)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
The good news is, it still sends the DEVICE_SELECTED intent before it closes, so I could still connect to it programmatically. But it's really dirty. I want to use the self-contained LocalBluetoothMonitor from native android, which can scan, connect, pair, all on its own without changing activities.
It seems as if the BluetoothScanDialog can not connect to devices, just show nearby devices. It is not an error with your code.
The good thing is that if you have the DEVICE_SELECTED, it is not much code to finish the job. You should be able to use the following:
private Boolean connect(BluetoothDevice bdDevice) {
Boolean bool = false;
try {
Class cl = Class.forName("android.bluetooth.BluetoothDevice");
Class[] par = {};
Method method = cl.getMethod("createBond", par);
Object[] args = {};
bool = (Boolean) method.invoke(bdDevice);//, args);// this invoke creates the detected devices paired.
} catch (Exception e) {
e.printStackTrace();
}
return bool.booleanValue();
};
Related
I am using JItsi meet api for video call on linphone android app open source project. I have followed jitsi meet handbook for integrating on linphone.
Here is my sample code:
public class JitsiActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
URL serverURL;
try {
serverURL = new URL("https://meet.jit.si");
} catch (MalformedURLException e) {
e.printStackTrace();
throw new RuntimeException("Invalid server URL!");
}
JitsiMeetConferenceOptions defaultOptions =
new JitsiMeetConferenceOptions.Builder()
.setServerURL(serverURL)
.setWelcomePageEnabled(false)
.build();
JitsiMeet.setDefaultConferenceOptions(defaultOptions);
JitsiMeetConferenceOptions options =
new JitsiMeetConferenceOptions.Builder().setRoom("linphone").build();
JitsiMeetActivity.launch(this, options);
finish();
}
}
I have successfully made a call on debug mode, after making an apk on release mode, It refresh activity when I attempt to make a video call and go to home page. can you give me a guideline to solve this problem. I have tested apk on Android 10 OS.
--After Debugging on release mode I have found this error
020-09-24 16:50:12.383 10364-10364/org.linphone E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.linphone, PID: 10364
java.lang.IllegalArgumentException: reportSizeConfigurations: ActivityRecord not found for: Token{2329006 ActivityRecord{cf5fae1 u0 org.linphone/.activities.JitsiActivity d-1 s-1 t-1 f}}
at android.os.Parcel.createException(Parcel.java:1967)
at android.os.Parcel.readException(Parcel.java:1931)
at android.os.Parcel.readException(Parcel.java:1881)
at android.app.IActivityManager$Stub$Proxy.reportSizeConfigurations(IActivityManager.java:8621)
at android.app.ActivityThread.reportSizeConfigurations(ActivityThread.java:3360)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3318)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7096)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.reportSizeConfigurations(ActivityManagerService.java:10305)
at android.app.IActivityManager$Stub.onTransact$reportSizeConfigurations$(IActivityManager.java:12560)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2357)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3841)
at android.os.Binder.execTransact(Binder.java:750)
You need to provide a stacktrace to for anyone to help you debug it, however, this code can be simplified greatly which would lead to easier debugging..
You are supplying Jitsi with it's own default server url "https://meet.jit.si" which isn't necessary as Jitsi will use it's own server anyway. If you were planning on using your own server you can still provide that easily in the JitsiMeetActivity::launch method as the room parameter...
JitsiMeetActivity.launch(context, "https://myserver.com/linphone")
Removing all the unnecessary boiler-plate will leave you with this:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
JitsiMeetActivity.launch(this, "linphone");
}
I'm using Xamarin for Android and I'm getting this error in an AlertDialog.Builder.Show() method, but it only happens on some Samsung (with Android 7.0) devices, we have tried some other devices and this problem doesn't happen. I'm getting it only after using the application some time. The stacktrace is the following
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <7802aa64ad574c33adca332a3fa9706a>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <7802aa64ad574c33adca332a3fa9706a>:0
at Android.App.AlertDialog+Builder.Show () [0x0000a] in <dc51acef1f304f0dab449a7fc6039799>:0
at Prizma.Controls.Common.BindingComboBox.ShowDialog () [0x00062] in C:\TeamProjects\PrizmaProject\Main\MobileSales.iOS\Prizma.Controls.iOS\Common\BindingComboBox.cs:408
--- End of managed Android.Views.WindowManagerBadTokenException stack trace ---
android.view.WindowManager$BadTokenException: Unable to add window -- window android.view.ViewRootImpl$W#cb70704 has already been added
at android.view.ViewRootImpl.setView(ViewRootImpl.java:902)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97)
at android.app.Dialog.show(Dialog.java:404)
at android.app.AlertDialog$Builder.show(AlertDialog.java:1136)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11185)
at android.view.View$PerformClick.run(View.java:23752)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
My code is something like this
try
{
AlertDialog.Builder a = new AlertDialog.Builder(MainActivity);
a.SetTitle("Select");
a.SetAdapter(_Adapter, new EventHandler<DialogClickEventArgs>(ClosedDialog));
a.Create();
a.Show();
}
catch (Exception ex)
{
//Exception code
}
I put the AlertDialog.Builder Show() method in a Try Catch, but after I get the exception for the first time, I keep getting it everytime.
Some remarks
I'm still getting this error even the application never goes to the background.
The app is compiled using the latest Android SDK (8.1)
I didin't have Xamarin Android to the latest version, but now I have it and the problem is still there.
Not just the AlertDialogs doesn't show after the error, the Popup menus too.
I got a Samsung Galaxy J7 Prime with Android 6.0.1 and this error didn't happen, but after upgrade it to 7.0 the problem started. In other devices like Motorola, Hawuei, LG, etc.. we don't have this issue even they have Android 7.0.
Please help me, I have weeks with this issue and my clients that have Samsung devices are killing me :)
Thanks in advance.
Regards
Allan
You are adding a dialog to a dead activity, so before showing dialog, you should check if the activity is already finished by this:
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.app_name);
builder.setMessage(msg);
AlertDialog alert = builder.create();
//To check if activity is finished
if (!((Activity)ctx).isFinishing()) {
alert.show();
}
Show your dialog like this in a fragment: use if (!IsFinishing) in an activity
if (!((Activity)Context).IsFinishing)
{
try
{
AlertDialog.Builder a = new AlertDialog.Builder(MainActivity);
a.SetTitle("Select");
a.SetAdapter(_Adapter, new EventHandler<DialogClickEventArgs>(ClosedDialog));
a.Create();
a.Show();
}
catch (Exception ex)
{
//Exception code
}
}
try
{
RunOnUiThread (() => {
AlertDialog.Builder a = new AlertDialog.Builder(MainActivity);
a.SetTitle("Select");
a.SetAdapter(_Adapter, new EventHandler<DialogClickEventArgs>(ClosedDialog));
a.Create();
a.Show();
});
}
catch (Exception ex)
{
//Exception code
}
with reference to : https://forums.xamarin.com/discussion/128420/badtokenexception-unable-to-add-window-window-android-view-viewrootimpl-has-already-been-added
I have pretty large app to inspect with a lot of activities. One of most popular exceptions is
No Activity found to handle Intent {
act=android.intent.action.WEB_SEARCH (has extras) }
What the heck? I don't see in code any "WEB_SEARCH" anywhere, I can't reproduce it, I don't even know where to look for cause (in which Activity). Below stack of Exception, without any class from my package... How to track and fix this?
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.WEB_SEARCH (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
at android.app.Activity.startActivityForResult(Activity.java:3432)
at android.app.Activity.startActivityForResult(Activity.java:3393)
at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
at android.app.Activity.startActivity(Activity.java:3628)
at android.app.Activity.startActivity(Activity.java:3596)
at android.webkit.SelectActionModeCallbackSec.onActionItemClicked(SelectActionModeCallbackSec.java:390)
at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onActionItemClicked(PhoneWindow.java:3264)
at android.support.v7.view.SupportActionModeWrapper$CallbackWrapper.onActionItemClicked(Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onActionItemClicked(Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onActionItemClicked(Unknown Source)
at android.support.v7.view.StandaloneActionMode.onMenuItemSelected(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(Unknown Source)
at android.support.v7.view.menu.MenuItemImpl.invoke(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.performItemAction(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.performItemAction(Unknown Source)
at android.support.v7.view.menu.MenuPopupHelper.onItemClick(Unknown Source)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1490)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3275)
at android.widget.AbsListView$1.run(AbsListView.java:4518)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
I have to answer my own question for another future searchers. For use in Activity with WebView, or for safety in some Base/MainActivity abstract layer:
#Override
public void startActivityForResult(Intent i, int reqCode, Bundle b){
boolean activityExists = i.resolveActivityInfo(getPackageManager(), 0) != null;
if(activityExists)
super.startActivityForResult(i, reqCode, b);
else{
if(Intent.ACTION_WEB_SEARCH.equals(i.getAction()) && i.getExtras()!=null){
String query = i.getExtras().getString(SearchManager.QUERY, null);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.pl/search?q="+query));
boolean browserExists = i.resolveActivityInfo(getPackageManager(), 0) != null;
if(browserExists && query!=null){
startActivity(browserIntent);
return;
}
}
Toast.makeText(this, R.string.error_no_app_for_intent, Toast.LENGTH_LONG).show();
}
}
Reason of this behaviour is (probably) custom system UI/modded Android made by hardware producer, which is adding some features related with searching. Not reproducable on "clean" Android device
Met the same issue recently, did some dig, i think snachmsm's answer is good, and i wanna make some analysis for other searchers.
Obviously no code written by me is starting an Intent with WEB_SEARCH, and according to the crash log, the intent is invoked by android.webkit.SelectActionModeCallbackSec.onActionItemClicked, so the fact is that if you use a webview, when the user long click and select some text , in some phones or themes or ROMs it will show an ActionMenu with "find" and "web search" or only one of them, depends on the various implementation. And when the user click "web search" it will start an intent with WEB_SEARCH.
Then the solution is simple, in the Activities that use a webview, override startActivityForResult to handle the certain intent. Why don't he override startActivity either? Because startActivity invoke startActivityForResult eventually.
I'm developing an Android application that casts content to Chromecast.
Sometimes in my com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks implementation in the onConnected method, I get a
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
exception.
Here is the stack trace:
FATAL EXCEPTION: main
Process: com.joaomgcd.autocast, PID: 13771
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
at com.google.android.gms.internal.eg.a(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.b(Unknown Source)
at com.google.android.gms.cast.Cast$CastApi$a.launchApplication(Unknown Source)
at com.joaomgcd.autocast.media.MediaConnectionCallbacks.onConnected(MediaConnectionCallbacks.java:37)
at com.google.android.gms.internal.dx.b(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.bn(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.f(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$2.onConnected(Unknown Source)
at com.google.android.gms.internal.dx.b(Unknown Source)
at com.google.android.gms.internal.dx.bT(Unknown Source)
at com.google.android.gms.internal.dw$h.b(Unknown Source)
at com.google.android.gms.internal.dw$h.b(Unknown Source)
at com.google.android.gms.internal.dw$b.bR(Unknown Source)
at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
This only seems to happen if I had already connected to the GoogleApiClient before and am connecting for a second time. Between the 2 calls I disconnect from the api client with the code below.
My guess is that this is a bug. Am I correct? Since I'm in the onConnected method, the GoogleApiClient should already be connected.
What can I do to get around it? Should I just wait for a while until the GoogleApiClient is really connected?
I am doing this in a service and here are the relevant bits:
when the service starts:
mMediaRouter.addCallback(mMediaRouteSelector, mediaCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
mediaCallback has this code:
#Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
super.onRouteAdded(router, route);
if (route.getDescription().equals("Chromecast")) {
...
mSelectedDevice = com.google.android.gms.cast.CastDevice.getFromBundle(route.getExtras());
...
castClientListener = new CastListener(context, apiClient);
Cast.CastOptions.Builder apiOptionsBuilder = Cast.CastOptions.builder(mSelectedDevice, castClientListener);
...
apiClient.set(new GoogleApiClient.Builder(context).addApi(Cast.API, apiOptionsBuilder.build()).addConnectionCallbacks(connectionCallback).addOnConnectionFailedListener(new MediaConnectionFailedListener(context)).build());
apiClient.get().connect();
}
}
connectionCallback has this code:
#Override
public void onConnected(final Bundle arg0) {
...
Cast.CastApi.launchApplication(apiClient, UtilAutoCast.CHROMECAST_APP_ID, false).setResultCallback(connectionCallback);
...
}
The code above is the part where the crash happens.
And when I stop the service I run this code:
if (mMediaRouter != null) {
mMediaRouter.removeCallback(mediaCallback);
mMediaRouter = null;
}
if (apiClient != null) {
Cast.CastApi.stopApplication(apiClient);
if (apiClient.isConnected()) {
apiClient.disconnect();
apiClient = null;
}
}
Thanks in advance.
Google APIs for Android > GoogleApiClient
You should instantiate a client object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.
The implementation of the GoogleApiClient appears designed for only a single instance. It's best to instantiate it only once in onCreate, then perform connections and disconnections using the single instance.
I would guess that only one GoogleApiClient can be actually be connected, but multiple instances are receiving the onConnected callback.
In your case it's probably fine to not call connect in onStart, but only in onRouteAdded.
I think this issue is very similar to Fatal Exception: java.lang.IllegalStateException GoogleApiClient is not connected yet
Have you declare following <meta> tag
<application ...>
...
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
...
</application>
I just forgot to write so may you also stuck with this reason.
Thank you.
From showcase app (Googlecast Github Sample CastHelloText-android ) receiver app is launched onRouteSelected (not onRouteAdded as you are doing in your code). I would try to change that. In case it does not work, I would add log lines in every method related to connection & session, and see what is happening.
Another tip: I have had crash with stopping the application (in case chromecast device is physically plugged out from power). Solution is to putCast.CastApi.stopApplication(apiClient); inside if (apiClient.isConnected()).
It seems like you are calling GoogleApiClient before it is connected
move this line in onCreate()
// First we need to check availability of play services
if (checkPlayServices()) {
// Building the GoogleApi client
//buildGoogleApiClient();
try {
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}catch (IllegalStateException e)
{
Log.e("IllegalStateException", e.toString());
}
createLocationRequest();
}
Hope it helps you.
According to the Android documentation if I don't want my ShareActionProvider to persist the share history I should call
mShareActionProvider.setShareHistoryFileName(null)
However when I do this I get the following crash on selecting a share option:
11-15 10:06:34.848: E/AndroidRuntime(22461): java.lang.IllegalStateException: No preceding call to #readHistoricalData
11-15 10:06:34.848: E/AndroidRuntime(22461): at android.widget.ActivityChooserModel.persistHistoricalDataIfNeeded(ActivityChooserModel.java:573)
11-15 10:06:34.848: E/AndroidRuntime(22461): at android.widget.ActivityChooserModel.addHisoricalRecord(ActivityChooserModel.java:743)
11-15 10:06:34.848: E/AndroidRuntime(22461): at android.widget.ActivityChooserModel.chooseActivity(ActivityChooserModel.java:491)
11-15 10:06:34.848: E/AndroidRuntime(22461): at android.widget.ActivityChooserView$Callbacks.onItemClick(ActivityChooserView.java:547)
Here is the code that sets up the ShareActionProvider:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.article_pager_menu, menu);
// mShareActionProvider is a field in the Activity
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
.getActionProvider();
mShareActionProvider
.setShareHistoryFileName(null);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
mShareActionProvider.onCreateActionView();
return true;
}
Any ideas how I can fix this?
So in the end I had to write my own ShareActionProvider by copying the one found in Android source. I also had to copy over the ActivityChooserView and the ActivityChooserModel from source. The actual modification needed to hide the default activity in the action bar is in the updateAppearance() method in the ActivityChooserView. This is how it should look:
private void updateAppearance() {
// Expand overflow button.
if (mAdapter.getCount() > 0) {
mExpandActivityOverflowButton.setEnabled(true);
} else {
mExpandActivityOverflowButton.setEnabled(false);
}
mDefaultActivityButton.setVisibility(View.GONE);
if (mDefaultActivityButton.getVisibility() == VISIBLE) {
mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
} else {
mActivityChooserContent.setBackgroundDrawable(null);
}
}
I couldn't figure out why setShareHistoryFileName(null) was causing the problem I originally described though. Thanks for the attempted answer Seven.
Reading the source code on ActivityChooserModel I've found that the history file is open using Context's openFileInput. As long as that class keep working like that, you will be able to keep your history "clean" if you delete it using the usual method for those kinds of files:
getApplicationContext().deleteFile(SHARE_HISTORY_FILE_NAME);
shareActionProvider.setShareHistoryFileName(SHARE_HISTORY_FILE_NAME);
The "most used" icon will show for a while, when the selected application is opening, but as soon as the user is back at your app, it will disappear.
You could also delete the file on your onShareTargetSelected method, if needed.
I tried all, I'm using old widget.ShareActionProvider (not compat 7), so null leads to crash, deleteFile surely deletes but history always still exists after app restart... so I've found only one working thing: random!
String fname=ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME;
try {
fname = prefs.getString("SHARE_HISTORY_FILE_NAME", ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
getApplicationContext().deleteFile(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
fname="SHARE_HISTORY_FILE_NAME"+Math.random()*1000;
SharedPreferences.Editor ed = prefs.edit();
ed.putString("SHARE_HISTORY_FILE_NAME", fname);
ed.commit();
} catch (Exception e) {
Log.e(TAG,"err "+e.toString());
}
mSharedActionProvider.setShareHistoryFileName(fname);
modified com.actionbarsherlock.widget.ShareActionProvider's onCreateActionView then call ActivityChooserModel's method: setHistoryMaxSize(0)