Broadcast not receiving between two custom application - android

My program is about calculating calories of some food. This is a practice for CS course. I'm beginner on Android OS and I do not know why my receiving process cannot be completed or shown on Activity.
I just write the relevant code pieces here. I had some items on sqlite database and I can check my items on database with Log.d method and they are okay.
App1:
Manifest:
<receiver android:name="ItemBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.example.furkan.datagenerator" />
</intent-filter>
</receiver>
Received.class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.received);
ItemBroadcastReceiver br = new ItemBroadcastReceiver();
Cursor cursor = (Cursor) br.receivedItem;
ReceivedItemsAdapter adapter = new ReceivedItemsAdapter(this, cursor);
ListView listView = getListView();
listView.setAdapter(adapter);
}
Adapter:
public class ReceivedItemsAdapter extends CursorAdapter {
public ReceivedItemsAdapter(Context context, Cursor c) {
super(context, c);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.received, parent, false);
return retView;
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
//ImageView icon = (ImageView) view.findViewById(R.id.icon);
TextView name = (TextView) view.findViewById(R.id.name);
TextView cal = (TextView) view.findViewById(R.id.amountCal);
TextView unit = (TextView) view.findViewById(R.id.unit);
unit.setText(" cal");
name.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
cal.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2))));
}}
Broadcast Receiver:
public class ItemBroadcastReceiver extends BroadcastReceiver {
Item receivedItem;
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
receivedItem = new Item(bundle.getString("name"),
Integer.parseInt(bundle.getString("calories")),
bundle.getString("category"),
null);
}}
App2:
MainActivity:
public class MainActivity extends AppCompatActivity {
final int DELAY = 60000;
ReceivedItem item;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ReceivedItemsDatabaseHelper dbHelper = new ReceivedItemsDatabaseHelper(this);
item = new ReceivedItem(dbHelper.fetchReceivedItem().getString(
dbHelper.fetchReceivedItem().getColumnIndex(
dbHelper.fetchReceivedItem().getColumnName(1))),
Integer.parseInt(dbHelper.fetchReceivedItem().getString(
dbHelper.fetchReceivedItem().getColumnIndex(
dbHelper.fetchReceivedItem().getColumnName(2)))),
dbHelper.fetchReceivedItem().getString(
dbHelper.fetchReceivedItem().getColumnIndex(
dbHelper.fetchReceivedItem().getColumnName(3))), null);
Thread thread = new Thread() {
public void run() {
synchronized (this) {
try {
Log.d("Response ", item.getName()+", "+item.getCategory()+", "+item.getCalories());
Intent intent = new Intent();
intent.setAction("com.example.furkan.datagenerator");
intent.putExtra("name", item.getName());
intent.putExtra("calories", item.getCalories());
intent.putExtra("category", item.getCategory());
sendBroadcast(intent);
sleep(DELAY);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
thread.start();
}}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

IntentFilter filter = new IntentFilter();
filter.addAction("com.example.furkan.datagenerator");
ItemBroadcastReceiver br = new ItemBroadcastReceiver();
registerReceiver(br, filter);

You should read about BroadcastReceivers again.
ItemBroadcastReceiver br = new ItemBroadcastReceiver();
Cursor cursor = (Cursor) br.receivedItem;
ReceivedItemsAdapter adapter = new ReceivedItemsAdapter(this, cursor);
ListView listView = getListView();
listView.setAdapter(adapter);
This creates a new instance of the receiver and assigns the receivedItem to cursor. But receivedItem is null and since you never register br for broadcasts, it'll never be not null. Also I'm not sure, if Item could be cast to Cursor.
Considering the code you posted here and the title you used, using BroadcastReceiver might not be a good idea at all. You should try to pass data to Received via intent or load the data directly from persisted storage.
And at last your thread doesn't make any sense.

Related

quick tiles is shown but not active in notification bar

I am trying to implement simple quick settings tile with the help of google docs,
but my tile appears to be there but greyed out(intent activity)- I can't click or do anything with it and cant remove it either without restarting my phone(one plus 3T/oreo8.0.0).
and the same thing goes with sample code google provided.
what things do i need to keep in mind/ how to do it?
is there anything I am missing?
I saw one similar question but it was a bit over my head.
MANIFEST
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".QSIntentService"
android:icon="#drawable/ic_android_black_24dp"
android:label="#string/qs_intent_tile_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<activity
android:name=".ResultActivity"
android:label="#string/result_label"/>
</application>
JAVA (Main ACtivity)
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
QSintentservice.java
public class QSIntentService extends TileService{
private static final String SERVICE_STATUS_FLAG = "serviceStatus";
private static final String PREFERENCES_KEY = "com.google.android_quick_settings";
#Override
public void onClick() {
updateTile();
boolean isCurrentlyLocked = this.isLocked();
if (!isCurrentlyLocked) {
Resources resources = getApplication().getResources();
Tile tile = getQsTile();
String tileLabel = tile.getLabel().toString();
String tileState = (tile.getState() == Tile.STATE_ACTIVE) ?
resources.getString(R.string.service_active) :
resources.getString(R.string.service_inactive);
Intent intent = new Intent(getApplicationContext(),
ResultActivity.class);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_NAME_KEY,
tileLabel);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_INFO_KEY,
tileState);
startActivityAndCollapse(intent);
}
}
private void updateTile() {
Tile tile = this.getQsTile();
boolean isActive = getServiceStatus();
Icon newIcon;
String newLabel;
int newState;
if (isActive) {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_active));
newIcon = Icon.createWithResource(getApplicationContext(), ic_android_black_24dp);
newState = Tile.STATE_ACTIVE;
} else {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_inactive));
newIcon =
Icon.createWithResource(getApplicationContext(),
android.R.drawable.ic_dialog_alert);
newState = Tile.STATE_INACTIVE;
}
tile.setLabel(newLabel);
tile.setIcon(newIcon);
tile.setState(newState);
tile.updateTile();
}
private boolean getServiceStatus() {
SharedPreferences prefs =
getApplicationContext()
.getSharedPreferences(PREFERENCES_KEY,
MODE_PRIVATE);
boolean isActive = prefs.getBoolean(SERVICE_STATUS_FLAG, false);
isActive = !isActive;
prefs.edit().putBoolean(SERVICE_STATUS_FLAG, isActive).apply();
return isActive;
}
}
Result.java
public class ResultActivity extends AppCompatActivity {
public static final String RESULT_ACTIVITY_INFO_KEY = "resultActivityInfo";
public static final String RESULT_ACTIVITY_NAME_KEY = "resultActivityName";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
assert extras != null;
String tileState = extras.getString(RESULT_ACTIVITY_INFO_KEY);
String tileName = extras.getString(RESULT_ACTIVITY_NAME_KEY);
TextView outputText = findViewById(R.id.result_info);
outputText.setText(String.format(Locale.US,
getString(R.string.result_output),
tileName,
tileState));
TextView returnHome = findViewById(R.id.result_return_main);
returnHome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent goHome = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(goHome);
}
});
}
}
}
This code works fine on other devices. However, there is an issue in one plus quick setting menu as its observed and brought to notice. Check the below link to verify,
https://forums.oneplus.net/threads/android-oreo-8-0-oxigenos-quick-settings-bug.690621/

