No Activity found to handle Intent - Error - Java for Android App Development

Hey guys I have already made few apps and doing exactly the same this time though I am getting errors. Please check my logcat below
Code:
05-04 07:35:41.888: E/AndroidRuntime(1066): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.droidacid.count.COUNT }
This is my java code of main class
Code:
package com.droidacid.count;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class mainMenu extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
Button count = (Button) findViewById(R.id.count);
try{
bapticalc.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.droidacid.count.COUNT"));
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
this is my count class code
Code:
package com.droidacid.count;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class system extends Activity{
Button system;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.apticalc);
system = (Button) findViewById(R.id.system);
system.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.droidacid.count.SYSTEM"));
}
});
}
}
And atlast this is my android manifest code
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.droidacid.count"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".mainMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".count"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="com.example.sweet_memories.COUNT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I am really sorry for such a long question guys but really wanted to state everything happening with me...Also I would really appreciate if someone would help me on how to check logcat properly for errors?

So, from your mainMenu you are sending an intent to start the "count", is that the activity that you have named system?
Code:
public class system extends Activity
and in the "system" activity you are trying to start itself? And you also have a button named system?
I think you should rename the class "system" to "count", eclipse will offer you to change the compilation unit to count automatically. And I shouldn't name a button system, maybe mBtnSystem or something like that.

thanks problem solved

coolbud012 said:
thanks problem solved
Click to expand...
Click to collapse
Great. Please add [solved] to the thread title.

Related

Need Help With Admob Ads

for the life of me i cannot get the ads to display. i have it all set so it shows the space for them, but tit will not display an ad. my code is posted below
java file
Code:
package com.cmoney12051.helpcenter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Random;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;
import com.google.ads.*;
import android.app.Activity;
import android.app.AlertDialog;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class WebViewTemplate extends Activity {
private WebView myWebView;
/** Called when the activity is first created. */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { // Enables browsing to previous pages with the hardware back button
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Lookup R.layout.main
AdView layout = (AdView)findViewById(R.id.ads);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID ="xxxxxxxxxxxxxxx";
AdView adView2 = new AdView(this, AdSize.BANNER, pubID );
// Add the adView to it
layout.addView(adView2);
// Initiate a generic request to load it with an ad
AdRequest request= new AdRequest();
request.setTesting(true);
adView2.setVisibility(AdView.VISIBLE);
adView2.loadAd(request);
myWebView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://cmoney12051.com/HelpCenter/mobile.php"); // Specify the URL to load when the application starts
//myWebView.loadUrl("file://sdcard/"); // Specify a local file to load when the application starts. Will only load file types WebView supports
myWebView.setWebViewClient(new WebViewKeep());
myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control
}
private class WebViewKeep extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuItem item = menu.add("Login");
item.setIcon(R.drawable.login);
item = menu.add("Register");
item.setIcon(R.drawable.register);
item = menu.add("Email Cmoney");
item.setIcon(R.drawable.email);
item = menu.add("Share on Facebook");
item.setIcon(R.drawable.facebook_icon);
item = menu.add("Donate");
item.setIcon(R.drawable.donate);
item = menu.add("Exit");
item.setIcon(R.drawable.exit);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getTitle() == "Exit"){
android.app.AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Exit?");
builder.setIcon(R.drawable.exit);
builder.setMessage("Are you sure you want to exit?");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.exit(0);
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
}
if (item.getTitle() == "Login"){
myWebView.loadUrl("http://cmoney12051.com/HelpCenter/ucp.php?mode=login");
myWebView.setWebViewClient(new WebViewKeep());
}
if (item.getTitle() == "Register"){
myWebView.loadUrl("http://cmoney12051.com/HelpCenter/ucp.php?mode=register");
myWebView.setWebViewClient(new WebViewKeep());
}
if (item.getTitle() == "Email Cmoney"){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "[email protected]" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "A Message From Cmoneys Android Help Center App");
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
}
if (item.getTitle() == "Share on Facebook"){
myWebView.loadUrl("http://www.facebook.com/sharer.php?u=http://cmoney12051.com/HelpCenter&t=Cmoneys%20Android%20Help%20Center&refsrc=http://m.facebook.com/sharer.php");
myWebView.setWebViewClient(new WebViewKeep());
}
if (item.getTitle() == "Donate"){
myWebView.loadUrl("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GDB6U44B67FXU");
myWebView.setWebViewClient(new WebViewKeep());
}
return true;
}
}
Main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView
android:layout_width="fill_parent"
android:layout_height="60px"
android:layout_alignParentTop="true"
android:visibility="visible"
android:id="@+id/ads">
</com.google.ads.AdView>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableRow1">
<ImageView android:id="@+id/logo"
android:src="@drawable/logo"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ImageView>
<TextView android:text="Cmoneys Android Help Center"
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textStyle="bold"
android:textSize="30px">
</TextView>
</TableRow>
<DigitalClock android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/digitalClock1" android:text="DigitalClock"></DigitalClock>
<WebView
android:id="@+id/webview"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusableInTouchMode="true">
</WebView>
</LinearLayout>
Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="2"
android:versionName="1.1" package="com.cmoney12051.helpcenter">
<application android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:icon="@drawable/logo">
<activity android:name=".WebViewTemplate"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdView"
android:configChanges="keyboard|keyboardHidden|orientation"/>
<meta-data android:value="xxxxxxxxxxxxxx" android:name="pubID" />
<meta-data android:value="true" android:name="AD_REQUEST" />
<meta-data android:value="false" android:name="TEST_MODE" />
</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Any Help Is Really Appreciated. Thanks anyway

