cubeacon / android-cubeacon-sample

Android Cubeacon Sample Project
12 stars 10 forks source link

meta user #8

Closed agungR closed 9 years ago

agungR commented 9 years ago

Hi Cubeacon, i stiil newbie on android programming i have a problem putting on script for meta user. i saw on backend it can place #fullname for notification. but when i try running on application it just say "there". i saw this script on cubeacon guide.

CBUser.setUserData("User fullname", "User valid email"); CBUser.currentUser().sendDataInBackground(new Callback() { @Override public void onCompleted(Exception exp) { if (exp == null) // show succesfull message else // show error message by exp.getMessage() } }); where to put this and how to use it.

alann-maulana commented 9 years ago

Hi @agungR ,

You can put that code on your activity. After successfully set your username, you can enable and set your notification text with Personal Notification on Cubeacon Developer

Regards.

agungR commented 9 years ago

Hi @alann-maulana , i use this in my activity

public class InputActivity extends Activity {
    private EditText name, email;
    private Button save;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this.getApplicationContext();

        name = (EditText) findViewById(R.id.editName);
        email = (EditText) findViewById(R.id.editEmail);
        save = (Button) findViewById(R.id.saveBtn);

        save.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                CBUser.setUserData("User fullname", "User valid email");
                CBUser.currentUser().sendDataInBackground(new Callback() {
                    @Override
                    public void onCompleted(Exception exp) {
                        if (exp == null) {
                            Intent intent = new Intent(InputActivity.this,
                                    SplashActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                        } else {
                            Log.e("InputActivity", exp.getMessage());
                            }

                        }
                });
            }
        });

    }

}

But still Force Close with error

08-10 10:30:19.049: E/AndroidRuntime(1848): FATAL EXCEPTION: main
08-10 10:30:19.049: E/AndroidRuntime(1848): Process: com.example.cube, PID: 1848
08-10 10:30:19.049: E/AndroidRuntime(1848): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cube/com.example.cube.InputActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.os.Looper.loop(Looper.java:135)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread.main(ActivityThread.java:5221)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at java.lang.reflect.Method.invoke(Native Method)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at java.lang.reflect.Method.invoke(Method.java:372)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-10 10:30:19.049: E/AndroidRuntime(1848): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
08-10 10:30:19.049: E/AndroidRuntime(1848):     at com.example.cube.InputActivity.onCreate(InputActivity.java:33)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.Activity.performCreate(Activity.java:5937)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-10 10:30:19.049: E/AndroidRuntime(1848):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
08-10 10:30:19.049: E/AndroidRuntime(1848):     ... 10 more

Any suggestion?

alann-maulana commented 9 years ago

Hi @agungR

First you need to extends your activity class that used to scan beacon to CBActivity class. Read our complete tutorials here. Thanks.

Regards.

agungR commented 9 years ago
package com.example.cube;

import com.eyro.cubeacon.CBActivity;
import com.eyro.cubeacon.CBUser;

import com.eyro.cubeacon.CBUser.Callback;

import android.content.Intent;
import android.os.Bundle;

import android.util.Log;
import android.view.View;

import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class InputActivity extends CBActivity  {
   Button b1,b2;
   EditText ed1,ed2;

   public static String name;
   public static String email;

   TextView tampil_nama,tampil_email;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_input);

      ed1=(EditText)findViewById(R.id.name);
      ed2=(EditText)findViewById(R.id.email);

      b1=(Button)findViewById(R.id.button);
      b2=(Button)findViewById(R.id.button2);
      b1.setOnClickListener(new login());
      b2.setOnClickListener(new cancel()); 

      tampil_nama = (TextView) findViewById (R.id.viewName);
      tampil_email = (TextView) findViewById (R.id.viewEmail);

   }
//next page      
   class login implements Button.OnClickListener {
        public void onClick (View v) {

     name = tampil_nama.getText().toString();
     email = tampil_email.getText().toString();
     tampil_nama.setText(ed1.getText());
     tampil_email.setText(ed2.getText());

     //meta user         
     CBUser.setUserData(name, email);
     CBUser.getName();
     CBUser.getEmail();
     CBUser.currentUser().sendDataInBackground(new Callback() {

        @Override
        public void onCompleted(Exception v){

            if (v == null) {
                 Intent i = new Intent(InputActivity.this,
                         SplashActivity.class);
                 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                 startActivity(i);
             } else {
                 Log.v("InputActivity", v.getMessage());
             }

        }

    });

        }
    }

//cancel   
   class cancel implements Button.OnClickListener {
        public void onClick (View v) {

            ed1.setText("");
            ed2.setText("");
    }
    }

}

hi @alann-maulana this my inputActivity i still can't upload the #fullname data into cloud, anything wrong with my code?

alann-maulana commented 9 years ago

Hi @agungR ,

We are sorry for the inconvenience, we will check it soon and update or fix this issue.

Thanks and regards.