Insert data from parse into sqllite database - java

I am trying to get notification content and store it into the database automatically, as soon as the notification is released from parse.com the data should be saved in the database whether the user clicks to view the notification or not.
This is what i have tried so far but still not working. It only save the content into a database when a user clicks on the notification.
Application.java
public class Application extends android.app.Application{
public Application() {
}
#SuppressWarnings("deprecation")
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "YwWVJ1IdukAXQx6WqksoRlA94k1OoJ6cHqdgsInHaTN", "fCh5pWNiSaHaFtuACufgs9va6wq31pte8nuaiCAG6Nb");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, Notification.class);
}
}
FireBackground.java
public class FireBackground extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, Notification.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Notification.java
public class Notification extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ParseAnalytics.trackAppOpened(getIntent());
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String message="";
SQLiteDatabase db;
db = openOrCreateDatabase(
"notification.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
//CREATE TABLES AND INSERT MESSAGES INTO THE TABLES
String CREATE_TABLE_NOTICES = "CREATE TABLE IF NOT EXISTS notices ("
+ "ID INTEGER primary key AUTOINCREMENT,"
+ "NOTIFICATIONS TEXT)";
db.execSQL(CREATE_TABLE_NOTICES);
if(extras !=null){
String jsonData = extras.getString("com.parse.Data");
try{
JSONObject notification = new JSONObject(jsonData);
message = notification.getString("alert");
String sql =
"INSERT or replace INTO notices (NOTIFICATIONS) "
+ "VALUES('" + message + "')";
db.execSQL(sql);
}
catch(JSONException e){
Toast.makeText(getApplicationContext(), "Something went wrong with the notification", Toast.LENGTH_SHORT).show();
}
}
}
android manifest file
<application
android:name="com.parse.starter.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
<activity
android:name="com.parse.starter.Notification"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name=".HomeActivity"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: If you change the package name of this sample app,
change "com.parse.starter" in the lines
below to match the new package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
I would be grateful if anyone would direct me to use the correct method. Thanks

Your code for saving the notification data to your local database runs in the Activity. And the activity is started when the notification is opened, hence the nameonPushOpen. Hence, move the code that saves to the database to FireBackground in a method like onPushRecieved(...)

You should override onPushReceive method in your BroadcastReceiver and than get necessary data
from intent.
Here is my example with retreiving jsonData:
#Override
protected void onPushReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
DBServiceFlow.save(intent);
} catch (JSONException | ParseException e) {
Log.e(TAG, "", e);
}
}
Then you could implement your own Service with background thread to save your data. For example you could just use IntentService
public class DBService extends IntentService {
#Override
public void onHandleIntent(Intent intent) {
if (intent.getAction() == "com.tac.save_notification") {
//parse your json here...
DBHelper.save(...);
}
}
}
PS: never work with DB in main thread. (like you show in your Notification Activity)

Related

How to read multiple payload from nfc tags and store the payloads into an arraylist?

