I have no idea what it could be. I searched through my code for like 30 min
MainActivity:
public class MainActivity extends Activity {
public void onResume(){
ArrayList<String> voiceResults = getIntent().getExtras()
.getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
if (voiceResults.size() >= 1) {
String infoId = "That is what you said";
Card ShowDataCard = new Card(this);
ShowDataCard.setText(voiceResults.get(0));
//ShowDataCard.setText("Testing");
ShowDataCard.setInfo(infoId);
View ShowDataCardView = ShowDataCard.toView();
setContentView(ShowDataCardView);
}
else {
String mainText = "You did not say anything.";
String infoId = "Why didn't you say anything?";
Card ShowDataCard = new Card(this);
ShowDataCard.setText(mainText);
ShowDataCard.setInfo(infoId);
View ShowDataCardView = ShowDataCard.toView();
setContentView(ShowDataCardView);
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.glass.texttospeech"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.glass.texttospeach.MainActivity"
android:label="#string/app_name"
android:icon="#drawable/icon" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger_start" />
</activity>
</application>
So what could it be? The intent filters are correct, the packages are correct, voice trigger is correct.
I am just trying to have it print what you said. I have done it before but it will not work now!
when you are overriding Activity methods, don't forget to call super methods.
here you are overriding onResume() but not calling super method. call super method like
#Override
public void onResume() {
super.onResume();
// do your work....
}
and use Override annotation when you are overriding any method for readability and check for NullPointException when you are getting extras from Intent. Intent.getExtras...() will return null if there is no mapping found for a given key
Related
None of the many similar questions I have found have helped to solve my issue.
Here are some questions I've looked at:
ServiceConnection.onServiceConnected() never called after binding to started service
onServiceConnected never called after bindService method
ServiceConnection::onServiceConnected not called even though Context::bindService returns true?
OnServiceConnected not getting called
Here is part of my android app code:
//Local service interface
private INetworkQueryService myNetworkQueryService = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Intent intent = new Intent(this, NetworkQueryService.class);
startService (intent);
bindService (new Intent(this, NetworkQueryService.class), myNetworkQueryServiceConnection,
Context.BIND_AUTO_CREATE);
}
//Service connection
private final ServiceConnection myNetworkQueryServiceConnection = new ServiceConnection() {
/** Handle the task of binding the local object to the service */
public void onServiceConnected(ComponentName className, IBinder service) {
myNetworkQueryService = ((NetworkQueryService.LocalBinder) service).getService();
// as soon as it is bound, run a query.
loadNetworksList();
}
/** Handle the task of cleaning up the local binding */
public void onServiceDisconnected(ComponentName className) {
myNetworkQueryService = null;
}
public void loadNetworksList() {
// delegate query request to the service.
try {
myNetworkQueryService.startNetworkQuery(myCallback);
} catch (RemoteException e) {
}
}
};
/**
* This implementation of INetworkQueryServiceCallback is used to receive
* callback notifications from the network query service.
*/
private final INetworkQueryServiceCallback myCallback = new INetworkQueryServiceCallback.Stub() {
#Override
public void onQueryComplete(List<NetworkInfo> networkInfoArray,
int status) throws RemoteException {
displayNetworks(networkInfoArray, status);
}
/** place the message on the looper queue upon query completion. */
};
As you can sy, myNetworkQueryServiceConnection should be called from within the bindService method (located in onCreate()). This (in theory) should also run onServiceConnected (I think), but I put a breakpoint in my code and it never stops inside that method. I did some debugging and bindService returns false, so for some reason it's not successfully binding it.
This is my first time ever having to bind services in Android, so I'm sure I've missed something. I'm hoping someone could point out a mistake.
Let me know if you're missing any information--I'm not sure what all you might need, and I really can't post my entire app code here.
EDIT: I keep reading things about registering the service in the manifest but cannot seem to figure out where or how that would be done? Here's the manifest for this project:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tek15.cellemrmonitor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I certainly don't see anything about the service, but I guess I don't know how to add it.
You need to add a <service> element, as a peer of your <activity> element, as a child of <application>:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tek15.cellemrmonitor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="NetworkQueryService" />
</application>
My example element assumes that NetworkQueryService is really com.tek15.cellemrmonitor.NetworkQueryService — otherwise, substitute in the proper fully-qualified class name.
I am creating android application for sending notification. I have create two Android application. Here I want to send some forms details via notification from first Android application to 2nd android application in Android.
And after that receiving the notification, click on the notification I want to open my second Android application. What should be done to send the push notification to the particular individual user in Android?
Here is my Activity one codes
public class Activity_One extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_one);
Button btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.customer.Activity_One","com.vendor.Activity_B"));
startActivity(intent);
}
});
}
}
Here is AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.customer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Activity_One"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is Activity two code
public class Activity_B extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_two);
Button bn = (Button)findViewById(R.id.button1Send);
bn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction("com.customer.Activity_One");
startActivity(intent);
}
});
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vendor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Activity_B"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action
android:name="com.vendor.Activity_B" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You do not need to use notifications at all. You can just use intents. That is the standard way to accomplish what you want to achieve. See Interacting with Other Apps for details.
From first application you can start a normal notification and from second application initialize a broadcast receiver and read notification
I m trying to start an IntentService from the main activity of y application and it won't start. I have the service in the manifest file. Here's the code:
MainActivity
public class Home extends Activity {
private LinearLayout kontejner;
IntentFilter intentFilter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
kontejner = (LinearLayout) findViewById(R.id.kontejner);
intentFilter = new IntentFilter();
startService(new Intent(getBaseContext(), HomeService.class));
}
}
Service:
public class HomeService extends IntentService {
public HomeService() {
super("HomeService");
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
Toast.makeText(getBaseContext(), "TEST", Toast.LENGTH_LONG).show();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.salefinder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".HomeService" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
How can I make it work?
onHandleIntent gets called from a background thread. You can't modify the UI, or in this case, make Toast from outside the UI thread. So, I wouldn't expect anything to happen with your service.
Just try writing something out with Log.d() to see if your service is getting called.
It seams that android cached a bad version of the app - I forced closed it and started it again, and it worked...
I am trying to send an Intent from the onCreate in an Activity to start an IntentService. However the IntentService's onHandleIntent is never being received. I have tried changing around the Manifest with Intent-filters but nothing seems to be working. No exceptions are being thrown, but the IntentService is simply not called.
Here is the onCreate
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = new TwitterDB(this);
String[] columns = new String[1];
columns[0] = TwitterDB.TEXT;
tAdapter = new SimpleCursorAdapter(this, 0, null, columns, null, 0);
tweets = (ListView)findViewById(R.id.listtwitter);
tweets.setAdapter(tAdapter);
Intent intent = new Intent(this, SyncService.class);
intent.putExtra("action", SyncService.TWITTER_SYNC);
this.startService(intent);
}
Here is the creator and onHandleIntent of the IntentService class, I know it is not being called because logcat never shows "Retrieved intent". The constructor is not called either (There was a log call in there, but I removed it.
public SyncService(){
super("SyncService");
twitterURI = Uri.parse(TWITTER_URI);
Log.i("SyncService", "Constructed");
}
#Override
public void onHandleIntent(Intent i){
int action = i.getIntExtra("action", -1);
Log.i("SyncService", "Retrieved intent");
switch (action){
case TWITTER_SYNC:
try{
url = new URL(twitterString);
conn = (HttpURLConnection)url.openConnection();
syncTwitterDB();
conn.disconnect();
}catch(MalformedURLException e){
Log.w("SyncService", "Twitter URL is no longer valid.");
e.printStackTrace();
}catch(IOException e){
Log.w("SyncService", "Twitter connection could not be established.");
e.printStackTrace();
}
break;
default:;
// invalid request
}
}
And here is the Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TwitterTwoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<service android:name="SyncService"/>
</activity>
</application>
</manifest>
Move your service declaration outside of the scope of the TwitterTwoActivity in the XML file, as I have done here:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TwitterTwoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="SyncService"/>
</application>
</manifest>
You need to define the path to the service in your manifest, simply putting the name is not sufficient.
Change
<service android:name="SyncService"/>
to
<service android:name=".SyncService"/>
if SyncService is in the root of your package, add respective folder before .SyncService if needed.
I am developing an Android app, in which I have to move to MapActivity on Button click event.
But the app is crashing while switching from Activity to MapActivity.
can anyone help me on this?
Thanks in advance.
Here is my code,
public class PopupActivity extends Activity implements GPSCallback
{
.......
public void display_map(String str)
{
Intent showMap_intent = new Intent(this,DisplayGoogleMaps.class);
PopupActivity.this.startActivity(showMap_intent);
}
}
This is my map Activity class
public class DisplayGoogleMaps extends MapActivity
{
MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
And This is my Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="#string/app_name"
android:name=".PopupActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".DisplayGoogleMaps" >
</activity>
</application>
</manifest>
there is nothing in error log while crashing!
Did you declare the map activity in your Manifest? Did you set the Android API package as Google APIs ?
These are mandatory.
What do you mean with "while switching from Activity to MapActivity"?
How do you switch? Any source code?
When you want to show some data in am MapView you have to start an Intent.
public void onClick(View view) {
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
// Set the request code to any code you like, you can identify the
// callback via this code
startActivity(i);
}
From http://www.vogella.de/articles/AndroidIntent/article.html => 6. Tutorial: Explicit intents and data transfer between activities
In your case the class >ActivityTwo< has to be the MapActivity