[NEWBIE] Intents not working properly..

Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Manifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.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>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_xml.xml
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:layout_width = "fill_parent"
android:layout_height="wrap_content"
android:text="Click for second Activity"
android:onClick="onClick"
android:id="@+id/button1"
/>
</RelativeLayout>
second_act.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter your name! " />
<Button
android:id="@+id/logOn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hit to Login"
android:onClick = "onClick" />
</LinearLayout>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
int request_Code = 1;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.MainActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
SecondActivity.xml
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SecondActivity extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_act);
Toast.makeText(this, getIntent().getStringExtra("str1"),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, getIntent().getIntExtra("age1", 0),
Toast.LENGTH_SHORT).show();
Bundle bundle = getIntent().getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
}
public void onClick(View v) {
Intent i = new Intent();
i.putExtra("age3", 45);
i.setData(Uri.parse("Something has been passed to main aactivity"));
setResult(RESULT_OK, i);
finish();
}
}
Logcat[only the portion highlighted in red! ]
Uploaded here, for a better view..
hiphop12ism said:
Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Click to expand...
Click to collapse
OK, so first of all, in your manifest, you do not need to create an intent-filter, that is just if an activity needs to be launched from another application.
Then, when you create your Intent to start the SecondActivity, do it like this:
Code:
Intent i = new Intent(this, SecondActivity.class);
// put extras and startforResult here
The Error in the logcat states that it could not find the activity, so I suppose this is why
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Still crashing!
zalez said:
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Click to expand...
Click to collapse
I changed the code, as you said.. But it is still not working...
I am uploading the manifest, and the MainActivity.java again..
Mainfest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.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>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.intents.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.SecondActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
It is giving errors because of how you are trying to get the strings from the intent in SecondActivity.
replace what you have in your SecondActivity onCreate with the below.
Code:
Intent intent = getIntent();
Toast.makeText(this, intent.getStringExtra("str1"), Toast.LENGTH_LONG).show();
Toast.makeText(this, String.valueOf(intent.getIntExtra("age1", 0)), Toast.LENGTH_LONG).show();
Bundle bundle = intent.getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
Thank you, finally it worked :thumbup:
Sent from my GT-S6102 using xda app-developers app

[Guide] Adding Animations To Your Application [Part 1]

