I have looked more than 2 hours for a solution, but no chance.
I have installed parse into my application android and I have installed it in my phone (android s4 mini, using wifi currently).
Here is how my parse is setup in my project:
Parse.initialize(mInstance, App.parseAppId, App.parseAppKey);
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(mInstance, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
I see that parse logged my installation
http://awesomescreenshot.com/0865kofmd9
But when I send a push, my app crash "Unfortunately Application has stopped working"
Here is my androidmanifest:
http://pastebin.com/UySbvP8P
Any advise please?
Thanks
Please try to replace the default parse push receiver with this: :
remove:
PushService.setDefaultPushCallback(mInstance, MainActivity.class);
AndroidManifest.xml:
<receiver
android:name="ParsePushReceiver"
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>
ParsePushReceiver.java:
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
public class ParsePushReceiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent newIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
newIntent.putExtras(intent.getExtras());
context.startActivity(newIntent);
}
}
App.java
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, parseAppId, parseAppKey);
if (ParseInstallation.getCurrentInstallation() != null && ParseInstallation.getCurrentInstallation().getCreatedAt() == null) {
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
//track error
}
}
});
}
mInstance = this;
if (isOnline()) {
makeJsonObjectRequest();
}
}
Related
public class ReadNotifications extends NotificationListenerService {
Context context;
#Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
for (StatusBarNotification sbm : ReadNotifications.this.getActiveNotifications()) {
String title = sbm.getNotification().extras.getString("android.title");
String text = sbm.getNotification().extras.getString("android.text");
String package_name = sbm.getPackageName();
Log.v("Notification title is:", title);
Log.v("Notification text is:", text);
Log.v("Package Name is:", package_name);
}
}
}
<service android:name=".ReadNotifications"
android:label="#string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Previously I was able to get NotificationListenerService to work, but now I can't figure out why it isn't working. I've tried running it as it is, trying to start the service from the main activity, creating notifications from the same app, sending notifications from another app, changing emulators, but no logs are being sent.
You should grant the special permission in the android settings, you can open them like this (requires API level 22):
if (!NotificationManagerCompat.getEnabledListenerPackages(this).contains(getPackageName())) {
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
}
My issue here is more the result of the framework I'm using than Android itself. My app needs to register a ContentObserver after the user has installed a specific plugin associated with the AWARE framework. The framework has a sensor for installation of plugins, and sends a broadcast once this happens. Documentation can be found here: http://www.awareframework.com/installations/
I would like to accomplish this using a BroadcastReceiver.
I have a few questions regarding how to properly do this:
The way I interpret this documentation and Android is that if I register a BroadcastReceiver in my Manifest file with the intent filter "Installations.EXTRA_PACKAGE_NAME", every time a package is installed, it will activate my InstallationReceiver. If my understanding is still correct, I will be able to use getAction() on the received intent to parse the package name. Does this look like a correct understanding? Do intents works this way?
Is it proper to have my BrodcastReceiver in my Service class? Or should I make it a standalone class?
Did I register my receiver properly?
My MainService code:
package hcii.tracker;
public class MainService extends Service {
public static final Uri ACTIVITY_URI = Uri.parse("content://com.aware.plugin.google.activity_recognition.provider/plugin_google_activity_recognition");
public HashMap<Uri,ContentObserver> mContentObservers;
public void onCreate(){
Log.d("SERVICE", "Service created!");
Context context = this;
mContentObservers = new HashMap<Uri,ContentObserver>();
//Activate installations sensor
Aware.setSetting(context, Aware_Preferences.STATUS_INSTALLATIONS, true);
//Activate Accelerometer
Aware.setSetting(this, Aware_Preferences.STATUS_ACCELEROMETER, true);
//Set sampling frequency
Aware.setSetting(this, Aware_Preferences.FREQUENCY_ACCELEROMETER, 60);
Aware.setSetting(getApplicationContext(), "frequency_google_fused_location", 60,
"com.aware.plugin.google.fused_location");
Aware.startPlugin(getApplicationContext(), "com.aware.plugin.google.fused_location");
Aware.startPlugin(getApplicationContext(), "com.aware.plugin.google.activity_recognition");
sendBroadcast(new Intent(Aware.ACTION_AWARE_REFRESH));
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
public void onDestroy() {
try {
ContentObserver observer = mContentObservers.get(ACTIVITY_URI);
getContentResolver().unregisterContentObserver(observer);
mContentObservers.remove(ACTIVITY_URI);
} catch (IllegalStateException ise) {
Log.d("SERVICE", "No ContentObservers registered");
}
}
public class ActivityRecognitionObserver extends ContentObserver {
public Uri CONTENT_URI = Uri.parse("content://com.aware.plugin.google.activity_recognition.provider/plugin_google_activity_recognition");
public ActivityRecognitionObserver(Handler handler) {
super(handler);
}
public void onChange(boolean selfChange) {
super.onChange(selfChange);
// Get the latest recorded value
Log.d("OBSERVER", "Change in activity data detected");
Cursor activity = getContentResolver().query(CONTENT_URI, null, null, null,
"activity_name" + "DESC LIMIT 1");
if( activity != null && activity.moveToFirst() ) {
// Here we read the value
String activity_name = activity.getString(activity.getColumnIndex("activity_name"));
if (activity_name.equals("in_vehicle")){
Aware.setSetting(getApplicationContext(), "frequency_google_fused_location", 60,
"com.aware.plugin.google.activity_recognition");
Log.d("OBSERVER", "Recognized in vehicle");
Aware.startPlugin(getApplicationContext(), "com.aware.plugin.google.activity_recognition");
}
else {
Aware.setSetting(getApplicationContext(), "frequency_google_fused_location", 180,
"com.aware.plugin.google.activity_recognition");
Log.d("OBSERVER", "Recognized on foot");
Aware.startPlugin(getApplicationContext(), "com.aware.plugin.google.activity_recognition");
}
}
if( activity != null && ! activity.isClosed() ) activity.close();
}
}
public class InstallationReceiver extends BroadcastReceiver {
public InstallationReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null && action.equals("com.aware.plugin.google.activity_recognition")){
ActivityRecognitionObserver so = new ActivityRecognitionObserver(new Handler());
getContentResolver().registerContentObserver(ACTIVITY_URI, true, so);
mContentObservers.put(ACTIVITY_URI, so);
Log.d("SERVICE", "Observer registered");
}
}
}
}
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="hcii.tracker" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:replace="android:icon, android:theme" >
<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=".MainService"
android:exported="false" />
<receiver android:name="hcii.tracker.MainService$InstallationReceiver" >
<intent-filter>
<action android:name="Installations.EXTRA_PACKAGE_NAME" >
</action>
</intent-filter>
</receiver>
...
There are several problems here:
1) You can use an inner class for your BroadcastReceiver, but if so it must be declared static, because Android needs to be able to instantiate the class itself using new. This is not possible in your current architecture (because the class is an inner class). In general it is better (easier) to use a stand-alone class for this.
2) Your Intent filter is wrong. The linked documentation from Aware indicates that the broadcast Intent is Installations.ACTION_AWARE_APPLICATION_ADDED, so your intent filter needs to look like this:
<intent-filter>
<action android:name="Installations.ACTION_AWARE_APPLICATION_ADDED"/>
</intent-filter>
3) Once you have declared the BroadcastReceiver correctly, it will be triggered whenever Aware adds a plugin. The package name of the installed plugin is put into an "extra" in the Intent. To determine which plugin has been installed, you need to do something like this:
public void onReceive(Context context, Intent intent) {
String packageName = intent.getStringExtra("Installations.EXTRA_PACKAGE_NAME");
if (packageName != null && packageName.equals("your.plugin.package.name") {
// Do your stuff here...
}
}
I've spent the last two days trying to find a workaround for this.
I need to pre-config my app depending on the referral and since google play is broadcasting an Install Referrer intent when an app is installed, I created my own receiver for this task. The code for the manifest declaration and the Receiver is:
Manifest declaration:
<receiver
android:name="my.package.CustomReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
And the simplified code of the CustomReceiver:
public class CustomReceiver extends BroadcastReceiver {
private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";
#Override
public void onReceive(Context context, Intent intent) {
Log.d("debug", "waking receiver");
Uri uri = intent.getData();
getReferrerMapFromUri(uri);
new CampaignTrackingReceiver().onReceive(context, intent);
}
void getReferrerMapFromUri(Uri uri) {
MapBuilder paramMap = new MapBuilder();
// If no URI, return an empty Map.
if (uri == null) {
Log.d("debug", "intent null");
return;
}
if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {
// MapBuilder.setCampaignParamsFromUrl parses Google Analytics
// campaign
// ("UTM") parameters from a string URL into a Map that can be set
// on
// the Tracker.
paramMap.setCampaignParamsFromUrl(uri.toString());
Log.d("debug", paramMap.get(Fields.CAMPAIGN_SOURCE));
// If no source parameter, set authority to source and medium to
// "referral".
} else if (uri.getAuthority() != null) {
paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());
}
}
}
That's all. I am sending broadcast install intent with the adb shell command but it's not getting activated at all. I am using google analytics v3.
Thank you in advance!
I've tried this way. And it does work.( I am also using Google Analytics v3)
First, in manifest :
<!-- Used for Google Play Store Campaign Measurement-->;
<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
<receiver android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver" android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Second, add an CustomReceiver extends BroadcastReceiver
( In my case, I just copy and paste all the codes from developers )
package com.example.testanalytics;
import com.google.analytics.tracking.android.CampaignTrackingReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class CustomReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
// Pass the intent to other receivers.
// When you're done, pass the intent to the Google Analytics receiver.
new CampaignTrackingReceiver().onReceive(context, intent);
}
}
last step: in my activity( which I want to send messages to Google Analytics )
create an Intent and call sendBroadcast( Intent ) as follow:
Intent it = new Intent("com.android.vending.INSTALL_REFERRER");
it.setPackage("com.example.testanalytics");
it.putExtra("referrer", "utm_source%3Dyahoo%26utm_medium%3Dbanner+cpc%26utm_term%3Debook%26utm_content%3Dmy_content%26utm_campaign%3Dmy_campaign_name_2");
sendBroadcast(it);
And just get it.
I hope this may help you.
I want to open my application immediately when S Pen is detached , How can you do this, if the methods put under onSPenDetached is only called when my application is opened again?
Thanks,
Chandu
The following works on my Galaxy Tab A 9.7 with S-Pen (SM-P550) running Android 5.0.2.
Attaching and detaching the stylus creates Broadcast Intents of type com.samsung.pen.INSERT with a booleanExtra named penInsert of false if detached and true if put back into the device.
Thus a Broadcast Receiver can be created that filters this kind of events. The following code is for such a Broadcast Receiver which starts OneNote if the stylus is detached:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class SPenDetachIntentBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent penInsertIntent) {
if (!penInsertIntent.getBooleanExtra("penInsert", true)) {
try {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.microsoft.office.onenote");
context.startActivity(launchIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
In the Manifest file you need to declare it as a receiver listening for com.samsung.pen.INSERT Broadcast Intents with an intent filter. The following entry in a project's AndroidManifest.xml declares SPenDetachBroadcastReceiver, generates an instance and makes it listening for com.samsung.pen.Insert Broadcast Intents:
<receiver
android:name=".SPenDetachIntentBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.samsung.pen.INSERT" />
</intent-filter>
</receiver>
The advantage over using registerSPenDetachmentListener on an SPenEventLibrary object to register a Service with an onSPenDetached method implemented is that you do not need any additional library files and you also do not need additional permissions.
You will need to create a BroadcastReceiver and a Service.
The service:
public class SPenService extends Service {
SPenEventLibrary mSPenEventLibrary = new SPenEventLibrary();
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
mSPenEventLibrary.registerSPenDetachmentListener(this, new SPenDetachmentListener() {
#Override
public void onSPenDetached(boolean bDetached) {
if (bDetached) {
Toast.makeText(SPenService.this, "S Pen Detached", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SPenService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(SPenService.this, "S Pen Inserted", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onDestroy() {
super.onDestroy();
mSPenEventLibrary.unregisterSPenDetachmentListener(this);
}
}
The receiver:
public class SPenReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
context.startService(new Intent(context, SPenService.class));
}
}
}
The manifest (inside the <application> tag):
<receiver android:name=".SPenReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".SPenService" >
</service>
Is it possible to check if an Android device is connected to a VPN server?
A search in the API provides 'paltform highlights' for Android 1.6, so that doesn't fill me with much confidence.
You can register to broadcastreceiver and all vpn states will come to you application.
Add this to application manifest:
<receiver android:name=".ConnectivityReceiver">
<intent-filter>
<action android:name="vpn.connectivity" />
</intent-filter>
</receiver>
create a class:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ConnectivityReceiver extends BroadcastReceiver
{
public void onReceive(Context c, Intent intent)
{
String state = intent.getSerializableExtra("connection_state").toString();
Log.d("**************", state.toString());
if (state.equals("CONNECTING")) {
// Do what needs to be done
}
else if (state.equals("CONNECTED")) {
// Do what needs to be done
}
else if (state.equals("IDLE")) {
int errorCode = intent.getIntExtra("err", 0);
if (errorCode != 0) {
// Do what needs to be done to report a failure
}
else {
// Normal disconnect
}
}
else if (state.equals("DISCONNECTING")) {
// Usually not very interesting
}
}
}