通过服务更改位置的Android-Alert对话框 [英] Android-Alert Dialog on location change through service

查看:44
本文介绍了通过服务更改位置的Android-Alert对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我想通过服务弹出位置变更的警告对话框。在这里,我附上了我的清单,服务和广播请求代码。



在控制台中,它已经安装了.apk。



但我没有得到任何烤面包或alertdialog。



如果我错了,请纠正我。



谢谢。



Hello,

I want to pop up the alert dialog on location change through service. Here i have attached my manifest , Service and broadcastReciever codes.

In the console it is giving that .apk has been installed.

But i'm not getting any toast or alertdialog.

PLease correct me if i'm wrong.

Thanks.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ser"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="3" />
    
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        
        <receiver android:name="com.ser.Myreceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" /> 
        <category android:name="android.intent.category.HOME" />  
         
    </intent-filter>  
</receiver>

        
    <service  android:enabled="true" 
        android:name="com.ser.RunService">
    <intent-filter>  
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
        </service>    
        
        
    </application>

</manifest>







package com.ser;

import android.app.AlertDialog;
import android.app.Service;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;



public class RunService extends Service implements LocationListener{

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
    public void onCreate() {
        // TODO Auto-generated method stub

        System.out.println("**inside onCreate");
        super.onCreate();
        Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
        //Intent call = new Intent(Intent.ACTION_CALL,Uri.parse("tel:+5555")); 
        //startActivity(call);
    }
	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("ALERT")
		   .setTitle("Location")
		   .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
		       public void onClick(DialogInterface dialog, int id) {
		            
		       }
		   });
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

}










package com.ser;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
//import android.widget.Toast;
//import android.util.Log;

public class Myreceiver extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		System.out.println("MYRECEIVER");
			//Toast.makeText(Myreceiver.this, "MyReciver", Toast.LENGTH_SHORT).show();
		     Intent serviceLauncher = new Intent(context, RunService.class);
		     context.startService(serviceLauncher);
		     //Log.v("TEST", "Service loaded at start");
		  
	}

}

推荐答案



您可以在服务中打开任何UI,更好的方式使用Theme作为对话框进行新活动



Hi,
You can open any UI in service, better way make new activity with Theme as dialog

<activity android:name=".popup.PopupChatActivity" xmlns:android="#unknown">
		    android:theme="@android:style/Theme.Dialog"
		    android:configChanges="keyboardHidden|orientation"
			android:screenOrientation="portrait" 
			></activity>





你可以将意图传递给活动。





谢谢。



You can pass intent to activity.


Thank you.


@tatvamobile非常感谢先生。
@tatvamobile thank you very much sir.


这篇关于通过服务更改位置的Android-Alert对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