For my app I use pushbullet to send push messages to my device. On this device, I have an app, that should display this message. Therefore I use the pushbullet - API, described here: https://docs.pushbullet.com/extensions/messaging/guide/
So I add a service to my manifest file and implemented a class, that only should write a Log message.
my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stfgorbitzapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.pushbullet.android.permission.READ_MESSAGING_EXTENSION_DATA" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/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>
<service
android:name=".SampleMessagingExtension"
android:permission="com.pushbullet.android.permission.READ_MESSAGING_EXTENSION_DATA">
<intent-filter>
<action android:name="com.pushbullet.android.extension.MessagingExtension" />
</intent-filter>
<meta-data
android:name="protocolVersion"
android:value="1" />
</service>
</application>
</manifest>
my basic activity, only showing "Hello World"
package com.example.stfgorbitzapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
}
}
my class, that should be executed when receiving the intent:
package com.example.stfgorbitzapp;
import android.content.Intent;
import android.util.Log;
import com.pushbullet.android.extension.MessagingExtension;
public class SampleMessagingExtension extends MessagingExtension{
private static final String TAG = "SampleMessagingExtension";
#Override
protected void onMessageReceived(final String conversationIden, final String message) {
Log.i(TAG, "Pushbullet MessagingExtension: onMessageReceived(" + conversationIden + ", " + message + ")");
}
#Override
protected void onConversationDismissed(final String conversationIden) {
Log.i(TAG, "Pushbullet MessagingExtension: onConversationDismissed(" + conversationIden + ")");
}
}
but when I send a push message, I could not read the Log message. Can onyone help me? Did I forget something? I.e. specific permissions?
Maybe do you need also Network state and Wifi permissions?
Pushbullet should use network to exchange notifications..
About the log: the priority is set to INFO level. Maybe do you filter them?
Do you use Android Studio or Eclipse?
Related
I am working on an Android app (academic purposes) and as part of the app I want to integrate a Keylogger. Following this answer Android Key logger I tried to implement it using AccessibilityService. The code for my class, called Keylogger.java, is the following:
import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
public class Keylogger extends AccessibilityService {
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
int tipo = event.getEventType();
switch(tipo) {
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
case AccessibilityEvent.TYPE_VIEW_CLICKED: {
String data = event.getText().toString();
System.out.println("data: " + data);
break;
}
default:
break;
}
}
#Override
public void onInterrupt() {
}
#Override
public void onServiceConnected() {
Log.d("Keylogger", "Starting service");
}
}
The Manifest file looks like this:
<?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.mychat">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<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>
<activity android:name=".ChatBoxActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".Keylogger"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
</application>
and finally, the Configuration file for the service:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames=""
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="" />
When I install the app on the device it works just fine (that is, I get no errors), and I can manually activate the service going to Settings >> Accessibility. But nothing happens next. I tried everything (launch other applications and type some text) but the prints that I placed on each case will not show up. The app does several things but from my understanding the service should work automatically. What am I missing and how can I get it right?
Thank you in advance.
https://github.com/bshu2/Android-Keylogger
Here's a android accessibility Keylogger I've used before , and works nice
I guess you can compare your application with that Keylogger , you might find your mistake
I'm wondering why this simple receiver for detecting connection change don't work for me, it is like with al other sample which i search on google
in this sample application i have only one activity and broadcast
BroadcastReceiver:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ConnectivityReceiver extends BroadcastReceiver {
public ConnectivityReceiver() {
super();
}
#Override
public void onReceive(Context context, Intent arg1) {
Log.e("onReceive ", " , ");
}
}
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.sampleapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver
android:name=".ConnectivityReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
</application>
</manifest>
after turning on/off i dont have any output on logcat
and its my activity:
public class MainActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
If your application is targeting Android N, then you must have to register your CONNECTIVITY_CHANGE broadcast dynamically Context.registerReceiver().
Reference:
Android N Background Optimizations
I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>
I want to check whether internet is present or no continuously in background service so that I get broadcast as soon as the device gets connected to internet. Suggest with some snippets. Thank you.
Create class that extends BroadcastReceiver , use ConnectivityManager.EXTRA_NO_CONNECTIVITY to get connection info.
Code :
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.widget.Toast;
public class CheckConnectivity extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent arg1) {
boolean isConnected = arg1.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if(isConnected){
Toast.makeText(context, "Internet Connection Lost", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(context, "Internet Connected", Toast.LENGTH_LONG).show();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.connect.broadcast"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:exported="false"
android:name=".CheckConnectivity" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>
Rather than creating Service just create intent-filter with connectivity change Developer Android
<receiver android:enabled="true" android:name=".YourReceiver"
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
With your BroadcastReciever:
public class YourReceiver extends BroadcastReceiver
{
#Override
public void onReceive( Context context, Intent intent )
{
}
}
I am currently working on an app that uses a broadcastreceiver to check for incoming text messages, but all of the sudden it seems to have stopped working, I even wrote a small test application that, to me at least, seems syntactically correct, but also is not functioning.
Here is the code from the test project:
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AGApplications.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".test"
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=".MsgMon">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-sdk android:minSdkVersion="8" />
</manifest>
The BroadcastReceiver:
package com.AGApplications.test;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MsgMon extends BroadcastReceiver{
#Override
//Called when new message is received
public void onReceive(Context context, Intent intent) {
Log.d("PHONE", "Message Received");
}
}
And the main activity:
package com.AGApplications.test;
import android.app.Activity;
import android.os.Bundle;
public class test extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
As far as I can tell I'm not doing anything wrong, but obviously I am!
So I discovered the issue. You cannot use "PHONE" as a debug tag. Don't ask me why, as I cannot seem to figure it out, but after using multiple different tags, "PHONE" was the only one that wouldn't register.
My bug seems to lie elsewhere and I am hot on the trail again! Thank you all for your help!
All seems to ok for me i have done same example
here is my code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.infostretch.broadcastex"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name="broadcastex" android:label="#string/app_name"><intent-filter><action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
</manifest>
public class broadcastex extends BroadcastReceiver {
/** Called when the activity is first created. */
private static final String TAG = "smsfwd";
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Intent recieved: " + intent.getAction());
Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());
if (messages.length > -1) {
Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());
}
}
this code is working for me in android 2.1 have a try i think all is same as you