What it's suppose to do is turn on location when needed and turn off location when not needed. I am having trouble with my Location Service when I tap to turn on location service it says, "app has stopped" please find my logcat below. any help is truely appreciated. Thank You
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kenpar.dmsassign2, PID: 21749
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=21749, uid=10184
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2640)
at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1499)
at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:377)
at com.kenpar.dmsassign2.LocationActivity$1.onClick(LocationActivity.java:30)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19274)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Application terminated.
Location java code:
public class LocationActivity extends Activity {
Button onLoc;
Button offLoc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
onLoc = (Button)findViewById(R.id.onLoc);
offLoc = (Button)findViewById(R.id.offLoc);
onLoc.setOnClickListener(new OnClickListener(){
public void onClick (View view){
Intent intent = new Intent ("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
}
});
offLoc.setOnClickListener(new OnClickListener(){
public void onClick (View view){
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
sendBroadcast(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.location, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
On android version 4.4 and above you cannot manually turn location services on and off. It will throw a securityException and can only be done manually. What you can do, you can move the user to the location services settings screen when location services are required by firing this intent:
startActivity(context, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Related
In Activity A, it has listView and a icon, to intent to Activity B.
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { //listview
public void onItemClick(AdapterView<?> listView, View view, final int position, long id) {
Expenses o = (Expenses) obj.getItem(position);
Uri image = o.getImage();
Intent intent = new Intent(QuickExpenses.this,AddExpenses.class);
intent.putExtra("image",image.toString());
startActivity(intent);
}
});
#Override
public boolean onOptionsItemSelected(MenuItem item) { // get action bar icon
switch (item.getItemId()) {
case R.id.action_add_task:
mClickedPosition = -1;
Intent intent = new Intent(QuickExpenses.this, AddExpenses.class);
startActivityForResult(intent, PROJECT_REQUEST_CODE);
return true;
}
}
Activity B
if(getIntent().getExtras()!=null) { //if has value pass from A
Uri imageUri=Uri.parse(getIntent().getStringExtra("image"));
if(imageUri!=null) {
imageView.setImageURI(imageUri);
}
else {
Toast.makeText(getApplication(),"null",Toast.LENGTH_SHORT).show();
}
}
Log
12-22 01:26:12.217 25588-25588/com.example.tony.monthlyexpenses E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tony.monthlyexpenses/com.example.tony.monthlyexpenses.AddExpenses}: java.lang.NullPointerException: uriString
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$600(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: uriString
I press the listview , everything seems fine and I can see the image is display in imageview, but when I click the icon, app crashed. I have added if(imageUri!=null) but it still crashed. Why would this happen ?
I follow this https://stackoverflow.com/a/25171292/5156075
Error point to Uri imageUri=Uri.parse(getIntent().getStringExtra("image"));
Update your checks. Your are trying to parse String which can be null, so before parsing it to uri check for null value.
String image = getIntent().getExtras().getString("image");
if(image!= null) {
Uri imageUri=Uri.parse(image);
}
I'm having issues with my prototype application. It works fine between two emulators on my PC, but when I install it on my phone it won't send text messages or even care to ask for the permission (if that is the issue).
Furthermore, I'm recieving the same error no matter what I do, on app start, each time I press a button and on every new intent start:
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
I've been looking at a lot of similar issues, and I did add
uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>
to my manifest, but nothing seems to work for me.
The real odd thing to me is that the error occurs on application start, because nothing interesting really seems like nothing interesting is happening at that point:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Go to contact list
public void onClick(View view) {
Intent i = new Intent(this,AddContact.class);
startActivity(i);
}
public void onGPS(View view) {
Intent j = new Intent(this,GPSActivity.class);
startActivity(j);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Any ideas ?
The issue is seemingly with Samsung Galaxy S3. The link: Permission Denial: this requires android.permission.INTERACT_ACROSS_USERS_FULL
Provided by Sumighosh Chaurvil explains the problem; And that there's really not much to do about it.
I installed the application on another phone, and it works with no problems whatsoever!
I want to use android's speech to text. following is my MainActivity.java
public class MainActivity extends AppCompatActivity {
private TextView txtSpeechInput;
private ImageButton btnSpeak;
private final int REQ_CODE_SPEECH_INPUT = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeechInput = (TextView) findViewById(R.id.txtSpeechInput);
btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
// hide the action bar
//getActionBar().hide();
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("OnClickListener CALLED:", "");
promptSpeechInput();
}
});
}
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
Log.i("promptSpeechInput :", "Prompt speech CALLED");
}
/**
* Receiving speech input
* */
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("OnActivity CALLED1:","one");
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
Log.i("OnActivity CALLED2:", result.get(0));
}
break;
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Here is my Log:
02-26 16:23:05.047 13636-13636/com.example.vishal.speechtotext I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#39ca1da6 time:158833044
02-26 16:23:09.637 13636-13636/com.example.vishal.speechtotext I/Timeline: Timeline: Activity_launch_request time:158837632
02-26 16:23:09.707 13636-13636/com.example.vishal.speechtotext I/promptSpeechInput :: Prompt speech CALLED
02-26 16:23:42.797 13636-13636/com.example.vishal.speechtotext I/OnActivity CALLED1:: one
02-26 16:23:42.837 13636-13636/com.example.vishal.speechtotext I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#39ca1da6 time:158870837
code just runs, doesn't show any error. i am unable to find what the
error is.
I am testing on Lollipop
Do i need net connection?
any help will be appreciated.
Yes you'll be needing Internet for this. Paste Following permissions inside your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Right now all the devices are not supporting offline speech input. To enable offline speech input for supported devices follow below steps:
On your device go to Settings -> Language and Input. Click on icon on Google voice input.
Under ALL tab select the language you want to download.
3. Once the language package downloaded, you can see it under INSTALLED tab.
I have downloaded speech input packages on my Nexus 5 and offline speech is working fine.
For further reference checkout the below link:
https://web.archive.org/web/20160218040751/http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/
I am trying to implement an android simple code that uses proximityalerts and gives an alert when entering and exiting some defined area
the code runs without errors but i would like to test if it works with coordinates (first not in the area, then goes in should receive an alert, then exits and receive another alert) so i googled how to use telnet to give lat,long but all i found is giving fixed values
is there another way to approach this?
PS: I am using android studio :)
EDIT: i figured out how to change the coordinates and i followed a tutorial to get proximity test ... the code runs without any errors but the intent to give the alert does not seem to fire
here is my code:
MainActivity
public class MainActivity extends ActionBarActivity {
LocationManager lm;
double lat=32.001271,long1=35.950375; //Defining Latitude & Longitude
float radius=100; //Defining Radius
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm=(LocationManager) getSystemService(LOCATION_SERVICE);
Intent i= new Intent("com.example.hala.proximityalert"); //Custom Action
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), -1, i, 0);
lm.addProximityAlert(lat, long1, radius, -1, pi);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
ProximityReceiver
public class ProximityReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
// The reciever gets the Context & the Intent that fired the broadcast as arg0 & agr1
String k=LocationManager.KEY_PROXIMITY_ENTERING;
// Key for determining whether user is leaving or entering
boolean state=arg1.getBooleanExtra(k, false);
//Gives whether the user is entering or leaving in boolean form
if(state){
// Call the Notification Service or anything else that you would like to do here
Toast.makeText(arg0, "Welcome to my Area", Toast.LENGTH_LONG).show();
}else{
//Other custom Notification
Toast.makeText(arg0, "Thank you for visiting my Area,come back again !!", Toast.LENGTH_LONG).show();
}
}
}
so if anyone has an idea on why it doesn't fire i would really appreciate the help
You can give coordinates via :
Eclipse -> DDMS -> Emulator Control tab -> Give coordinate includes
latitude and longitude
I have an application that is connected and disconnected. These two states are handled by a single button. However, that was clear to the user, when you click Connect, the app must change the name of the button to disconnect, and unlike too. I tried to do it like this:
#Override
public boolean onMenuItemSelected(int panel, MenuItem item) {
showToast(item.getTitle().toString(), Toast.LENGTH_LONG);
if(item.getTitle().equals("Conectar") &&
item.getItemId() == (R.id.connectionButton))
{
ConnectProcess con = new ConnectProcess(Configuration.this);
con.execute();
item.setTitle(getResources().getString(R.string.disconnect));
}
else if(item.getTitle().equals("Desconectar") &&
item.getItemId() == (R.id.connectionButton))
{
LoadCompany loadCompany = new LoadCompany(Configuration.this);
loadCompany.execute();
item.setTitle(getResources().getString(R.string.connect));
}
return true;
}
When I run the command, the following exception is being thrown. Anyone know how to fix this problem?
06-09 15:08:26.140: E/AndroidRuntime(1219): FATAL EXCEPTION: main
06-09 15:08:26.140: E/AndroidRuntime(1219): Process: com.sisteplantbrasil.prisma3mobilev2, PID: 1219
06-09 15:08:26.140: E/AndroidRuntime(1219): java.lang.ClassCastException: com.android.internal.view.menu.ActionMenuItemView cannot be cast to android.view.MenuItem
06-09 15:08:26.140: E/AndroidRuntime(1219): at com.sisteplantbrasil.prisma3mobilev2.Configuration.setConnectionButtonText(Configuration.java:105)
Can you show me more of your logCat.Normally the line wich create the error is write on it.
But if i understand your question,you can use "seText()".
Here a code example:
//
button1=(Button) findViewById(R.id.yourButton);
button1.setOnClickListener(yourListener);
private OnClickListener yourListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
button1.setText("Your New Txt");
};
To change the actionbar menus in the support actionbar. call the super method supportInvalidateOptionsMenu(); onCreateOptionsMenu will then be called where you can change the menu. There is also invalidateOptionsMenu() method witch does the same thing on the non support version of the actionbar.
public class Whatever extends ActionBarActivity {
boolean action_connect = false;
public boolean onOptionsItemSelected(MenuItem item) {
int x = item.getItemId();
switch (x) {
case R.id.action_connect:
action_connect = true;
super.supportInvalidateOptionsMenu();
return true;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (action_connect) {
}