Hi Stackers I still new in coding and need some help. Now I have two NFC tags and both tags is storing with different Geo coordinates(longitude, latitude). Currently, I able to read the payload from the NFC tags. What I want is to store the payloads from both of the NFC tags into an arraylist. When I read the first tag it does stored the payload into arraylist, but when read second tag the payload will overwritten the previous payload.
Android Manifest:
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".arraylist"></activity>
<activity
android:name=".MainActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:scheme="geo" />
</intent-filter>
</activity>
</application>
MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) {
Toast.makeText(this, "nfc not supported", Toast.LENGTH_SHORT).show();
finish();
return;
}
if (!nfcAdapter.isEnabled()) {
startActivity(new Intent("android.settings.NFC_SETTINGS"));
Toast.makeText(this, "nfc not yet open", Toast.LENGTH_SHORT).show();
}
mPendingIntent = PendingIntent.getActivity(this,0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0 );
}
private void readIntent(Intent intent){
list = new ArrayList<>();
Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
for(int i=0; i<parcelables.length; i ++){
NdefMessage message =(NdefMessage)parcelables[i];
NdefRecord[] records = message.getRecords();
for(int j=0; j<records.length; j++){
NdefRecord record = records[j];
byte[] original = record.getPayload();
byte[] value = Arrays.copyOfRange(original,0,original.length);
String payload = new String(value);
if(list != null){
list.add(payload);
System.out.println(list);
}
}
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
readIntent(intent);
}
#Override
protected void onResume() {
super.onResume();
nfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
#Override
protected void onPause() {
super.onPause();
nfcAdapter.disableForegroundDispatch(this);
}
Here is my output:
I/System.out: [geo:1.523534,103.633690]
But my expectation output is:
[geo:1.523534, 103.633690, geo:1.5364496, 103.656321]
So how can achieve that second tag payload will not overwritten the previous payload?
The problem this time is that you are not creating a new instance of a Fragment like your were in your previous similar question, you are creating a new arraylist every time a card is read and thus de-referencing the first list object for it to be deleted by the garbage collection.
This is a classic variable initialisation issue.
readIntent is called every time a card is read.
So remove the first line of `readIntent where you create a new list.
e.g.
private void readIntent(Intent intent){
Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
....
Then in your class definition initialise the arraylist once only.
e.g.
public class MainActivity extends AppCompatActivity {
private ArrayList<String> list = new ArrayList();

Show login activity only once and on next start main activity

I want to open login_activity on first time entering app, and then on the second entering to app open main_activity.
I create something but it wont work. so I wonder what I'm doing wrong?
this is my LoginActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
userName = (EditText) findViewById(R.id.username);
userPhone = (EditText) findViewById(R.id.userPhone);
loginBtn = (Button) findViewById(R.id.buttonLogin);
dbHandler = new LogsDBHandler(this);
loginBtn.setOnClickListener(this);
setTitle("AMS - biomasa | prijava");
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
if (pref.getBoolean("activity_executed", false)) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
SharedPreferences.Editor edt = pref.edit();
edt.putBoolean("activity_executed", true);
edt.commit();
}
}
public void insert() {
User user = new User (
userName.getText().toString(),
userPhone.getText().toString());
dbHandler.addUser(user);
Toast.makeText(getBaseContext(), "Prijavljeni ste!", Toast.LENGTH_SHORT).show();
}
#Override
public void onClick(View v) {
if (v == loginBtn && validateUser()) {
insert();
}
}
In main activity i have only image and two buttons.
And in manifest I add launcher to main and login activity.
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What am I doing wrong here?
Create one start-up activity call it as SplashActivity
public class SplashActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// decide here whether to navigate to Login or Main Activity
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
if (pref.getBoolean("activity_executed", false)) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
}
}
In your LoginActivity simply set activity_executed to true
public void insert() {
User user = new User (
userName.getText().toString(),
userPhone.getText().toString());
dbHandler.addUser(user);
Toast.makeText(getBaseContext(), "Prijavljeni ste!", Toast.LENGTH_SHORT).show();
//set activity_executed inside insert() method.
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
SharedPreferences.Editor edt = pref.edit();
edt.putBoolean("activity_executed", true);
edt.commit();
}
change manifest as below-
<activity android:name=".MainActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you can change launcher activity as main activity.so that when you open the application it is starting from main activity there you can check whether he is logged in or not.if he is not logged in you must navigate him to login activity or else you just do it as it is.Following is manifest file..
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"></activity>
You should add another empty activity (with no UI) that loads before anything.
Then use SharedPreferences to store some value. Thus if the user has already opened your app once, the value is stored. And then use a condition to check this value. If its the value you saved skip login_activity and direct to main_activity else direct to login_activity.
Problem about the line
if (pref.getBoolean("activity_executed", false)) {
You can Implement this method to call inside if(appIsLoggedIn)
public boolean appIsLoggedIn(){
return pref.getBoolean("activity_executed", false);
}

Android - Try to send fake sms to myself without mobile network usage

I'm trying to send message to my phone with this app, without using network usage, but my code doesn't work. I followed some tutorial, check android dev and I haven't found anything (in my logcat I don't have error). Could you help me to find out my problem.
My information about compilation, compiler and phone:
Android Studio 1.0.1
API 19 Android 4.4.4 (kitkat)
Build 19
Android phone version 4.4.4
Manifest:
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Function of my main activity:
Context context;
String sender;
String body;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get current context
context = this;
//App started
Toast.makeText(context, "Started", Toast.LENGTH_LONG).show();
CheckApp();
}
private void CheckApp() {
sender = "1234";
body = "Android sms body";
//Get my package name
final String myPackageName = getPackageName();
//Check if my app is the default sms app
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
//Get default sms app
String defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);
//Change the default sms app to my app
Intent intent = new Intent( Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName());
startActivity(intent);
//Write the sms
WriteSms(body, sender);
//Change my sms app to the last default sms app
Intent intent2 = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent2.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, defaultSmsApp);
startActivity(intent2);
}
else{
//Write the sms
WriteSms(body, sender);
}
}
//Write the sms
private void WriteSms(String message, String phoneNumber) {
//Put content values
ContentValues values = new ContentValues();
values.put(Telephony.Sms.ADDRESS, phoneNumber);
values.put(Telephony.Sms.DATE, System.currentTimeMillis());
values.put(Telephony.Sms.BODY, message);
//Insert the message
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
context.getContentResolver().insert(Telephony.Sms.Sent.CONTENT_URI, values);
}
else {
context.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
}
Well, this is what i wanna do but with my own app and not with the app Fake Text Message that downloaded to the play store.
Make the fake message and what should i see on my default sms app:
With the help from Mike M. I finally finished my program. So, this is the code that you must add to your app to be able to send sms without using network:
Manifest:
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- BroadcastReceiver that listens for incoming SMS messages -->
<receiver android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver android:name=".MmsReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<!-- My activity -->
<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>
<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".ComposeSmsActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<!-- Service that delivers messages from the phone "quick response" -->
<service android:name=".HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
</application>
Main Activity:
Context context;
Button button;
String sender,body,defaultSmsApp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get current context
context = this;
//Set composant
button = (Button) findViewById(R.id.button);
//Get default sms app
defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);
//Set the number and the body for the sms
sender = "0042";
body = "Android fake message";
//Button to write to the default sms app
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Get the package name and check if my app is not the default sms app
final String myPackageName = getPackageName();
if (!Telephony.Sms.getDefaultSmsPackage(context).equals(myPackageName)) {
//Change the default sms app to my app
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName());
startActivityForResult(intent, 1);
}
}
});
}
//Write to the default sms app
private void WriteSms(String message, String phoneNumber) {
//Put content values
ContentValues values = new ContentValues();
values.put(Telephony.Sms.ADDRESS, phoneNumber);
values.put(Telephony.Sms.DATE, System.currentTimeMillis());
values.put(Telephony.Sms.BODY, message);
//Insert the message
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
context.getContentResolver().insert(Telephony.Sms.Sent.CONTENT_URI, values);
}
else {
context.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
//Change my sms app to the last default sms
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, defaultSmsApp);
context.startActivity(intent);
}
//Get result from default sms dialog pops up
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
final String myPackageName = getPackageName();
if (Telephony.Sms.getDefaultSmsPackage(context).equals(myPackageName)) {
//Write to the default sms app
WriteSms(body, sender);
}
}
}
}
As a result of adding things in your manifest you must add 4 classes: SmsReceiver, MmsReceiver, ComposeSmsActivity and HeadlessSmsSendService. You can let them empty as shown below.
SmsReceiver:
public class SmsReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
}
}
MmsReceiver:
public class MmsReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
}
}
ComposeSmsActivity:
public class ComposeSmsActivity extends ActionBarActivity {
}
HeadlessSmsSendService:
public class HeadlessSmsSendService extends IntentService {
public HeadlessSmsSendService() {
super(HeadlessSmsSendService.class.getName());
}
#Override
protected void onHandleIntent(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
If you need more help to understand this program have a look there:
Youtube - DevBytes: Android 4.4 SMS APIs
Android developers - Getting Your SMS Apps Ready for KitKat
Possiblemobile - KitKat SMS and MMS supports

Android. Launch app from Dialer

This is what I have so far but nothing happens when I input this combination in dialer
public class DialReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, final Intent intent) {
if (intent.getAction().equals(android.content.Intent.ACTION_NEW_OUTGOING_CALL)) {
String phoneNumber = intent.getExtras().getString( android.content.Intent.EXTRA_PHONE_NUMBER );
if(phoneNumber.equals("*#588637#")) {
Intent intent1 = new Intent(context , Activity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.startActivity(intent1);
}
}
}
}
and in androidmanifest
<receiver
android:name=".receiver.DialReceiver"
android:exported="true"
android:process=":background"
tools:ignore="ExportedReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Try with these small changes..
String phoneNumber = intent.getExtras.getString("Intent.EXTRA_PHONE_NUMBER");
if(phoneNumber.equals("*#588637#")) {
//do your stuff
}
And do not forget to add this line in your Manifest.xml file
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
Also you may find these helpful..
http://android.programmerguru.com/simple-dialer-application/
http://tikuflower.blogspot.com/2011/12/android.html
Is the receiver getting the broadcast at all? If not, maybe you forgot to include the PROCESS_OUTGOING_CALLS permission.
Try This,
Add to this in manifest,
here host is 12456, so your secret code is *#*#123456#*#* (dial-in dialped)
<receiver android:name=".Dialer"> //here is your broadcast receiver class
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code"
android:host="123456"
/>
</intent-filter>
</receiver>
here is your Broadcast Receiver class :
class Dialer : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// Declare Here your launcher activity in Intent
var i : Intent = Intent(context, MainActivity::class.java)
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context!!.startActivity(i);
}
}
According to ridoy's 2nd link,
http://tikuflower.blogspot.com/2011/12/android.html
It should be
String phoneNumber = intent.getStringExtra("android.intent.extra.PHONE_NUMBER");
rather than
String phoneNumber = intent.getExtras.getString("Intent.EXTRA_PHONE_NUMBER");
That change works for me at least...

Intent not received by Broadcast Receiver

I'm trying to show a message when a user places a call using the standard android dialer.
I have the following code in my Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTestButtonListener();
Log.i(LOG_TAG, "Activity started...");
}
private void setTestButtonListener()
{
Button testButton = (Button)this.findViewById(R.id.testButton);
testButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Log.i(LOG_TAG, "Clicked on test...");
Toast.makeText(getApplicationContext(), (CharSequence)"You clicked on the test button" ,Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+150));
MainActivity.this.sendOrderedBroadcast(intent, null);
MainActivity.this.startActivity(intent);
Log.i(LOG_TAG, "intent broadcasted... I think... ");
}
});
}
Then in the BroadcastReceiver (well a class that derives from it):
public class OnMakingCallReceiver extends BroadcastReceiver
{
private static final String LOG_TAG = OnMakingCallReceiver.class.getSimpleName() + "_LOG";
#Override
public void onReceive(Context context,Intent intent)
{
Log.i(LOG_TAG, " got here!");
}
}
And then in the AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
<receiver android:name=".OnMakingCallReceiver" android:priority="999">
<intent-filter>
<action android:name="android.intent.action.CALL"/>
</intent-filter>
</receiver>
I click the test button and I see this output.
Clicked on test...
intent broadcasted... I think...
And thats all. I expected to see "got here!".
Any ideas why I don't?
Did you define the receiver in your AndroidManifest.xml?
Also, ACTION_CALL_BUTTON is sent when you click on something that goes directly to the dialer. Are you sure you're doing that.
I used this in AndroidManifest.xml and it works. I think the key thing is the intent NEW_OUTGOING_CALL in the intent-filter.
<receiver android:name=".OnMakingCallReceiver" android:exported="true" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.ACTION_CALL" />
</intent-filter>
</receiver>
Probably ACTION_CALL could be removed. Also this may need to be added to the manifest:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

Categories

Resources