Android receive sms only works in emulator (onReceive not called?) - java

Iam coding a little gps tracker wo sends me the gps coordinates when it receives a sms.
It works with 2 emulators and I get the message with the gps coordinates.
Then I tried it on my HTC Desire and send myself an sms.
But nothing happend!
Normally when the onReceive is called it shows a message with toast and sends an sms with gps coordinates but nothing is happening ;-/
Here the manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".GPSActivity"
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=".SmsReceiver" android:enabled="true">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
any ideas?
Ps.: The code is in my last thread HERE
THANKS!

Related

Android- Why 'adjustPan' on windowSoftInputMode doesn't work ? Anyone knows why?

Problems
Hey guys, I'm currently working on creating some IOS and Android app using React Native. And I'm struggling to fix the keyboard + screen issue on Android devices.
As you can see in the left picture, the keyboard hides another inputs so the users can't see below parts.(and the screen is not scrollable.. either)
Attempt
To resolve this, I implemented ' android:windowSoftInputMode="stateAlwaysHidden|adjustPan" , but it doesn't work. I don't know why...
Moreover I saw a lot of answers that 'ScrollView' must be implemented or used. I tried in manifest.xml file, but I got errors.
Can you guys explain what the issue is and advise me how I can resolve this issue? Thanks in advance.
P.S => This issue doesn't happen in IOS device.... it only happens in Android..
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="anonymous">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package anonymous;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "my_app";
}
}

Internet access with Android M

I'm trying to do HTTP requests in Anrdoid M. But every time I get the error:
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
As far as I know every app has the Internet permission by default in Android M. So why does this error occur?
I also tried adding the permission to my manifest and to get a runtime permission, but both without success.
<?xml version="1.0" encoding="utf-8"?>
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
As far as I know every APp has INTERNET permission by default in Android M
No, they do not.
So why does this error occur?
Apparently, you do not have the <uses-permission> element, or it is in the wrong spot.
and to get a runtime permission
The INTERNET permission is not dangerous and so does not require with the runtime permission system.
You must write the permission outside the application tag
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
As for the specific android.permission.INTERNET permission, it is still mandatory for apps that will access the Internet. If a developer were to publish an app without defining it in the Android manifest, an exception will be thrown the first time a connection attempt is made, and the app will possibly crash. This is no different than before.
So you can check in your manifest the permition for internet and network state
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
You must have the Internet permission in order to get access to the internet.
Use <uses-permission android:name="android.permission.INTERNET"/>
where I showed.

always get java.lang.SecurityException: Permission Denial trying to read the data from external storage

I am creating the media viewer app for android.When my app is running on mobile is works great, but when I run my app on tablet it crashes.I always get such exception:
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=26136, uid=10096 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
here is my code:
SortedSet<String> dirList=new TreeSet<String>();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.AudioColumns.DATA};
Cursor cursor = null;
if (uri != null)
cursor= context.getContentResolver().query(uri,projection,null,null,null);
if (cursor != null && cursor.moveToFirst()) {
do {
String tempDir = cursor.getString(0);
tempDir = tempDir.substring(0, tempDir.lastIndexOf("/"));
try {
dirList.add(tempDir);
} catch(Exception e) {
e.printStackTrace();
}
} while (cursor.moveToNext());
directories = new String[dirList.size()];
dirList.toArray(directories);
directories=mediaFilter.filterMediaFiles(directories);
if(!isInstalled){
isInstalled=true;
installAudioDetails();
}
return true;
}
}
manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vasylpaliy.mediaview">
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:largeHeap="true"
android:icon="#drawable/gallery_icon"
android:label="#string/app_name"
android:theme="#style/SelectTheme">
<activity
android:name=".MainActivity"
android:theme="#style/ImageTheme"
android:label="#string/photos">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ImageSelecter"
android:parentActivityName=".MainActivity"
android:label="#string/photos"
android:theme="#style/SelectTheme">
<intent-filter>
<action android:name="android.intent.action.ImageSelecter" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Settings"
android:label="Setting"
android:parentActivityName="com.example.vasylpaliy.mediaview.ImageSelecter">
<intent-filter>
<action android:name="android.intent.action.FullScreenImage" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AudioList"
android:theme="#style/AudioListTheme"
android:label="#string/audio_list">
</activity>
<activity
android:name=".AudioAction"
android:icon="#drawable/red_music"
android:configChanges="keyboardHidden|orientation"
android:theme="#style/AudioPlayerTheme"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:parentActivityName="com.example.vasylpaliy.mediaview.AudioList"
android:label="#string/audio_view">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<data android:mimeType="audio/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".ImageSlider"
android:theme="#style/ImageSlider"
android:parentActivityName=".ImageSelecter"
android:label="Image">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:name="com.audioplayer.AudioPlayer"
android:theme="#style/AudioPlayerTheme">
</activity>
<service
android:name="com.audioplayer.AudioService">
</service>
</application>
</manifest>
set permission on AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Home"
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=".cst_cell_album_list"
android:label="#string/title_activity_cst_cell_album_list" >
</activity>
<service android:enabled="true" android:name="com.vvs.root.memusic.PlayerService" />
<receiver android:name="com.vvs.root.memusic.PlayerService$MyReceiver" >
</receiver>
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
By the looks of it you have set up the permissions correctly in your manifest. This crash might only happen on Android-M API23. The reason for that is READ_EXTERNAL_STORAGE is considered a Dangerous permission. So even though you have declared it in the Manifest, you need make sure to get the user to accept this permission at runtime. How to do this? Read here: http://developer.android.com/training/permissions/requesting.html
This is the right way to do it, but if you want to take the short way around, you could set the targetSdkVersion to 22 or lower. This will ensure that even when running on the M version, all permissions are granted. But still the user can manually turn off these permissions. So that's the downfall.
Note: This lesson describes how you implement permissions requests on
apps that target API level 23 or higher, and are running on a device
that's running Android 6.0 (API level 23) or higher. If the device or
the app's targetSdkVersion is 22 or lower, the system prompts the user
to grant all dangerous permissions when they install or update the
app.