updating the listview upon device rotation

When I press the search button for the second time the listview does not update.
When I rotate the phone from a horizontal position to a vertical one the app save the state, but when i rotate the app from a vertical position to a horizontal one it does not.
Can you help me?
MainActivity:
public class MainActivity extends AppCompatActivity implements LoaderCallbacks<List<Book>> {
private static final String LOG_TAG = MainActivity.class.getName();
private static final String GOOGLEBOOK_REQUEST_URL =
"https://www.googleapis.com/books/v1/volumes?q=";
private static final String URL_FIX = "&maxResults=10";
private static final int BOOK_LOADER_ID = 1;
private String googleBookRequest;
private BookAdapter mAdapter;
private ListView listView;
private EditText searchBar;
/** TextView that is displayed when the list is empty */
private TextView mEmptyStateTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
listView.setEmptyView(mEmptyStateTextView);
mAdapter = new BookAdapter(this, new ArrayList<Book>());
final LoaderManager loaderManager = getLoaderManager();
listView.setAdapter(mAdapter);
searchBar = (EditText) findViewById(R.id.search_view);
ImageButton button = (ImageButton) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Get a reference to the ConnectivityManager to check state of network connectivity
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
googleBookRequest="";
// Get details on the currently active default data network
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
// If there is a network connection, fetch data
if (networkInfo != null && networkInfo.isConnected()) {
// Get a reference to the LoaderManager, in order to interact with loaders.
LoaderManager loaderManager = getLoaderManager();
googleBookRequest = createSearchUrl(searchBar);
// Initialize the loader. Pass in the int ID constant defined above and pass in null for
// the bundle. Pass in this activity for the LoaderCallbacks parameter (which is valid
// because this activity implements the LoaderCallbacks interface).
loaderManager.initLoader(BOOK_LOADER_ID, null, MainActivity.this);
} else {
// Otherwise, display error
// First, hide loading indicator so error message will be visible
View loadingIndicator = findViewById(R.id.loading_indicator);
loadingIndicator.setVisibility(View.GONE);
// Update empty state with no connection error message
mEmptyStateTextView.setText(R.string.no_internet_connection);
}
}
});
}
#Override
public Loader<List<Book>> onCreateLoader(int i, Bundle bundle) {
// Create a new loader for the given URL
return new BookLoader(this, googleBookRequest);
}
#Override
public void onLoadFinished(Loader<List<Book>> loader, List<Book> books) {
// Hide loading indicator because the data has been loaded
View loadingIndicator = findViewById(R.id.loading_indicator);
loadingIndicator.setVisibility(View.GONE);
mAdapter.clear();
if (books != null && !books.isEmpty()) {
mAdapter.addAll(books);
} else{
// Set empty state text to display "No earthquakes found."
mEmptyStateTextView.setText(R.string.no_books);}
}
#Override
public void onLoaderReset(Loader<List<Book>> loader) {
// Loader reset, so we can clear out our existing data.
mAdapter.clear();
}
private String createSearchUrl(EditText editText) {
String search = editText.getText().toString().toLowerCase().trim();;
StringBuilder url = new StringBuilder(GOOGLEBOOK_REQUEST_URL);
return url.append(search.replace(" ", "+")).append(URL_FIX).toString();
}
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.booklistingapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Updating a CircularButton in a custom Fragment created with FragmentGridPagerAdapter

