I followed a guide to enter the in app purchase and unlock all features. The procedure to purchase works well.
I explain what I do: I added a check in my database, which counts the number of records in a table, if the number is> = 1, I open an activity for purchase in the app. Once purchased, through the method getPurchases, control the purchase, if it was done I open the activity, otherwise I open the activity for purchase. I created this code peril control but I get error:
08-11 18:08:18.120: W/ContextImpl(19293): Implicit intents with startService
are not safe: Intent {
act=com.android.vending.billing.InAppBillingService.BIND }
android.content.ContextWrapper.bindService:529
main.Elenco_F_Fragment.Controlla_record_per_acquisto:243
main.Elenco_F_Fragment.access$9:233
this is the row 243:
final boolean blnBind = getActivity().bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
this is the code for the control
private void Controlla_record_per_acquisto(){
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
String controllo = "SELECT COUNT(_id) FROM tbf";
Cursor c = db.rawQuery(controllo, null);
while (c.moveToNext()){
int numero_id = c.getInt(0);
if(numero_id >=1){
// Bind Service
final boolean blnBind = getActivity().bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
if (!blnBind) return;
if (mService == null) return;
Bundle ownedItems;
try {
ownedItems = mService.getPurchases(3, getActivity().getPackageName(), "inapp", null);
Intent intent = null;
intent = new Intent(getActivity(), Crea_e.class);
startActivity(intent);
} catch (RemoteException e) {
e.printStackTrace();
Toast.makeText(context, "getPurchases - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getPurchases() - fail!");
return;
}
int response = ownedItems.getInt("RESPONSE_CODE");
Toast.makeText(context, "getPurchases() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getPurchases() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) return;
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
Log.i(tag, "getPurchases() - \"INAPP_PURCHASE_ITEM_LIST\" return " + ownedSkus.toString());
Log.i(tag, "getPurchases() - \"INAPP_PURCHASE_DATA_LIST\" return " + purchaseDataList.toString());
Log.i(tag, "getPurchases() - \"INAPP_DATA_SIGNATURE\" return " + (signatureList != null ? signatureList.toString() : "null"));
Log.i(tag, "getPurchases() - \"INAPP_CONTINUATION_TOKEN\" return " + (continuationToken != null ? continuationToken : "null"));
}else {
Intent intent = null;
intent = new Intent(getActivity(), InAppBillingActivity.class);
startActivity(intent);
}
c.close();
db.close();
}
}
EDIT--------------------------------------------
private void Controlla_record_per_acquisto(){
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
String controllo = "SELECT COUNT(_id) FROM FTB";
Cursor c = db.rawQuery(controllo, null);
while (c.moveToNext()){
int numero_id = c.getInt(0);
if(numero_id >=1){
Intent intent = null;
intent = new Intent(getActivity(), InAppBillingActivity.class);
startActivity(intent);
}else {
Intent intent = null;
intent = new Intent(getActivity(), Cure.class);
startActivity(intent);
}
c.close();
db.close();
}
}
I would suggest you to use the new Billing system, with the IabHelper class there you can do what you have described above both async/sync without the needs for "extra" code really.
http://developer.android.com/training/in-app-billing/preparing-iab-app.html
Related
I'm making a SMS app, I have a contact list, I want to be able to tap on contact and pass that contact number into new activity so that I could send message to that contact number,
I know How can we pass Value of clicked List item to new Activity, but somehow I'm not able to use that Intent.putExtra method in my scenario.
private void getContactList() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if ((cur != null ? cur.getCount() : 0) > 0) {
while (cur != null && cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
if (cur.getInt(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] {
id
},
null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.i(TAG, "Name: " + name);
Log.i(TAG, "Phone Number: " + phoneNo);
}
pCur.close();
}
}
}
if (cur != null) {
cur.close();
}
}
You can use a Bundle to do this. You mentioned that you somehow couldn't call putExtra on your intent, make sure it isn't a typo as it is supposed to be putExtras, also make sure you are creating your intent correctly as shown below.
In the activity that will send the data:
Intent intent = new Intent(getActivity(), SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putString("phoneNo", phoneNo);
intent.putExtras(bundle);
startActivity(intent);
Then on the receiving activity:
Bundle bundle = getIntent().getExtras();
String number = bundle.getString("phoneNo");
public void action(View view){
Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
if(intent!=null) //here is my problem, it return true always
{startActivity(intent);}
else{k++;
Context context = getApplicationContext();
CharSequence mesajText = "Failed To Open! " + k;
int duration = 3;
Toast screen_message = Toast.makeText(context,mesajText,duration);
screen_message.show();
}
}
How can I verify if my 'intent' have a valid activity(works when it's open) or an invalid one(app crash when it's open)?
if(intent!=null) will always evaluate to true because your are initializing intent just before the if condition. If you want to check if Intent can be handled then use resolveActivity as follows:
Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else{
k++;
CharSequence mesajText = "Failed To Open! " + k;
int duration = 3;
Toast screen_message = Toast.makeText(this,mesajText,duration);
screen_message.show();
}
Could someone please help with the following issue?
I am in the process of creating an app where the client will sign on the device and then it will submit the form to an email address. The form works and data is being submitted correctly, but i am having trouble in getting the signature to display initially before the form is being submitted.
So here is what I have so far.
For my ExampleDBHelper.java class:
public static final String PERSON_FAULT_REPORTED = "faultreport";
public static final String PERSON_TECH_COMMENT = "techreport";
public static final String PERSON_SIGNATURE = "signature";
public static final String PERSON_JOB_NUMBER = "jobnumber";
public ExampleDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(
"CREATE TABLE " + PERSON_TABLE_NAME +
"(" + PERSON_COLUMN_ID + " INTEGER PRIMARY KEY, " +
PERSON_FAULT_REPORTED + " TEXT, " +
PERSON_TECH_COMMENT + " TEXT, " +
PERSON_SIGNATURE + " BLOB, " +
PERSON_JOB_NUMBER + " INTEGER)"
);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + PERSON_TABLE_NAME);
onCreate(db);
}
public boolean insertPerson(String faultreport,
String techreport,
String signature,
int jobnumber) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(PERSON_FAULT_REPORTED, faultreport);
contentValues.put(PERSON_TECH_COMMENT, techreport);
contentValues.put(PERSON_SIGNATURE, signature);
contentValues.put(PERSON_JOB_NUMBER, jobnumber);
db.insert(PERSON_TABLE_NAME, null, contentValues);
return true;
}
public int numberOfRows() {
SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, PERSON_TABLE_NAME);
return numRows;
}
public boolean updatePerson(String faultreport,
String techreport,
String signature,
int jobnumber) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(PERSON_FAULT_REPORTED, faultreport);
contentValues.put(PERSON_TECH_COMMENT, techreport);
contentValues.put(PERSON_SIGNATURE, signature);
contentValues.put(PERSON_JOB_NUMBER, jobnumber);
db.update(PERSON_TABLE_NAME, contentValues, PERSON_COLUMN_ID + " = ? ", new String[]{Integer.toString(id)});
return true;
}
public Integer deletePerson(Integer id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(PERSON_TABLE_NAME,
PERSON_COLUMN_ID + " = ? ",
new String[]{Integer.toString(id)});
}
public Cursor getPerson(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("SELECT * FROM " + PERSON_TABLE_NAME + " WHERE " +
PERSON_COLUMN_ID + "=?", new String[]{Integer.toString(id)});
return res;
}
public Cursor getAllPersons() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("SELECT * FROM " + PERSON_TABLE_NAME, null);
return res;
}
Then in my MainActivity.java class:
faultReported = (EditText) findViewById(R.id.EFaultReported);
techComment = (EditText) findViewById(R.id.ETehComment);
sigImage = (ImageView) findViewById(R.id.custimagesig);
jobEditText = (EditText) findViewById(R.id.editCustComment);
SimpleDateFormat calld = new SimpleDateFormat( "yyMMddHHmm" );
jobEditText.setText( calld.format( new Date() ));
saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(this);
buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout);
editButton = (Button) findViewById(R.id.editButton);
editButton.setOnClickListener(this);
deleteButton = (Button) findViewById(R.id.deleteButton);
deleteButton.setOnClickListener(this);
dbHelper = new ExampleDBHelper(this);
if (personID > 0) {
saveButton.setVisibility(View.GONE);
buttonLayout.setVisibility(View.VISIBLE);
Cursor rs = dbHelper.getPerson(personID);
rs.moveToFirst();
String faultrep = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_FAULT_REPORTED));
String techcom = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_TECH_COMMENT));
String custsign = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_SIGNATURE));
int personAge = rs.getInt(rs.getColumnIndex(ExampleDBHelper.PERSON_JOB_NUMBER));
if (!rs.isClosed()) {
rs.close();
}
faultReported.setText((CharSequence) faultrep);
faultReported.setFocusable(false);
faultReported.setClickable(false);
techComment.setText((CharSequence) techcom);
techComment.setFocusable(false);
techComment.setClickable(false);
sigImage.setImageDrawable(Drawable.createFromPath(custsign));
sigImage.setFocusable(false);
sigImage.setClickable(false);
jobEditText.setText((CharSequence) (personAge + ""));
jobEditText.setFocusable(false);
jobEditText.setClickable(false);
}
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.saveButton:
persistPerson();
return;
case R.id.editButton:
saveButton.setVisibility(View.VISIBLE);
buttonLayout.setVisibility(View.GONE);
faultReported.setEnabled(true);
faultReported.setFocusableInTouchMode(true);
faultReported.setClickable(true);
techComment.setEnabled(true);
techComment.setFocusableInTouchMode(true);
techComment.setClickable(true);
sigImage.setEnabled(true);
sigImage.setFocusableInTouchMode(true);
sigImage.setClickable(true);
jobEditText.setEnabled(true);
jobEditText.setFocusableInTouchMode(true);
jobEditText.setClickable(true);
return;
case R.id.deleteButton:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.deletePerson)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dbHelper.deletePerson(personID);
Toast.makeText(getApplicationContext(), "Deleted Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), FragmentJob.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog d = builder.create();
d.setTitle("Delete Form?");
d.show();
return;
}
}
public void persistPerson() {
if (personID > 0) {
if (dbHelper.updatePerson(personID,
faultReported.getText().toString(),
techComment.getText().toString(),
sigImage.getDrawable().toString(),
Integer.parseInt(jobEditText.getText().toString()))) {
Toast.makeText(getApplicationContext(), "Form Update Successful", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), FragmentJob.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Form Update Failed", Toast.LENGTH_SHORT).show();
}
} else {
if (dbHelper.insertPerson(
faultReported.getText().toString(),
techComment.getText().toString(),
sigImage.getDrawable().toString(),
Integer.parseInt(jobEditText.getText().toString()))) {
Toast.makeText(getApplicationContext(), "Form Inserted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Could not Insert Form", Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(), FragmentJob.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
Then finally the method for creating the signature:
b1 = (Button) findViewById(R.id.SignatureButton);
signImage = (ImageView) findViewById(R.id.custimagesig);
b1.setOnClickListener(onButtonClick);
Button.OnClickListener onButtonClick = new Button.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(CreateOrEditActivity.this, CaptureSignature.class);
startActivityForResult(i, 0);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == 1) {
Bitmap b = BitmapFactory.decodeByteArray(
data.getByteArrayExtra("byteArray"), 0,
data.getByteArrayExtra("byteArray").length);
signImage.setImageBitmap(Bitmap.createScaledBitmap(b, 625, 625, false));
}
Not sure if if the CaputureSignature.class is needed? This is only to bring up the "Sinature Pad" for the customer to sign on.
I am not sure what i am doing wrong here? Could some one please help?
Please let me know if you require more information.
Thanks Guys :-)
Actually you are trying to get String of image but you saved a byte as blob so in place of String custsign = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_SIGNATURE)); you should try byte[] custsign = rs.getBlob(rs.getColumnIndex(ExampleDBHelper.PERSON_SIGNATURE)); and parse byte[] in bitmap and set to imageView.
Edit
byte[] custsign = rs.getBlob(rs.getColumnIndex(ExampleDBHelper.PERSON_SIGNATURE));
if(custsign.length>0){
Bitmap bitmap = BitmapFactory.decodeByteArray(custsign, 0, custsign.length);
imageView.setImageBitmap(bitmap);
}else{
Toast.makeText(this,"Image is Not Fetching ",Toast.LENGTH_LONG).show();
}
I have a listView in Activity A as shown below. All the values and name were actually returned from Activity C to B then only A.
When the first list is clicked, it should display text Project and value 3 on editText B. But it displays Medical which was actually getting from the last list.
After I change the value from 3 to 43 and return to A, the name changed. What should I do so that the name will remain the same ?
Activity A
ArrayAdapter<String> adapter;
ArrayList<String> m_listItems = new ArrayList<String>();
int mClickedPosition;
adapter=new ArrayAdapter<String (getActivity(),R.layout.claims,R.id.textView1,m_listItems);
listV = (ListView) claims.findViewById(R.id.listView1);
listV.setOnItemClickListener(new AdapterView.OnItemClickListener() { // if list clicked
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
mClickedPosition = position;
if (name.equals("Project")) {
String temp[] = m_listItems.get(position).split("\\s\\s+");
result = temp[temp.length - 1].trim();
result = result.replace("RM","");
Intent intent = new Intent(Claims1.this.getActivity(), Project1.class);
intent.putExtra("bitmap", true); // image
intent.putExtra("name", name);
intent.putExtra("result", result);
startActivityForResult(intent, 0);
Log.e("RESULT", "Result= " + result);
}
else if(name.equals("Medical"))
{
String temp[] = m_listItems.get(position).split("\\s\\s+");
result = temp[temp.length - 1].trim();
result = result.replace("RM","");
Intent intent = new Intent(Claims1.this.getActivity(), Medical.class);
intent.putExtra("bitmap", true);
intent.putExtra("name", name);
intent.putExtra("result", result);
startActivityForResult(intent, 1);
}
}
});
return claims;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0: // for Project
result = data.getStringExtra("text"); //get from B
name = data.getStringExtra("a");
description = data.getStringExtra("c");
as = Long.parseLong(result);
Log.d("FIRST", "result:" + result);
Text = " " + name + " " + "RM" + result + "";
if (mClickedPosition == -1) { // if is icon button clicked
m_listItems.add(Text);
} else {
m_listItems.set(mClickedPosition, Text);
}
adapter.notifyDataSetChanged();
listV.setAdapter(adapter);
break;
case 1: // for Medical
result = data.getStringExtra("text");
name = data.getStringExtra("a");
description = data.getStringExtra("c");
as = Long.parseLong(result);
Log.d("FIRST", "result:" + result);
Text = " " + name + " " + "RM" + result + "";
// m_listItems.clear();
if (mClickedPosition==-1)
{
m_listItems.add(Text);
}
else
{
m_listItems.set(mClickedPosition, Text);
}
adapter.notifyDataSetChanged();
listV.setAdapter(adapter);
break;
Activity B (Project1)
if(getIntent().getExtras()!=null) { //if has value pass from A
final String Amount = getIntent().getExtras().getString("result");
final String description1 = getIntent().getExtras().getString("description");
txt1.setText(description1);
txt.setText(Amount);
}
b.setOnClickListener(new View.OnClickListener() { // return to A
public void onClick(View arg0) {
Intent returnIntent = new Intent();
a = "Project";
text = txt.getText().toString(); // amount
returnIntent.putExtra("text", text);
returnIntent.putExtra("a", a);
returnIntent.putExtra("c", c); // receive from Activity C
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
viewImage.setImageBitmap(Global.img); // receive from C
}
Noted that the result in Activity A represents value 3,5 while name represents project and Medical. How can I fix this ? Please help.
From what I understood, your variable name in Activity A contains previously resulted value (from Activity B) and not from row you have clicked on listview i.e. "Medical" value you previously got from Activity B which held by variable name and on your listview click event you have checks the if name is "Medical" or "Project" (and in this case it is "Medical" and hence Medical activity is started).
One solution is to get the value("Project/Medical") from listview.
Try this code.
Activity A
mClickedPosition = position;
String temp[] = m_listItems.get(position).split("\\s\\s+");
result = temp[temp.length - 1].trim();
result = result.replace("RM","");
name = temp[1].trim();
if (name.equals("Project")) {
Intent intent = new Intent(Claims1.this.getActivity(), Project1.class);
intent.putExtra("bitmap", true);
intent.putExtra("name", name);
intent.putExtra("result", result);
startActivityForResult(intent, 0);
Log.e("RESULT", "Result= " + result);
}
else if(name.equals("Medical"))
{
Intent intent = new Intent(Claims1.this.getActivity(), Medical.class);
intent.putExtra("bitmap", true);
intent.putExtra("name", name);
intent.putExtra("result", result);
startActivityForResult(intent, 1);
}
My application consists of a listview that contains data retrieved from a database. The database has columns : cognome, nome, ruolo, telefono.
When I click on an item, a dialog containing 2 buttons is opened : call and sms.
I would like that when I click the button call, I hand the call to the number corresponding to the line.
The problem is when I click the button, there is an error message : >connection problem or invalid mmi code.
My main is below.
public class ListaContatti extends ListActivity {
PersonaManager manager;
List<Persona> lista = new ArrayList<>();
TextView visualizza;
private PersonaHelper mPersonaHelper;
private static final String TAG = "MyActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_contatti);
mPersonaHelper = new PersonaHelper(this);
manager = new PersonaManager(this);
manager.open();
visualizzaLista();
//stampaCose();
manager.close();
final ArrayAdapter<Persona> adapter = new ArrayAdapter<>(this, R.layout.row, R.id.textViewList, lista.toArray(new Persona[0]));
setListAdapter(adapter);
}
protected void onListItemClick(ListView list, View v, int position, long id) {
final Dialog dialog = new Dialog(this);
dialog.setTitle("Continua con ");
dialog.setContentView(R.layout.custom_dialog_layout);
TextView view = (TextView)findViewById(R.id.textViewList);
final Button call = (Button) dialog.findViewById(R.id.call);
Button sms = (Button) dialog.findViewById(R.id.sms);
//Button social = (Button) dialog.findViewById(R.id.social);
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
SQLiteDatabase db = mPersonaHelper.getReadableDatabase();
final Cursor cursor = db.rawQuery("SELECT TELEFONO FROM contatti", null);
call.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
cursor.moveToFirst();
final int numeroTelefono = cursor.getColumnIndex(PersonaHelper.TELEFONO);
while (cursor.isAfterLast() == false) {
//view.append("n" + cursor.getString(numeroTelefono));
cursor.moveToNext();
}
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + numeroTelefono ));
//callIntent.setData(Uri.parse("tel" + db.query("contatti", new String[]{"TELEFONO"}, null, null, null, null, null)));
startActivity(callIntent);
}
});
sms.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
dialog.show();
}
private void stampaCose() {
StringBuilder sb = new StringBuilder();
for (Persona attuale : lista) {
sb.append(attuale.toString());
sb.append("\n");
}
}
private void visualizzaLista() {
Cursor cursor = manager.getPersoneSalvate();
lista.clear();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
String cognome = cursor.getString(cursor.getColumnIndex(PersonaHelper.COGNOME));
String nome = cursor.getString(cursor.getColumnIndex(PersonaHelper.NOME));
String ruolo = cursor.getString(cursor.getColumnIndex(PersonaHelper.RUOLO));
String numero = cursor.getString(cursor.getColumnIndex(PersonaHelper.TELEFONO));
//String mail = cursor.getString(cursor.getColumnIndex(PersonaHelper.COLUMN_MAIL));
// String descrizione = cursor.getString(cursor.getColumnIndex(PersonaHelper.COLUMN_DESCRIZIONE));
//lista.add(new Persona(cognome,nome, numero, mail)); // al posto dei due null mettere mail e descrizione
lista.add(new Persona(cognome, nome, ruolo, numero));
cursor.moveToNext();
}
}
//monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
}