2011-07-28 16 views
2

我正在開發聊天應用程序。我想顯示彈出視圖時,有人向這樣的用戶發送消息,如http://code.google.com/p/android-smspopup/。 也有參照圖片https://market.android.com/details?id=com.blntsoft.emailpopupandroid:聊天應用程序彈出視圖

任何一個任何想法,它是如何工作的?它會在本地應用程序或其他應用程序顯示also.please提供我要reference.I正在使用Web服務calls.so服務的鏈接服務將調用彈出視圖。

謝謝。

+0

在這裏你需要識別..當你的味精來...你可以使用廣播接收器類..所以你有通知彈出您的自定義對話框。 自定義對話框的鏈接:http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application – CoDe

+0

查看SDK中的ApiDemos項目 - DialogActivity示例。 –

回答

10

據我所知,您無法從服務打開對話框。 但是你有一個選項來打開服務的彈出窗口

1)製作一個彈出窗口的佈局。

2)創建活動和佈局設置爲內容鑑於此活動

3)在清單你必須寫這

<activity android:theme="@android:style/Theme.Dialog"> 

4)從服務,你有你的時候調用此活動要打開popup.But保持介意從服務,你必須設定意向標誌作爲

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

現在你可以能夠打開你的活動作爲彈出窗口。

EDIT

1)佈局的main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<EditText android:id="@+id/web" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 
<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 
    <EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 

2)test2.java將作爲彈出

package com.example.AutocompleteTextView; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class Test2 extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 
} 

3)Manifest.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.AutocompleteTextView" android:versionCode="1" 
    android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".CustomAutoComplete" android:label="@string/app_name"> 
     </activity> 

     <activity android:name="test1"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="Test2" android:theme="@android:style/Theme.Dialog"> 
     </activity> 
     <service android:name="MyService"></service> 
    </application> 
</manifest> 

4)服務MyService.java

package com.example.AutocompleteTextView; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Service; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.IBinder; 

public class MyService extends Service{ 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
    } 

    @Override 
    public void onStart(Intent intent, int startId) { 
     super.onStart(intent, startId); 
     Intent intent1 = new Intent(this, Test2.class); 
     intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent1); 


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

} 

這是從哪個我正在開始服務

package com.example.AutocompleteTextView; 

import java.lang.reflect.InvocationTargetException; 
import java.lang.reflect.Method; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.webkit.WebView; 
import android.widget.FrameLayout; 

public class test1 extends Activity { 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     startService(new Intent(getApplicationContext(), MyService.class)); 
     finish(); 

    } 
} 
+0

感謝您的重播,確實有任何彈出的工作代碼? –

+0

檢查我爲你的問題添加了一個演示文件 – Dharmendra

+0

感謝你的代碼工作 –

0

只是加入

android.permission.SYSTEM_ALERT_WINDOW

活性

清單中的權限,現在我可以顯示退出服務。