I have a wearable app that has a couple of fragments created with FragmentGridPagerAdapter. One of the fragments has a couple of CircularButtons and I want to update the backcolor of the button when a message is received from handheld phone. I have no problems in receiving the message. However, button's color (or anything in UI) doesn't update. Do you know how can I fix this?
public class UIPageAdapter extends FragmentGridPagerAdapter {
private final Context mContext;
MainControlFragment[] mainControlFragments;
private List mRows;
uiChangeListener mUIChangeListener = new uiChangeListener();
public UIPageAdapter(Context ctx, FragmentManager fm) {
super(fm);
Log.i("pageAdapter", "constructor");
mContext = ctx;
mainControlFragments = new MainControlFragment[2];
mainControlFragments[0] = new MainControlFragment();
mainControlFragments[1] = new MainControlFragment();
LocalBroadcastManager.getInstance(ctx).registerReceiver(mUIChangeListener,new IntentFilter(Constants.BROADCAST_CONTROL_HOME));
}
#Override
public Fragment getFragment(int row, int col) {
Log.i("PageAdapter","Fragment #" + col +"is asked");
return mainControlFragments[col];
}
public void changeStatus(int button, boolean status) {
mainControlFragments[0].setStatus(button,status);
// notifyDataSetChanged();
}
public class uiChangeListener extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
String act = intent.getAction();
if (act == Constants.BROADCAST_CONTROL_HOME) {
int key = intent.getIntExtra(Constants.CONTROL_HOME_KEY,-1);
String command = intent.getStringExtra(Constants.CONTROL_HOME_COMMAND);
changeStatus(key,command.equals("on"));
}
}
}
#Override
public int getRowCount() {
return 1;
}
#Override
public int getColumnCount(int i) {
return 2;
}
}
Basically when a message received from the handheld device a WearableListener class broadcasts an update message to the UIPageAdapter
This is the listener class
public class ListenerService extends WearableListenerService
{
String tag = "ListenerService";
#Override
public void onMessageReceived(MessageEvent messageEvent) {
final String message = (new String(messageEvent.getData()));
Log.i(tag,message);
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.BROADCAST_CONTROL_HOME)
.putExtra(Constants.CONTROL_HOME_KEY, messageEvent.getPath())
.putExtra(Constants.CONTROL_HOME_COMMAND,Integer.parseInt(message.substring(1)))
.putExtra("caller",tag));
}
#Override
public void onCreate() {
super.onCreate();
Log.i(tag, "onCreate");
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="smartstuff.com.tr.myautomationtool" >
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
<service android:name=".ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Finally the custom fragment
public class MainControlFragment extends Fragment{
ViewGroup container;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("controlFragment","create");
this.container = container;
// Inflate the layout for this fragment
return inflater.inflate(R.layout.main_control, container, false);
}
public void setStatus(int button, boolean status) {
Log.i("controlFragment",button + " "+ status);
CircularButton[] btns = new CircularButton[4];
btns[0] = (CircularButton) container.findViewById(R.id.cbtnFront);
btns[1] = (CircularButton) container.findViewById(R.id.cbtnBack);
btns[2] = (CircularButton) container.findViewById(R.id.cbtnBed);
btns[3] = (CircularButton) container.findViewById(R.id.cbtnCoffee);
btns[button].setColor(status?Color.BLACK:Color.RED);
}
}
I also tried the notifyDataSetChanged(); method in UIPageAdapter however it it only calls onCreateView method in fragment. Any help is appreciated
I'm assuming you already resolved this but I had to add a call to invalidate() on the CircularButton after calling setColor():
_circularButton.setColor(ContextCompat.getColor(getActivity(), buttonColor));
_circularButton.invalidate();
Without the call to invalidate the UI only updated some of the time.

