I created a basic app to check whether broadcast is received when phone state is changed, but it is not working. I tried with making outgoing call and incoming calls too. I realized these are common issues with Vivo, Honor etc. Here is Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jss.servicetester">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ReceiverMe">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
</manifest>
And here is code for receiver:
package jss.servicetester;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
/**
* Created by DELL WORLD on 5/28/2017.
*/
public class ReceiverMe extends BroadcastReceiver {
String LOGTAG = "Receiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(LOGTAG, "action:" + intent.getAction());
}
}
Can anyone help me.
started working in oppo F3 after making some changes in battery options for application. Like Unfreeze app in background.
Related
I want to notify when power of the phone connects and disconnects by broadcast receiver.
but the problem is that it doesnt work when i define receiver in manifest, but it works well if i defineit dynamically.
This is my manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.batterymanager">
<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"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
</application>
</manifest>
And here is my Broadcast:
package com.example.batterymanager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class PowerConnectionReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
/*if (intent.getAction().equals("android.intent.action.ACTION_POWER_CONNECTED")) {
Toast.makeText(context, "Power Connected", Toast.LENGTH_SHORT).show();
} else if (intent.getAction().equals("android.intent.action.ACTION_POWER_DISCONNECTED")){
Toast.makeText(context, "Power Disconnected", Toast.LENGTH_SHORT).show();
}*/
Toast.makeText(context, "" + intent.getAction(), Toast.LENGTH_SHORT).show();
Log.i("HUU", intent.getAction());
}
}
I dont know why it doesnt work! ):
New android limitations:
As part of the Android 8.0 (API level 26) Background Execution Limits,
apps that target the API level 26 or higher can no longer register
broadcast receivers for implicit broadcasts in their manifest.
However, several broadcasts are currently exempted from these
limitations. Apps can continue to register listeners for the following
broadcasts, no matter what API level the apps target.
https://developer.android.com/guide/components/broadcast-exceptions
I am trying to use gcm to push notifications on android devices. So far I have registered with gcm and sent my back-end the necessary information to make a post request to the gcm severs which builds a 200 response. All the steps have come together except the client side receiving the message. I don't get the message. Displayed here is my gcm listener class:
import com.google.android.gms.gcm.GcmListenerService;
public class MyGcmListenerService extends GcmListenerService {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
private static final String TAG = "MyGcmListenerService";
#Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
sendNotification(from,message);
}
private void sendNotification(String title, String body) {
Context context = getBaseContext();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title)
.setContentText(body);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.google.android.c2dm.permission.RECEIVE"/>
<permission android:name="com.example.caesar.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.caesar.gcm.permission.C2D_MESSAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<recieve android:name = ".GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.example.caesar.gcm" />
</intent-filter>
</recieve>
</application>
// new manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.google.android.c2dm.permission.RECEIVE"/>
<permission android:name="com.example.caesar.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.caesar.gcm.permission.C2D_MESSAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<reciever
android:name = "com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.example.caesar.gcm" />
</intent-filter>
</reciever>
<service
android:name="com.example.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.example.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
</application>
Actually looking at this further it looks like you haven't setup the receiver correctly. Seems you need to include at least.
<service
android:name="com.example.MyGcmListenerService "
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
And for the rest just follow that link.
You have to put your resgistration intent service at the end of yout Manifest file. Like this example:
<service
android:name="com.example.gcm.RegistrationIntentService"
android:exported="false">
</service>
Hope that help you, more information, you can visit this link and you can view an example of RegistrationIntentService here.
I've been trying to work with Parse for a while and I'm having a simple problem. I believe I am missing something with syntax but I could be wrong.
Every time I run the line,
Parse.initialize(this, "APP_ID", "CLIENT_ID");
I may have those in the wrong order. But on my system they are correct.
The application opens then closes immediately. When I moved the code, it crashes on that window.
What am I missing?
Here is my pointApp.java file:
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
public class pointApp extends Application {
public void onCreate(){
super.onCreate();
Log.w("CONTENT:","OPENING...");
try {
Parse.enableLocalDatastore(this);
Parse.initialize(this, "APP_ID", "CLIENT_ID");
}catch(Exception e){
//Log.v("Error:", "Unable to connect");
}
}
}
On my activity page, launch.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class launch extends Activity{
protected void onCreate(Bundle savedInstanceState){
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//here check if the gps is on.
setContentView(R.layout.gps_check);
/*THIS SHOULD REMOVE BECASE THEY SHOULDNT BE ABLE TO SKIP THE GPS SCREEN*/
Button continue_btn = (Button) findViewById(R.id.continue_btn);
continue_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent("android.intent.action.start"));
}
});
/*END OF CODE THAT GETS REMOVE */
}
}
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.-.point">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:name=".pointApp">
<activity
android:name=".launch"
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 android:name=".start"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.start"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.login"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".signup"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.signup"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".friends_list"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.friends_list"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".add_friend"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.add_friend"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".point"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.point"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
You need to substitute in your app id and client id. It's on the Parse dashboard.
perhaps your jar file is broken.
please check your lib jar files.
I saw such error in my project.
When I exchange lib jar files, the error disappeared.
Please try this way.
My question will be seem's stupid but I make a simple code to make a Toast when I receive a SMS, but impossible to see my toast.
My Android Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.romain.assistantvocal" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<receiver class="com.example.romain.SMSReceiver" android:name=".SMSReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver class="com.example.romain.SMSReceiver" android:name=".SMSReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
And here my class SMSReceiver :
package com.example.romain.assistantvocal;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
import java.util.Locale;
/**
* Created by romain on 26/09/2014.
*/
public class SMSReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context,"gg romstan",Toast.LENGTH_LONG).show();
}
}
Thank you in advance for your answers.
Try using this revicer:
<receiver android:name=".SmsReceiver" android:permission="android.permission.BROADCAST_SMS" android:exported="true">
<intent-filter android:priority="6565" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
replace
<receiver class="com.example.romain.SMSReceiver" android:name=".SMSReceiver">
with
<receiver android:name="com.example.romain.assistantvocal.SMSReceiver">
If ur aware of Ordered broadcasts then it says "As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. "
So. If any broadcast has stopped passing data, u won't get the message.
Try putting log in ur receiver and check. Whether ur receive message or not because ur toast message is correct.
U can't keep priority more than 1000 as per android guidelines. so, give some thing near to 1000 or remove priority and check.
I am attempting to launch an activity after the screen is unlocked and am getting the error log below. I looked at the other posts regarding my issue but now of them solved my problem
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate receiver com.me.phone.Receive: java.lang.ClassNotFoundException: com.me.phone.Receive
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2239)
at android.app.ActivityThread.access$1600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
Mainifest
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.me.phone.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>
<receiver android:name=".Recieve" >
<intent-filter
android:enabled="true"
android:exported="false" >
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
</manifest>
Reciever
package com.me.phone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Recieve extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent)
{
Intent activity = new Intent(context, MainActivity.class);
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
}
}
Could it be that "Receive" is spelled two different ways in your example?
From the exception:
...java.lang.ClassNotFoundException: com.me.phone.Receive
From the manifest:
<receiver android:name=".Recieve" >