I am making an app that tells you your phone number in the notification bar. I tested it in AVD but I get 'The application Phone Number (process com.CurlyFries.phonenumber) has stopped unexpectedly. Please try again.' when ever I launch the app. This is my code:
package com.CurlyFries.phonenumber;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
public class MainActivity extends Activity implements onclickListener {
public String getMyPhoneNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
static final int uniqueID = 16573892;
static boolean note = true;
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button stat = (Button)findViewById(R.id.menu_settings);
stat.setonclickListener(this);
}
public void onclick(View v) {
// TODO Auto-generated method stub
if (note == true){
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String title = getMyPhoneNumber();
Notification n = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
n.setLatestEventInfo(this, title, null, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
note = false;
}
if (note == false);{
nm.cancel(uniqueID);
note = true;
}
}
}
Any help will be appreciated.
Thanks in advance

New Topic/Question
Reply


MultiQuote









|