Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何启动android应用程序与GMail帐户对话?_Android_Service_Gmail_Gmail Imap - Fatal编程技术网

如何启动android应用程序与GMail帐户对话?

如何启动android应用程序与GMail帐户对话?,android,service,gmail,gmail-imap,Android,Service,Gmail,Gmail Imap,我正在开发一个已经存在的应用程序,但我只是为了学习而开发。我正在为Android开发GMail客户端应用程序。我尝试使用Content Observer,但找不到GMail收件箱的内容提供商URI。我正在尝试另一种方式,将ua设置为客户端。我的客户端已经设置好了,但是我不知道如何实例化这个客户端来访问GMail服务器 以下是我的代码: gmailbox.java package com.tyco.gmailApp; import android.app.Activity; import and

我正在开发一个已经存在的应用程序,但我只是为了学习而开发。我正在为Android开发GMail客户端应用程序。我尝试使用Content Observer,但找不到GMail收件箱的内容提供商URI。我正在尝试另一种方式,将ua设置为客户端。我的客户端已经设置好了,但是我不知道如何实例化这个客户端来访问GMail服务器

以下是我的代码:

gmailbox.java

package com.tyco.gmailApp;

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

public class GmailInbox extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //GmailObserver go = new GmailObserver();
        //this.getApplicationContext().getContentResolver().registerContentObserver(Uri.parse("content://imap.gmail.com"), true, go);

        Intent myService = new Intent(this,GMailService.class);
        myService.putExtra("user", "rj@gmail.com");
        myService.putExtra("password", "brooklyn");
        startService(myService);
    }
}
package com.tyco.gmailApp;


import java.util.Properties;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.view.inputmethod.InputMethodSession;
import android.view.inputmethod.InputMethod.SessionCallback;
public class GMailService extends Service
{

    private String mailhost = "imaps.gmail.com"; 
    private String user; 
    private String password; 

    @Override
    public IBinder onBind(Intent intent){
        return null;
    }

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


    }

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

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        this.user = intent.getStringExtra("user"); 
        this.password = intent.getStringExtra("password");; 
        Properties props = new Properties();
        props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        props.setProperty("mail.imaps.host", mailhost); 
        props.put("mail.imaps.auth", "true"); 
        props.put("mail.imaps.port", "993"); 
        props.put("mail.imaps.socketFactory.port", "993"); 
        props.put("mail.imaps.socketFactory.class", 
                  "javax.net.ssl.SSLSocketFactory"); 
        props.put("mail.imaps.socketFactory.fallback", "false");
        props.put("mail.imaps.socketFactory.fallback", "false");
        props.setProperty("mail.imaps.quitwait", "false"); 


// I Don't Know what to do here



    }




}
GMailService.java

package com.tyco.gmailApp;

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

public class GmailInbox extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //GmailObserver go = new GmailObserver();
        //this.getApplicationContext().getContentResolver().registerContentObserver(Uri.parse("content://imap.gmail.com"), true, go);

        Intent myService = new Intent(this,GMailService.class);
        myService.putExtra("user", "rj@gmail.com");
        myService.putExtra("password", "brooklyn");
        startService(myService);
    }
}
package com.tyco.gmailApp;


import java.util.Properties;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.view.inputmethod.InputMethodSession;
import android.view.inputmethod.InputMethod.SessionCallback;
public class GMailService extends Service
{

    private String mailhost = "imaps.gmail.com"; 
    private String user; 
    private String password; 

    @Override
    public IBinder onBind(Intent intent){
        return null;
    }

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


    }

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

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        this.user = intent.getStringExtra("user"); 
        this.password = intent.getStringExtra("password");; 
        Properties props = new Properties();
        props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        props.setProperty("mail.imaps.host", mailhost); 
        props.put("mail.imaps.auth", "true"); 
        props.put("mail.imaps.port", "993"); 
        props.put("mail.imaps.socketFactory.port", "993"); 
        props.put("mail.imaps.socketFactory.class", 
                  "javax.net.ssl.SSLSocketFactory"); 
        props.put("mail.imaps.socketFactory.fallback", "false");
        props.put("mail.imaps.socketFactory.fallback", "false");
        props.setProperty("mail.imaps.quitwait", "false"); 


// I Don't Know what to do here



    }




}
在将所有信息收集到properties对象后,我不知道该怎么办。请提出一些建议

问候,,
Rahul Jaiswal添加此代码以连接邮件服务器

Session session = Session.getDefaultInstance(props, null);
    try{
        Store store = session.getStore("imaps");
        store.connect(mailhost, mailid,password);    
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        int count=folder.getUnreadMessageCount();
        Message  message[] = folder.getMessages();
        for (int i=0, n=message.length; i<n; i++) {
                System.out.println("subject " +message[i].getSubject());
        }
      }
Session Session=Session.getDefaultInstance(props,null);
试一试{
Store Store=session.getStore(“imaps”);
store.connect(mailhost、mailid、密码);
Folder Folder=store.getFolder(“收件箱”);
文件夹。打开(文件夹。只读);
int count=folder.getUnreadMessageCount();
Message Message[]=folder.getMessages();

对于(int i=0,n=message.length;i添加此代码以连接邮件服务器

Session session = Session.getDefaultInstance(props, null);
    try{
        Store store = session.getStore("imaps");
        store.connect(mailhost, mailid,password);    
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        int count=folder.getUnreadMessageCount();
        Message  message[] = folder.getMessages();
        for (int i=0, n=message.length; i<n; i++) {
                System.out.println("subject " +message[i].getSubject());
        }
      }
Session Session=Session.getDefaultInstance(props,null);
试一试{
Store Store=session.getStore(“imaps”);
store.connect(mailhost、mailid、密码);
Folder Folder=store.getFolder(“收件箱”);
文件夹。打开(文件夹。只读);
int count=folder.getUnreadMessageCount();
Message Message[]=folder.getMessages();

对于(int i=0,n=message.length;我尝试了这段代码,但是Session是javax.mail包中定义的一个类,Android不支持它。我在我的项目中添加了mail-1.4_1.jar。现在我遇到了以下错误:javax.mail.MessagineException:Host未解析:imaps.gmail.com;嵌套异常是:java.net.SocketException:Host未解析:imaps、 我通过将我的邮件主机url改为“imap.gmail.com”而不是“imaps.gmail.com”解决了这个问题我尝试了这段代码,但是Session是javax.mail包中定义的一个类,Android不支持它。我在我的项目中添加了mail-1.4_1.jar。现在我得到了以下错误:javax.mail.MessaginException:Host未解析:imaps.gmail.com;嵌套的异常是:java.net.SocketException:Host未解析:imaps.gmail.com我通过将我的邮件主机url修改为“imap.gmail.com”而不是“imaps.gmail.com”