Like what the title says and i want to display the phone number to a textView then masking the last 4 digits if possible, but i can't run it properly, the application suddenly stops... here is a sample/reference code of what i want to do. If using toast it displays the number but when am using intent my code does not work runtime error
Sender(2nd Activity)
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class MyCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Intent a = new Intent(context,MainActivity.class);
a.putExtra("key", incomingNumber);
context.startActivity(a);
}
main activity
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv1,tv2;
String gotBread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
tv1.setSelected(true);
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
tv2.setText(gotBread);
}
public void initialize() {
// TODO Auto-generated method stub
tv1 = (TextView) this.findViewById(R.id.tV1);
tv2 = (TextView) this.findViewById(R.id.tV2);
}
}
here is my logcat hope it helps...
08-18 02:50:10.121: D/AndroidRuntime(1306): Shutting down VM 08-18 02:50:10.121: W/dalvikvm(1306): threadid=1: thread exiting with uncaught exception (group=0xb2a3fba8) 08-18 02:50:10.131: E/AndroidRuntime(1306): FATAL EXCEPTION: main 08-18 02:50:10.131: E/AndroidRuntime(1306): Process: com.example.detectincomingcall, PID: 1306 08-18 02:50:10.131: E/AndroidRuntime(1306): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.detectincomingcall/com.example.detectincomingcall.MainActivity}: java.lang.NullPointerException 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread.access$800(ActivityThread.java:135) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.os.Handler.dispatchMessage(Handler.java:102) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.os.Looper.loop(Looper.java:136) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread.main(ActivityThread.java:5017) 08-18 02:50:10.131: E/AndroidRuntime(1306): at java.lang.reflect.Method.invokeNative(Native Method) 08-18 02:50:10.131: E/AndroidRuntime(1306): at java.lang.reflect.Method.invoke(Method.java:515) 08-18 02:50:10.131: E/AndroidRuntime(1306): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 08-18 02:50:10.131: E/AndroidRuntime(1306): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 08-18 02:50:10.131: E/AndroidRuntime(1306): at dalvik.system.NativeStart.main(Native Method) 08-18 02:50:10.131: E/AndroidRuntime(1306): Caused by: java.lang.NullPointerException 08-18 02:50:10.131: E/AndroidRuntime(1306): at com.example.detectincomingcall.MainActivity.onCreate(MainActivity.java:21) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.Activity.performCreate(Activity.java:5231) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 08-18 02:50:10.131: E/AndroidRuntime(1306): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 08-18 02:50:10.131: E/AndroidRuntime(1306): ... 11 more
0 comments:
Post a Comment