Adding Aminations To Give Your Application A Cool Strike :good:
Here I have mentioned some Cool Animations Effects.
[Note: Assuming the package name to be package.name.here and created a folder named anim in /res/.
Blink Effect
Code:
[QUOTE]
[B]Java Code[/B] [BlinkActivity.java]
package package.name.here;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
public class BlinkActivity extends Activity implements AnimationListener {
TextView txtMessage;
Button btnStart;
// Animation
Animation animBlink;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
txtMessage = (TextView) findViewById(R.id.txtMessage);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animBlink = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.blink);
// set animation listener
animBlink.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtMessage.setVisibility(View.VISIBLE);
// start the animation
txtMessage.startAnimation(animBlink);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for blink animation
if (animation == animBlink) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
}
[B]XML Code[/B] [activity_blink.xml in [COLOR="green"]res/layout/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is fadein animation"
android:layout_centerInParent="true"
android:textSize="25dp"
android:padding="20dp"
android:background="#000000"
android:visibility="gone"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]XML Code[/B] [Blink.xml in [COLOR="green"]res/anim/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
[/QUOTE]
FadeOut Effect
Code:
[QUOTE]
[B]Java Code[/B] [FadeOutActivity.java]
package info.androidhive.androidanimations;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class FadeOutActivity extends Activity implements AnimationListener {
TextView txtMessage;
Button btnStart;
// Animation
Animation animFadeOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fadeout);
txtMessage = (TextView) findViewById(R.id.txtMessage);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_out);
// set animation listener
animFadeOut.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// start the animation
txtMessage.startAnimation(animFadeOut);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for fade out animation
if (animation == animFadeOut) {
Toast.makeText(getApplicationContext(), "Animation Stopped",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
[B]XML Code[/B] [activity_fadeout.xml in [COLOR="green"]res/layout/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is fadeout animation"
android:layout_centerInParent="true"
android:textSize="25dp"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]XML Code[/B] [fade_out.xml in [COLOR="green"]res/anim[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
</set>
[/QUOTE]
CrossFade Effect
Code:
[QUOTE]
[B]Java Code[/B] [CrossFadeActivity.java]
package package.name.here;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
public class CrossfadeActivity extends Activity implements AnimationListener {
TextView txtMessage1, txtMessage2;
Button btnStart;
// Animation
Animation animFadeIn, animFadeOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crossfade);
txtMessage1 = (TextView) findViewById(R.id.txtMessage1);
txtMessage2 = (TextView) findViewById(R.id.txtMessage2);
btnStart = (Button) findViewById(R.id.btnStart);
// load animations
animFadeIn = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_out);
// set animation listeners
animFadeIn.setAnimationListener(this);
animFadeOut.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// make fade in element visible
txtMessage2.setVisibility(View.VISIBLE);
// start fade in animation
txtMessage2.startAnimation(animFadeIn);
// start fade out animation
txtMessage1.startAnimation(animFadeOut);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// if animation is fade out hide them after completing animation
if (animation == animFadeOut) {
// hide faded out element
txtMessage1.setVisibility(View.GONE);
}
if(animation == animFadeIn){
// do something after fade in completed
// set visibility of fade in element
txtMessage2.setVisibility(View.VISIBLE);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
[B]XML Code[/B] [activity_crossfade.xml in [COLOR="green"]res/layout/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/txtMessage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This text will fade out"
android:layout_centerInParent="true"
android:textSize="25dp"/>
<TextView android:id="@+id/txtMessage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This text will fade in"
android:layout_centerInParent="true"
android:textSize="25dp"
android:visibility="gone"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]NOTE:No need to create any xml in anim folder for crossfade because it uses fadein and fadeout xml files from anim folder][/B]
[/QUOTE]
FadeIn Effect
Code:
[QUOTE]
[B]Java Code[/B] [FadeInActivity.java]
package package.name.here;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class FadeInActivity extends Activity implements AnimationListener {
TextView txtMessage;
Button btnStart;
// Animation
Animation animFadein;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fadein);
txtMessage = (TextView) findViewById(R.id.txtMessage);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
// set animation listener
animFadein.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtMessage.setVisibility(View.VISIBLE);
// start the animation
txtMessage.startAnimation(animFadein);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for fade in animation
if (animation == animFadein) {
Toast.makeText(getApplicationContext(), "Animation Stopped",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
[B]XML Code[/B] [activity_fadein.xml in [COLOR="green"]res/layout/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is fadein animation"
android:layout_centerInParent="true"
android:textSize="25dp"
android:visibility="gone"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]XML Code[/B] [fade_in.xml in [COLOR="green"]res/anim/[/COLOR] folder]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
[/QUOTE]
Also Check Out Adding Animations To Your Application [Part 2]:victory:
Please correct me if the code goes wrong somewhere.
Saurabh Shah
----------------------------------------------------------------
Hit Thanks :good:
a-ssassi-n said:
Adding Aminations To Give Your Application A Cool Strike :good:
Here I have mentioned some Cool Animations Effects.
Blink Effect
Code:
FadeOut Effect
Code:
CrossFade Effect
Code:
FadeIn Effect
Code:
More Effects coming soon on my next Post :victory: .
Please correct me if the code goes wrong somewhere.
A-ssassi-N
----------------------------------------------------------------
Hit Thanks :good:
Click to expand...
Click to collapse
nice :good:
Sorry, do not understand how to use your codes?
I'm confused
yvesadriel said:
nice :good:
Click to expand...
Click to collapse
English> Wanted a tutorial teaching best to apply the animations do not quite understand! sorry my bad english. Thanks
Portugues Brazil> Queria um tutorial ensinando melhor a aplicar as animações, não entendi muito bem ! desculpe meu mau ingles. Obrigada
Very nice OP!
I use these animations in my app.
Slide in left:
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-100%p" android:toXDelta="0%p" android:duration="250" />
</set>
Slide in right:
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="250" />
</set>
Slide out left:
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="0%p" android:toXDelta="-100%p" android:duration="250" />
</set>
Slide out right:
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="0%p" android:toXDelta="100%p" android:duration="250" />
</set>
I call them like so in base activity:
Code:
void slideInLeft(final View view) {
leftAnim = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
leftAnim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(final Animation animation) {
}
@Override
public void onAnimationRepeat(final Animation animation) {
}
@Override
public void onAnimationEnd(final Animation animation) {
}
});
view.startAnimation(leftAnim);
}
Nice guide! :good:
but there are already a couple of open source animations available like PropertyAnimation or the Android3DFlipTransition for instance. Maybe you can include those, too!
And also, you might want to make a section for animations in a list view as well (like the ListViewAnimations or the SugaredListAnimations)
agentdr8 said:
Very nice OP!
Click to expand...
Click to collapse
Thanks
blinoff82 said:
Sorry, do not understand how to use your codes?
Click to expand...
Click to collapse
Choose the animation you would like to use for you application.
Create a Android application project with blank activity.
[Note: Assuming that your package name is example.package]
Copy the Java Code to src/example.package/MainActivity.java
Copy the XML Code to res/layout/activity_main.xml
BUILD. DONE.
Saurabh Shah
----------------------------------------------------------------
Hit Thanks :good:
SimplicityApks said:
Nice guide! :good:
but there are already a couple of open source animations available like PropertyAnimation or the Android3DFlipTransition for instance. Maybe you can include those, too!
And also, you might want to make a section for animations in a list view as well (like the ListViewAnimations or the SugaredListAnimations)
Click to expand...
Click to collapse
Android3DFlipTransition is Awesome man
Thankyou for suggestion
i would realy like to see some viewager animations /transitions we can apply in transfromPage()
Thanks for making this guide. I look forward to seeing more animations in the future. I've posted this guide to the XDA Portal.
Thanks
willverduzco said:
Thanks for making this guide. I look forward to seeing more animations in the future. I've posted this guide to the XDA Portal.
Click to expand...
Click to collapse
Thank you very much.
Thank you for that!!
But what is that empty if (anim == ...) for??
You have to add Property Animations(and NineOldAndroids library), they are really significant to animating applications nowadays.
Thanks for the guide! Very useful and easy to follow, all in one place! :thumbup:
noted to self thrice
Nevermind managed to fix it

[Guide] Adding Animations To Your Application [Part 2]

Adding Aminations To Give Your Application A Cool Strike :good:
This is the second part of my previous post .
I have mentioned two more Cool Effects here.
Check Out Part 1 Adding Animations To Your Application[Part 1]
[Note: Assuming the package name to be package.name.here and created a folder named anim in /res/.
ZoomIn Effect
Code:
[B]Java Code[/B] [ZoomInActivity.java]
[QUOTE]
package package.name.here;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class ZoomInActivity extends Activity implements AnimationListener {
ImageView imgPoster;
Button btnStart;
// Animation
Animation animZoomIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zoom_in);
imgPoster = (ImageView) findViewById(R.id.imgLogo);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.zoom_in);
// set animation listener
animZoomIn.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// start the animation
imgPoster.startAnimation(animZoomIn);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for zoom in animation
if (animation == animZoomIn) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
[B]XML Code[/B] [activity_zoom_in.xml in res/layout folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center">
<ImageView android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:layout_centerInParent="true"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]XML Code[/B] [zoom_in.xml in res/anim folder]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
[B][COLOR="orange"]NOTE: Here image is a png file kept in res/drawable-hdpi folder.[/COLOR][/B][/QUOTE]
ZoomOut Effect
Code:
[B]Java Code[/B] [ZoomOutActivity.java]
[QUOTE]
package package.name.here
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class ZoomOutActivity extends Activity implements AnimationListener {
ImageView imgPoster;
Button btnStart;
// Animation
Animation animZoomOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zoom_out);
imgPoster = (ImageView) findViewById(R.id.imgLogo);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animZoomOut = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.zoom_out);
// set animation listener
animZoomOut.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// start animation
imgPoster.startAnimation(animZoomOut);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for zoom in animation
if (animation == animZoomOut) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
[B]XML Code[/B] [activity_zoom_out.xml in res/layout folder]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center">
<ImageView android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:layout_centerInParent="true"/>
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation"
android:layout_marginTop="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
[B]XML Code[/B] [zoom_out.xml in res/anim folder]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5" >
</scale>
</set>[/QUOTE]
Please correct me if the code goes wrong somewhere.
Part 3 Coming Soon :fingers-crossed:
Saurabh Shah
----------------------------------------------------------------
Hit Thanks :good:
nice code mate..

can't send message from wear to my phone app

I want to send data from my wear to the phone app.
I've created a phone app with this AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sh.evolutio.car">
<uses-feature
android:name="android.software.leanback"
android:required="true" />
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service android:name=".services.ListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<!-- <data android:scheme="wear" android:host="*" android:pathPrefix="/updatecar" /> -->
</intent-filter>
</service>
<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" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
my Phone ListenerService:
Code:
package sh.evolutio.car.services;
import android.content.Intent;
import android.util.Log;
import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;
public class ListenerService extends WearableListenerService {
private static final String TAG = "ListenerService";
private static final String MESSAGE_PATH = "/updatecar";
@Override
public void onCreate() {
Log.d(TAG, "ListenerService created");
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d(TAG, "onMessageReceived");
if (messageEvent.getPath().equals(MESSAGE_PATH)) {
Log.d(TAG, "good message");
} else {
Log.d(TAG, "bad message");
}
}
}
my MainActivity with this onCreate:
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
startService(new Intent(MainActivity.this, ListenerService.class));
}
When I start the App on my phone I got in the Logcat:
Code:
26131-26131/sh.evolutio.car D/ListenerService: ListenerService created
When I send with the wearapp some data to my phone, my ListenerService didn't fire the onMessageReceived method..
Here is my AndroidManifest from the wearapp:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sh.evolutio.carwear">
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="false" />
<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>
</manifest>
The MainActivity from the wearapp looks like this:
Code:
package sh.evolutio.carwear;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.wearable.activity.WearableActivity;
import android.util.Log;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.wearable.MessageApi;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable;
public class MainActivity extends WearableActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private static String TAG = "MainActivity";
private static final String MESSAGE_PATH = "/updatecar";
Node mNode; // the connected device to send the message to
GoogleApiClient mGoogleApiClient;
private boolean mResolvingError = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Connect the GoogleApiClient
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
sendMessage("test");
// Enables Always-on
setAmbientEnabled();
}
@Override
protected void onStart() {
super.onStart();
if (!mResolvingError) {
mGoogleApiClient.connect();
}
}
/**
* Resolve the node = the connected device to send the message to
*/
private void resolveNode() {
Log.d(TAG, "resolveNode");
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(NodeApi.GetConnectedNodesResult nodes) {
for (Node node : nodes.getNodes()) {
Log.d(TAG, "resolvedNode: " + node);
mNode = node;
}
}
});
}
@Override
public void onConnected(Bundle bundle) {
resolveNode();
}
@Override
public void onConnectionSuspended(int i) {}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "connectionResult: " + connectionResult);
}
/**
* Send message to mobile handheld
*/
private void sendMessage(String Key) {
if (mNode != null && mGoogleApiClient!= null && mGoogleApiClient.isConnected()) {
final String messageKey = Key;
Log.d(TAG, "isConnected: " + mGoogleApiClient.isConnected());
Log.d(TAG, "connected to: " + mNode.getId());
Task<Integer> sendTask = Wearable.getMessageClient(MainActivity.this).sendMessage(mNode.getId(), MESSAGE_PATH, messageKey.getBytes());
sendTask.addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer integer) {
Log.d(TAG, "onSuccess: " + integer);
}
});
sendTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: " + e.getMessage());
}
});
Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), MESSAGE_PATH, messageKey.getBytes()).setResultCallback(
new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(@NonNull MessageApi.SendMessageResult sendMessageResult) {
if (sendMessageResult.getStatus().isSuccess()) {
Log.v(TAG, "Message: { " + messageKey + " } sent to: " + mNode.getDisplayName());
} else {
// Log an error
Log.v(TAG, "ERROR: failed to send Message");
}
}
}
);
}
}
}
When I the message got send, i got this in the logcat from the wearapp:
Code:
sh.evolutio.carwear D/MainActivity: isConnected: true
sh.evolutio.carwear D/MainActivity: connected to: 778d0d53
sh.evolutio.carwear V/MainActivity: Message: { forward } sent to: HUAWEI Mate 10 Pro
sh.evolutio.carwear D/MainActivity: onSuccess: 17282
so the message was sent to my Mate 10 Pro. But why my Mate 10 Pro App can't receive the Message?

Categories

Resources