I can get bts info in one activity , but when use that code in OnRecive of this code it is not work , Why this code can not get bts tower?
package com.example.testneighbore;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import java.util.List;
public class SMS extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Toast.makeText(context, " START ", Toast.LENGTH_LONG).show();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
List<NeighboringCellInfo> NeighboringList = telephonyManager.getNeighboringCellInfo();
String retStr="";
for (int i = 0; i < NeighboringList.size(); i++) {
int cid = NeighboringList.get(i).getCid();
int lac = NeighboringList.get(i).getLac();
retStr += "&" + cid + "," + lac + ",";
}
Toast.makeText(context,"Print: "+ retStr, Toast.LENGTH_LONG).show();
Toast.makeText(context, " END ", Toast.LENGTH_LONG).show();
}
}
}
My AndroidManifest.xml is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testneighbore"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testneighbore.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=".SMS">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"/>
</manifest>
I think my main problem is with Context, but I'm not sure.
your problem is related to context, because the context is involved with receiving sms. To solve this problem, you have to make thread and get bts info in it. it is better that your thread to be call within ~20 seconds delay . you can use omething like this in OnRecieve()
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// get info
}
}, 20000);
Related
I am trying to make an android application which will send an sms when the device first boot up and after sending the sms successfully the application will be destroyed automatically.If the application fails to send the sms then it will try within 30 minutes from the device boot up time again.
But for the test purpose I am trying to send the sms to specific number.but it don't send the sms from the device. here is manifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.farhadrakib.waltonmobile.wst"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.NONE" />
</intent-filter>
</receiver>
</application>
</manifest>
and here is the broadcastReceiver code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;
public class MainActivity extends BroadcastReceiver{
private static final String DestinationAddress = "+8801746433855";
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String DeviceId = telephonyManager.getDeviceId();
Log.d("DEVICEID",DeviceId);
//String Line1Number = telephonyManager.getLine1Number();
if (DeviceId != null){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(DestinationAddress, null, "My id: "+DeviceId, null, null);
}
}
}
can anyone help??I really need some good sugesstion
i've got a problem showing notification on my android device, i utilize parse.com website, is there a better way to send notification? and how can i solve this?
This is my Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bpartyorg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<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>
<activity
android:name="com.example.bpartyorg.ShowPopUp"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</activity>
<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.example.bpartyorg.MyCustomReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.example.bpartyorg.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
This i my MyReceiver
package com.example.bpartyorg;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null)
{
Log.d(TAG, "Receiver intent null");
}
else
{
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.example.bpartyorg.UPDATE_STATUS"))
{
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata"))
{
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
i use PARSE.COM in "pushes sent" i have "1", so it sends push notification, but my android device doesn't show it how can i solve this problem?
I am develoing small android application in eclipse. In that project i kill the running process in android, i got the Permission Denial error. how can i solve this problem in android.
Anybody help for this problem....
THIS IS MY CODE
package com.example.nuts;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Toast;
import android.*;
public class killprocess extends Activity
{
SmsManager smsManager = SmsManager.getDefault();
Recivesms rms=new Recivesms();
String Number="";
int pid=0;
String appname="";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
Number=Recivesms.senderNum;
pid=Integer.parseInt(Recivesms.struid);
appname=getAppName(pid);
Toast.makeText(getBaseContext(),"App Name is "+appname, Toast.LENGTH_LONG).show();
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = am.getRunningAppProcesses();
if (processes != null){
for (int i=0; i<processes.size(); i++){
RunningAppProcessInfo temp = processes.get(i);
String pName = temp.processName;
if (pName.equals(appname))
{
Toast.makeText(getBaseContext(),"App Name is matched "+appname+" "+pName, Toast.LENGTH_LONG).show();
int pid1 = android.os.Process.getUidForName(pName);
//android.os.Process.killProcess(pid1);
am.killBackgroundProcesses(pName);
Toast.makeText(getBaseContext(), "Killed successfully....", Toast.LENGTH_LONG).show();
}
}
}
smsManager.sendTextMessage(Number, null,"Your process Successfully killed..." , null,null);
}catch(Exception e)
{
Toast.makeText(getBaseContext(),e.getMessage(), Toast.LENGTH_LONG).show();
}
}
private String getAppName(int Pid)
{
String processName = "";
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext())
{
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try
{
if(info.pid == Pid)
{
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
//Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ info.processName +" Label: "+c.toString());
//processName = c.toString();
processName = info.processName;
}
}
catch(Exception e)
{
//Log.d("Process", "Error>> :"+ e.toString());
}
}
return processName;
}
}
After executing the code. i got the following error...
Permission Denial:
killBackgroundProcess() from pid=894,
uid=10052 requires
android.permission.KILL_BACKGROUND_PROCESSES
Also i put the following line on manifest file
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESS" />
Anybody help for how to solve this problem...
Thanking you....
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nuts"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESS" ></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/clip1"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.nuts.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="com.example.nuts.createpassword"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.editpassword"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.processList"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.killprocess"
android:label="#string/app_name"
>
</activity>
<receiver android:name=".Recivesms">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.nuts.sensSms"
android:label="#string/app_name" >
</activity>
</application>
add permission in your manifest file
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>
</manifest>
Goto your manifest file and add this
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
You need to add the relevant permission in your AndroidManifest.xml
From the official documentation :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.app.myapp" >
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
...
</manifest>
Add this permission to your manifest file to kill backgroud process
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Note: If you are getting all the running application on your android then you can kill only manually installed application like subway surfer but you can't kill inbuilt android application like launcher of android.
I don't know where is the problem with my manifest, the problem is only with android 2.3.6. In my tablet with android 4.1.2 it's receiving the messages. I have received the registration ID with 2.3.6 but the messages are never received. Please,someone could help me?:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ciqtech.quicky.mobile.passenger"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission
android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
GCM CONFIGURATION
-->
<permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="..." />
<activity
android:name="com.ciqtech.quicky.mobile.passenger.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>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity android:name="com.facebook.LoginActivity" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity"
android:label="#string/title_activity_passenger" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.LoginActivity"
android:label="#string/title_activity_login" >
</activity>
<!-- GCM
RECEIVER
-->
<receiver
android:name="com.ciqtech.quicky.mobile.passenger.broadcast_receivers.QuickyGCMBroadcastReceiver"
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="com.ciqtech.quicky.mobile.passenger" />
</intent-filter>
</receiver>
<service android:name=".services.GCMIntentService" android:enabled="true" />
</application>
</manifest>
UPDATE
QuickyGCMBroadcastReceiver
package com.ciqtech.quicky.mobile.passenger.broadcast_receivers;
import com.ciqtech.quicky.mobile.passenger.services.GCMIntentService;
import com.google.android.gcm.GCMBroadcastReceiver;
import android.content.Context;
import android.util.Log;
public class QuickyGCMBroadcastReceiver extends GCMBroadcastReceiver {
final String TAG = "QuickyGCMBroadcastReceiver";
#Override
protected String getGCMIntentServiceClassName(Context context) {
Log.d(TAG, "GET GCM INTENT SERVICE CLASS NAME");
return GCMIntentService.class.getName();
}
}
GCMIntentService. The device register correctly in android 2.3.x but it doesn't receive the messages, my message log on onMessage isn't never called, while in android 4.1.x it works perfectly. Thanks for your help.
package com.ciqtech.quicky.mobile.passenger.services;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.ciqtech.quicky.mobile.passenger.R;
import com.ciqtech.quicky.mobile.passenger.activities.LoginActivity;
import com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity;
import com.ciqtech.quicky.mobile.passenger.broadcast_receivers.Device;
import com.ciqtech.quicky.mobile.passenger.configs.GCMSettings;
import com.ciqtech.quicky.mobile.passenger.dto.NotificationDTO;
import com.ciqtech.quicky.mobile.passenger.utils.SessionManager;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gms.gcm.GoogleCloudMessaging;
public class GCMIntentService extends GCMBaseIntentService {
Context ctx;
SharedPreferences prefs;
final String TAG = "GCMIntentService";
NotificationCompat.Builder builder;
public GCMIntentService() {
super(GCMSettings.GCM_SENDER);
}
#Override
public void onError(Context context, String errorId) {
Log.d(TAG + " - onError", "Messaging registration error: " + errorId);
}
#Override
protected boolean onRecoverableError(Context context, String errorId) {
Log.d(TAG + "- onRecoverableError", "Received recoverable error: " + errorId);
return super.onRecoverableError(context, errorId);
}
#Override
protected void onMessage(Context context, Intent intent) {
String msg = intent.getExtras().getString( "msg" );
Log.d(TAG, " - onMessage: " + msg);
// [more code]
}
// Put the GCM message into a notification and post it.
private void sendNotification(String msg) {
}
#Override
public void onRegistered(Context context, String registrationId) {
Log.d(TAG + " - onRegistered", "onRegistered()");
prefs = context.getSharedPreferences("Quickytaxi-Notifications",0);
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
SessionManager session = new SessionManager(context);
String uid = session.getUserDetails().get("id");
Log.d(TAG, deviceID + " " + registrationId + " " + uid);
Device.register(deviceID, registrationId, uid);
}
#Override
protected void onUnregistered(Context context, String s) {
Log.d(TAG + "- onUnregistered", "onUnregistered()");
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
Device.unregister(deviceID);
}
public void notify(NotificationDTO notificationDTO, Intent intent){
}
}
Try following workaround not using (so far as I know) any deprecated classes. Add the action "com.google.android.c2dm.intent.REGISTRATION" to the GCMBroadcastReceiver in your manifest. This will enable to receive the registration_id at your GCMBroadcastReceiver.
<receiver
android:name="YOUR_PACKAGE_NAME.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="YOUR_PACKAGE_NAME" />
</intent-filter>
</receiver>
After that your GCMBroadcastReceiver is able to receive the registration_id:
public void onReceive(Context context, Intent intent)
{
String regId = intent.getExtras().getString("registration_id");
if(regId != null && !regId.equals(""))
{
/* Do what ever you want with the regId eg. send it to your server */
}
}
Although I still get a SERVICE_NOT_AVAILABLE error, I can handle the registration_id in my GCMBroadcastReceiver and I am able to send messages to my smartphone. Quite weird, but it works for me.
I was facing same problem from last one week but simple solutions is Android.Manifest File Changes.You have added only two permissions for C2D_MESSAGE but it required three.
<permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.C2D_MESSAGE" />
It will work for all android versions.
Ensure that your package name specified in the manifest matches the category name specified in the GCM receiver configuration. According to the manifest provided Your package name should look as below :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ciqtech.quicky.mobile.passenger"
android:versionCode="1"
android:versionName="1.0" >
Similar question can be found here GCM Push RECEIVE category Name on Android OS < 4.1. Hope that helps.
I am making app which tracks user location continuously, so far i have been able to make a successful receiving of its ordinate on location change, but if he is restarting the phone than i am not able to start my service without user again opening the app.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aa.gpsdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.aa.gpsdemo.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=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.aa.gpsdemo.StartMyServiceAtBootReciever" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
StartMyServiceAtBootReciever.java
package com.aa.gpsdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartMyServiceAtBootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent("com.aa.gpsdemo.BackgroundService");
context.startService(serviceIntent);
}
}
}
BackgroundService.java
package com.aa.gpsdemo;
import android.app.Service;
import android.content.Intent;
import android.content.Context;
import android.os.IBinder;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.widget.Toast;
import android.location.Criteria;
public class BackgroundService extends Service {
private static NewLocationListener mylistner=null;
private final static String TAG = "MainActivity";
private Context context = null;
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
mylistner = new NewLocationListener(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setCostAllowed(true);
LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
String bestProvider=locManager.getBestProvider(criteria, true);
locManager.requestLocationUpdates(bestProvider,1000, 5, mylistner);
}
}
where i am going wrong any help would be highly appreciated on restart of a phone i get demoapp has stopped i tried putting toast on reciever but that toast also are not coming at present
Make Sure u have the permission in AndroidManifest File :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Change this to :
#Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context,BackgroundService.class);
startService(serviceIntent);
}
RECEIVE_BOOT_COMPLETED: Broadcast Action: This is broadcast once, after the system has finished booting. It can be used to perform application-specific initialization, such as installing alarms. You must hold the RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast.
Refrence
Stackoverflow Question