logcat report of push not being enabled correclty

I'm using Parse as a back end for my app and I used their quick start guide to setup push notifications.
I've followed it step by step and do not get pushes. Also I get this report in logcat when I start the app
08-22 18:46:34.785 4325-4325/maxbleggi.afstudentplanner D/com.parse.ParsePushChannelsController﹕ Tried to subscribe or unsubscribe from a channel, but push is not enabled correctly. Push is not configured for this app because the app manifest is missing required declarations. Please add the following declarations to your app manifest to use GCM for push: make sure that these permissions are declared as children of the root <manifest> element:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="maxbleggi.afstudentplanner.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="maxbleggi.afstudentplanner.permission.C2D_MESSAGE" />
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
<service android:name="com.parse.PushService" />
<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" />
<category android:name="maxbleggi.afstudentplanner" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported=false>
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
But I followed the guide and I believe my manifest is correct
here it is
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="maxbleggi.afstudentplanner" >
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="maxbleggi.afstudentplanner.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="maxbleggi.afstudentplanner.permission.C2D_MESSAGE" />
<application
android:name=".utils.InitializeParse"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".activities.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
android:name=".activities.RegisterActivity"
android:label="#string/title_activity_register" >
</activity>
<activity
android:name=".activities.RegisterPart_2Activity"
android:label="#string/title_activity_register_part_2" >
</activity>
<activity
android:name=".activities.RegisterPart2TeacherActivity"
android:label="#string/title_activity_register_part2_teacher" >
</activity>
<activity
android:name=".activities.SplashScreenActivity"
android:label="#string/title_activity_splash_screen" >
</activity>
<activity
android:name=".activities.RegisterPart_3TeacherActivity"
android:label="#string/title_activity_register_part_3_teacher" >
</activity>
<!--<meta-data android:name="com.parse.push.notification_icon"/>
android:resource="#drawable/ic_stat_bt"-->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</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" />
<category android:name="maxbleggi.afstudentplanner" />
</intent-filter>
</receiver>
</application>
</manifest>
here is where I start parse
...
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback()
{
#Override
public void done(ParseException e)
{
if (e == null)
{
} else
{
}
}
});
When I use my device I do not receive this logcat report but I do receive it when I use an emulator
If using Genymotion as emulator and it does not have Google Apps installed on it, that might cause the issue. Try to Install ARM translation and check again. For more see Unable to get push notification when using Genymotion as my emulator of my android app
I know there could be complex emulator problems but picking a simple one you seem to be missing a permission
<uses-permission android:name="maxbleggi.afstudentplanner.permission.C2D_MESSAGE" />

broadcast intent callback: result=CANCELLED forIntent

I have a mobile app, that registers to a c2dm server.
I have a server that sends a message to my app, to push a notification. The server receives ok result code from google c2dm.
In LogCat i see that my app receives the message but immediately produces the error i have in my post. And also the notification that i created is ignored.
08-10 16:28:09.157: W/GTalkService(13962): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.example.c2dmclient (has extras) }
i don't get it.
My manifest file is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.c2dmclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission android:name="com.example.c2dmclient.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.c2dmclient.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".C2DMRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter >
<action android:name="com.google.android.c2dm.intent.REGISTRATION" >
</action>
<category android:name="com.example.c2dmclient" />
</intent-filter>
</receiver>
<receiver
android:name=".C2DMMessageReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter >
<action android:name="com.google.android.c2dm.intent.RECEIVE" >
</action>
<category android:name="com.example.c2dmclient" />
</intent-filter>
</receiver>
<activity android:name="com.example.c2dmclient.RegistrationResultActivity" >
</activity>
<activity android:name="com.example.c2dmclient.MessageReceivedActivity" >
</activity>
</application>
</manifest>
If someone could help me please. i'm out of ideas
According to this forum post the situation arises in Android 3.1+ when the receiving app is in stopped state on the device (for example by using force stop from the settings). It will only start to receive messages again when it is manually started.
See also this post
Finally i have found where was the problem. When i was creating the notification, in the place of logo id, i have put 0. Now all it's working.

Categories