Gear Fit SDK IllegalStateException

I recently downloaded the Gear Fit-SDK from XDA-Developers-forum and tried the example in the pdf file.
The app is starting and I can click on the ListViewItem to start the ExampleDialog on my Gear Fit. But then I get the following error:
04-01 15:00:52.748 29498-29498/de.chrosey.gearfitone E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.chrosey.gearfitone, PID: 29498
java.lang.IllegalStateException: Scup is not initialized
at com.samsung.android.sdk.cup.ScupDialog.<init>(Unknown Source)
at de.chrosey.gearfitone.cup.HelloCupDialog.<init>(HelloCupDialog.java:15)
at de.chrosey.gearfitone.MainActivity$1.onItemClick(MainActivity.java:39)
...
Here are my files:
MainActivity.java
public class MainActivity extends ActionBarActivity {
String[] NAMES = {"Hello Cup"};
private HelloCupDialog mHelloCupDialog = null;
private static final int Hello_Cup = 0;
private ListView mListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, NAMES);
mListView = (ListView) findViewById(R.id.demo_list);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == Hello_Cup) {
if (mHelloCupDialog == null) {
mHelloCupDialog = new HelloCupDialog(
getApplicationContext());
} else {
mHelloCupDialog.finish();
mHelloCupDialog = null;
}
}
}
});
}[...]}
HelloCupDialog.java
public class HelloCupDialog extends ScupDialog {
public HelloCupDialog(Context context) {
super(context); //<-- this is where the error appears
}
#Override
protected void onCreate(){
super.onCreate();
setBackEnabled(true);
ScupLabel helloLabel = new ScupLabel(this);
[...]
setBackPressedListener(new BackPressedListener() {
#Override
public void onBackPressed(ScupDialog scupDialog) {
finish();
}
});
}}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.chrosey.gearfitone">
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.android.sdk.permission.SAMSUNG_CUP_SERVICE"/>
<application
[...]
<activity
[...]
<intent-filter>
<action android:name="com.samsung.android.sdk.cup"/>
</intent-filter>
</activity>
<meta-data
android:name="SAMSUNG_CUP_APP"
android:value="app_name;ic_launcher;true" />
</application>
I am testing on Samsung S4, Lollipop StockRom. IDE is Android Studio 1.1.
Has anybody an idea why it isn't working as other cups-enabled apps from PlayStore do?
You need to initialize Scup in your MainActivity before creating instance of ScupDialog. Add the following code after the setContentView.
Scup scup = new Scup();
try {
scup.initialize(this);
}catch (Exception e){}
Hope this is clear!

Search dialog box doesn't shows up

I tried to follow the developers guide line and checked the error that are similar to this my manifest and searchable file looks ok but still search dialog box doesn't appears. Any help is appreciated thanks in advance.
ser.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/hint">
</searchable>
manifest.xml
<activity
android:name="e.ftsexample.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/ser" />
</activity>
Mainactivity
public class MainActivity extends Activity {
DbS cr;
private String[] from;
private int[] to;
private SimpleCursorAdapter str;
private ListView LS;
SQLiteDatabase ss;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cr = new DbS(getApplicationContext());
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
GetMysearch(getIntent());
// views
LS = (ListView) findViewById(R.id.listView1);
from = new String[] { DbS.Name_Col, DbS.Number_col };
to = new int[] { R.id.sV, R.id.sVS };
ss = cr.getWritableDatabase();
Cursor currr = ss.query(DbS.Table_Name, new String[] { " rowid _id ",
DbS.Name_Col, DbS.Number_col }, null, null, null, null, null);
str = new SimpleCursorAdapter(this, R.layout.qss, currr, from, to, 0);
LS.setAdapter(str);
}
private void GetMysearch(Intent myint) {
// TODO Auto-generated method stub
// Intent myint = getIntent();
if (Intent.ACTION_SEARCH.equals(myint.getAction())) {
String query = myint.getStringExtra(SearchManager.QUERY);
Log.e("Reached", "intent");
doMySearch(query);
}
}
private void doMySearch(String query) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "QUERY REACHED",
Toast.LENGTH_SHORT).show();
}
#Override
public boolean onSearchRequested() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onSearchRequested",
Toast.LENGTH_SHORT).show();
return super.onSearchRequested();
}
#Override
protected void onNewIntent(Intent intent) {
Toast.makeText(getApplicationContext(), "Intet passed",
Toast.LENGTH_SHORT).show();
setIntent(intent);
GetMysearch(intent);
}
}
try adding this to your activity:
<meta-data
android:name="android.app.default_searchable"
android:value="e.ftsexample.MainActivity" />
Edit: The reason is that you configured your activity to receive search query, but not to initiate a search.you can add this to any other activity and start search by callin
onSearchRequested();
hope this help.

Categories

Resources